Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 14 of 14

Thread: Need to make a Teensy do this, how?

  1. #1
    Senior Member
    Join Date
    Oct 2014
    Posts
    134

    Need to make a Teensy do this, how?

    I need a to output a +/-5vdc or +/-10vdc pure analog signal that can be control by my Teensy 3.1 Can not be PWM output. I know there is one DAC available on the Teensy 3.1 but I need 6 outputs and 12bit ops preferred. The following product below works perfect in testing but can not interface it to x-plane plus I want to stick to using just my Teensy's. Thanks for any input.

    http://www.phidgets.com/products.php?product_id=1002

  2. #2
    Senior Member
    Join Date
    Nov 2013
    Posts
    719
    A reasonably basic class B amplifier ( http://sub.allaboutcircuits.com/imag...z/00972x01.png ) circuit can be deployed to boost Teensy 3.1 0V to 3.3V DAC output to -10V to +10V range but you have problems; only 1 DAC on Teensy 3.1 and when you find satisfactory way to add 5 more DACs you need 5 more copies of the amplifier.

    Is this the same project where you had 10 (or more?, even you?) Teensys hooked up simultaneously? If so, I think we all know where you can find the other 5 DACs

    Note: PNG file I have linked to is pretty generic, you need to DC bypass and then center the DAC output before it hits the input node on such a circuit - DC bypass is probably best as 10uF (for least filtering of higher frequencies) between DAC and input to amplifier circuit, centering probably best as 100K (or so) resistor from amp input node to 0V/GND node in amp circuit; dual rail power supply required, 0V/GND on that power supply needs to connect to GND on Teensy as well.

    Any good?

  3. #3
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,544
    I believe the MCP4728 is an i2c device that offers 4 DAC's per chip, with EEPROM to hold the last digital value for each of the pins as well as the i2c address. I imagine you would need an i2c level converter to convert the Teensy 3.3v to 5v (note, you will also need 2 pull-up resistors for i2c), and two MCP4728 chips. There was this discussion about the chip: https://forum.pjrc.com/threads/28424...C-using-i2c_t3

  4. #4
    Senior Member
    Join Date
    Feb 2013
    Posts
    563
    what are those signals going to be used for?


    anyways, if you want a -/+ 5V or -/+ 10V signal, i assume you have some bipolar power supply? well, probably you don't, if you were using that phidgetAnalog thing. (amazing, it costs 90$ and the page doesn't seem to say which DAC is being used?)

    at any rate, a bipolar supply (+/- 12v, +/- 15v) would make things easier. so let's assume you have one, you can then simply use basic op amp circuits to scale your signal. DAC datasheets usually have bipolar output examples, though details might somewhat depend on what it is that you want to do (eg. is DC accuracy important, or not so much).

    then there's various options re: choice of DAC. if you want/need high(ish) sample rates, you're probably looking at SPI not i2c. MCP4822 must be the most popular one; these are dual so you'd need three (CLK, MOSI, 3 x CS). if you're comfortable with SMD, there's way more choice, including quad and octal DACs, even bipolar DACs (AD5721R, for instance, though that's just single channel, so not very suitable).

  5. #5
    Senior Member
    Join Date
    Nov 2013
    Posts
    719
    Quote Originally Posted by mxxx View Post
    ...

    at any rate, a bipolar supply (+/- 12v, +/- 15v) would make things easier. so let's assume you have one, you can then simply use basic op amp circuits to scale your signal. DAC datasheets usually have bipolar output examples, though details might somewhat depend on what it is that you want to do (eg. is DC accuracy important, or not so much).

    ...
    Opamp based circuits have a problem in this field as far as I am concerned: All too easy to get the big voltage(s) all the way back to the MCU (mitigating this is more actives than should be needed for actual purpose imho), much less likely with a well chosen pair of transistors of opposite persuasions, hence why I suggest a simpler class B amplifier circuit.

  6. #6
    Senior Member
    Join Date
    Feb 2013
    Posts
    563
    Quote Originally Posted by robsoles View Post
    Opamp based circuits have a problem in this field as far as I am concerned: All too easy to get the big voltage(s) all the way back to the MCU (mitigating this is more actives than should be needed for actual purpose imho), much less likely with a well chosen pair of transistors of opposite persuasions, hence why I suggest a simpler class B amplifier circuit.
    which field? there's a whole (admittedly semi-professional at times) industry building audio/music devices around MCUs; they inherited/adopted a +/- 12V or +/- 15V power supply scheme/convention from the old days. they use op amp circuits all over the place. i never heard of a mcu failing because of over voltage.

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,500
    Under normal conditions, of course the inputs to an opamp should act as a very high impedance.

    Under horribly abnormal conditions, consider the opamp inputs are the base or gate of a transistor. In the case of bipolar transistors, the input is a P-N junction to another node inside the opamp. Only mosfet inputs are truly high impedance (at least at low frequencies), but mosfets are less common due to higher offset voltage errors and often noise issues too.

  8. #8
    Senior Member
    Join Date
    Nov 2013
    Posts
    719
    @mxxx: I was talking about the field of amplifying signals and I was probably being silly (hardly a 'first time' if so) - just the DC blocking capacitor and a little other mitigation and it is probably safe as houses to use an opamp instead of a pair of opposingly matched transistors set up in the simplest form of amplifier (which want the DC blocking cap etc anyway).

  9. #9
    Senior Member
    Join Date
    Dec 2013
    Location
    Brasilia, Brazil
    Posts
    166
    what are those signals going to be used for?


    That would be my question as well. I know Rob's building a 737 flight simulator and I guess it's one of the instruments.
    Sorry that I'm questioning your use case here, but I'd really like to know which one it is and why it requires 12 bits.

    What I want to say is that I don't see any instrument (much less a group of six) in a home-built simulator that requires or provides an accuracy of more than 9 or 10 bits. Even OBSs only work with a range of 0-360 degrees in steps of 1 (9 bits are sufficient). Altitude is handled digitally by driving stepper motors. Airspeed can reach values above 512, but it's only a single gauge with a single pointer, That pointer won't rotate more than - let's say - 330 degrees, so on an 8-bit-scale, one digit corresponds to an approximate angle of 1.29 degrees. To me, that sounds sufficient, I doubt that you will be able to visually read angles below that. The rest is scaling and calibration, which can/should/must be handled in software.

    The other instruments are even smaller, so resolutions above 8 bits won't produce any visual difference on them.

    Is this the same project where you had 10 (or more?, even you?) Teensys hooked up simultaneously? If so, I think we all know where you can find the other 5 DACs


    That sounds more than reasonable...

    i never heard of a mcu failing because of over voltage.


    Rob has: https://forum.pjrc.com/threads/29257...8596#post78596. It happens.

    Which brings me back to the question whether you replace that Teensy and how long dataref's are going. If it works fine (as you indicated in the private mail you sent), please let the community know in the original thread(s), so that Paul can incorporate the patch to the original X-Plane plugin.

  10. #10
    Senior Member
    Join Date
    Feb 2013
    Posts
    563
    Quote Originally Posted by jbliesener View Post
    ups, so i take it back.

  11. #11
    Senior Member
    Join Date
    Oct 2014
    Posts
    134
    Hi Jorg,
    I was waiting to test the code on the actual instrument before I gave it the final thumbs up. I had that portion of the code commented out for the moment.

    Yes, I need this to drive several parts of my instrumentation. I have +/-3.3, 5, 12, and 15vdc available. 10bit would suffice but I have found 12bit to have smoother movement. I am using the 8bit 0-255 pwm to drive a few things and it is not to bad.
    My goal is to have a smooth movement, protect my teensy's from power faults, and easy to program.
    I have not done SPI yet but do have some I2C stuff working.
    Just to give you an idea, one instrument, the ADI requires 40 wires alone to operate. So keeping wiring to a minimum is a must if at all possible.
    I appreciate everyone's input and am enjoying learning as much as possible and making this project/dream become a reality.

    Rob

  12. #12
    Senior Member
    Join Date
    Oct 2014
    Posts
    134
    What about something like this?
    https://www.adafruit.com/products/935

  13. #13
    Senior Member
    Join Date
    Dec 2013
    Location
    Brasilia, Brazil
    Posts
    166
    The problem with the MCP4725 is that you can only have two of them on the I2C bus, as their address is almost fixed. You only have one bit (A0) that you can set either to high or to low. Therefore, you can not address more than two MCP4725s on the same I2C bus.

    You're using LCs, right? Those have have two I2C buses (one on pins 18 and 19 and another one on pins 22 and 23), so you would be able to connect four MCPs to one Teensy LC. On the 3.1, the pins are different and you would have to use the bottom side pads 29 and 30 for the second I2C bus. Don't forget the pull-up resistors...

    Having said that, I still believe you don't need to produce clean analog signals to drive your instruments. Filtered PWM should easily do the job. Did you know that you can change the resolution (number of bits) and the frequency of the PWM outputs on the Teensy? This page explains all the details, including filtering the output signal: https://www.pjrc.com/teensy/td_pulse.html. PWM can give you up to 16 bits of resolution at 732 Hz or 10 bits at 47 KHz.

    On my simulator, I used a shift register chain (40 bits) and the ShiftPWM library (https://www.pjrc.com/teensy/td_libs_ShiftPWM.html). On a Teensy 2.0++ that gives me 8 bits resolution with 50 Hz, using only three pins on the Teensy. 8 bits/50 Hz is totally sufficient for those old analog gauges and given the inertia of the pointer, I don't even need to filter. You should be perfectly fine with the PWM outputs of Teensy 3.1 or LC. If you need some level shifting, go with Opamps and protect them according to Paul's suggestion on the other thread. Make sure to use Rail-to-Rail models (I'll need to replace those TL084's I used...).

  14. #14
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,544
    Quote Originally Posted by jbliesener View Post
    The problem with the MCP4725 is that you can only have two of them on the I2C bus, as their address is almost fixed. You only have one bit (A0) that you can set either to high or to low. Therefore, you can not address more than two MCP4725s on the same I2C bus.
    The datasheet for the MCP47245 says that for the actual chip there are 8 possible addresses. However, the version that Sparkfun and Adafruit sells only has 1 address pin broken out. But if you search around, you might find a variant with 3 pins for addresses (or the SMT chip).

    I did see a comment in the Sparkfun page that since Sparcfun and Adafruit MCP4725's have different base addresses, you could get two from Sparkfun and two from Adafruit to make 4. And as you mention, the LC has 2 i2c buses, for a total of 8 MCP4725's.

    Alternatively, you can get i2c multiplexers (https://www.tindie.com/products/Fybe...ll_prod_search).

    Note, I mentioned the MCP4728, which has 4 outputs, and according to the datasheet you can program the i2c address into EEPROM. It looks like you can get it with a through hole breakout board from: http://www.proto-advantage.com/store...kout_Board.php

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •