Shop OBEX P1 Docs P2 Docs Learn Events
Need Simple "No Parts" DAC, Sigma-Delta? — Parallax Forums

Need Simple "No Parts" DAC, Sigma-Delta?

RickInTexasRickInTexas Posts: 124
edited 2013-06-15 19:38 in Propeller 1
This is so simple, I feel silly asking but I'm having a brain-freeze on this.

Searching for DAC I find many solutions using external ICs, but I dont have any silicon DACs handy, so I just need something simple. I know that Sigma-Delta has been beat to death for ADC and that DAC should work in a similar manner.

I just want a couple of outputs where I can set them to arbitrary DC voltages e.g. 2.0 and 2.7.

By "no parts" I'm thinking a few Rs and Cs. Ideas?

RickInTexas

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-06-13 16:31
    A simple R/C filter attached to a single I/O pin will do what you want in most cases. The specific values of R and C depend on the frequencies involved (how fast the voltage has to change). For an example in the audio range, look at the schematic for any of the Propeller boards that have an audio output. Look in the ObEx for a PWM object. Usually, the % on time corresponds to the % voltage output with the maximum voltage usually 3.3V and minimum voltage 0V. Since there's some voltage drop across the output transistors, the actual voltage range is a little less.
  • jmgjmg Posts: 15,173
    edited 2013-06-13 17:22
    By "no parts" I'm thinking a few Rs and Cs. Ideas?

    You've looked at AN001 ?

    http://www.parallax.com/Portals/0/Downloads/appnt/prop/AN001-PropellerCountersv1.1.zip
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-06-13 20:48
    This is so simple, I feel silly asking but I'm having a brain-freeze on this.

    Searching for DAC I find many solutions using external ICs, but I dont have any silicon DACs handy, so I just need something simple. I know that Sigma-Delta has been beat to death for ADC and that DAC should work in a similar manner.

    I just want a couple of outputs where I can set them to arbitrary DC voltages e.g. 2.0 and 2.7.

    By "no parts" I'm thinking a few Rs and Cs. Ideas?

    RickInTexas

    There's a DAC! words built into Tachyon which uses the duty mode of the counters. This only needs a resistor from the pin to a capacitor to ground. If you want that voltage buffered then just use an opamp in voltage follower configuration. Then again you can add gain resistors and get a 0-10V etc.


    This is the word that's built into Tachyon, it makes it very simple to create a DAC.
    [B][COLOR=#000000][FONT=Ubuntu Mono]\ Write an 8-bit value to the pin as a duty cycle - filter output for a voltage[/FONT][/COLOR]
    
    [COLOR=#000000][FONT=Ubuntu Mono]pub [/FONT][/COLOR][COLOR=#000000][FONT=Ubuntu Mono][B]DAC![/B][/FONT][/COLOR][COLOR=#000000][FONT=Ubuntu Mono] ( byte pin -- )[/FONT][/COLOR]
    
    [COLOR=#000000][FONT=Ubuntu Mono]    DUP PINCLR APIN DUTY #24 SHL FRQ[/FONT][/COLOR]
    
    [COLOR=#000000][FONT=Ubuntu Mono]    ;    [/FONT][/COLOR]
    
    
    [/B]
    

    Connect a 220R resistor to the pin (assume it's P0) and connect the other end to a 0.1uF capacitor tied to ground and try this:

    $80 #P0 DAC!

    The output voltage should be around 1.65V.
  • RickInTexasRickInTexas Posts: 124
    edited 2013-06-14 13:26
    There's a DAC! words built into Tachyon which uses the duty mode of the counters. This only needs a resistor from the pin to a capacitor to ground. If you want that voltage buffered then just use an opamp in voltage follower configuration. Then again you can add gain resistors and get a 0-10V etc.


    This is the word that's built into Tachyon, it makes it very simple to create a DAC.
    [B][COLOR=#000000][FONT=Ubuntu Mono]\ Write an 8-bit value to the pin as a duty cycle - filter output for a voltage[/FONT][/COLOR]
    
    [COLOR=#000000][FONT=Ubuntu Mono]pub [/FONT][/COLOR][COLOR=#000000][FONT=Ubuntu Mono][B]DAC![/B][/FONT][/COLOR][COLOR=#000000][FONT=Ubuntu Mono] ( byte pin -- )[/FONT][/COLOR]
    
    [COLOR=#000000][FONT=Ubuntu Mono]    DUP PINCLR APIN DUTY #24 SHL FRQ[/FONT][/COLOR]
    
    [COLOR=#000000][FONT=Ubuntu Mono]    ;    [/FONT][/COLOR]
    
    
    [/B]
    

    Connect a 220R resistor to the pin (assume it's P0) and connect the other end to a 0.1uF capacitor tied to ground and try this:

    $80 #P0 DAC!

    The output voltage should be around 1.65V.

    Perfect!

    I get the following outputs, quite linear:

    Volts
    =====
    0 #P0 DAC! 0.002
    10 #P0 DAC! 0.203
    20 #P0 DAC! 0.404
    30 #P0 DAC! 0.606
    40 #P0 DAC! 0.808
    50 #P0 DAC! 1.009
    60 #P0 DAC! 1.210
    70 #P0 DAC! 1.412
    80 #P0 DAC! 1.613
    90 #P0 DAC! 1.811
    95 #P0 DAC! 1.874
    96 #P0 DAC! 1.886
    97 #P0 DAC! 1.899
    98 #P0 DAC! 1.911
    99 #P0 DAC! 1.923
    100 #P0 DAC! 0.002

    Now I just need to scale it so I can obtain the 2.75v that I need, but that's ok, I have plenty of options there; 74HC245 etc.

    @Peter I'm liking Tachyon more every day, but I've got a lot more to learn. I should be getting over the hump where my productivity begins to take off.

    Thanks to all. I do need to get more into the counters, they are handy indeed.

    RickInTexas
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2013-06-14 14:01
    Simple.
    Connect a resister from the capacitor to +3.3.
    The resister value is the same as the resistor from the capacitor to the prop pin.

    Or use a single higher value resistor such as 10KΩ which is significantly larger than the pin out resistor.
    This should go much closer to 3.3V than the 220Ω you are now using.

    Duane J
  • RickInTexasRickInTexas Posts: 124
    edited 2013-06-14 16:25
    Simple.
    Connect a resister from the capacitor to +3.3.
    The resister value is the same as the resistor from the capacitor to the prop pin.

    Or use a single higher value resistor such as 10KΩ which is significantly larger than the pin out resistor.
    This should go much closer to 3.3V than the 220Ω you are now using.

    Duane J

    Great idea Duane. I guess I need an analog refresher too. I got my novice ticket back in 1973 (WN9VYL), need to dig out those old study guides :) I knew this should be simple, I could have just order a cheap DAC (Mouser's accross town so I get stuff the next day), but that would be "cheating" and not in the spirit of "As simple as possible".

    Using a pair of 22KΩs I get a range of 2.185V to 3.131V. Since I need 2.0V to 2.75V I could achieve that range by bumping the 22KΩ up a bit, correct?

    Tachyon FORTH Rocks!

    RickInTexas
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-06-14 16:34
    Perfect!

    I get the following outputs, quite linear:

    Volts
    =====
    0 #P0 DAC! 0.002
    10 #P0 DAC! 0.203
    20 #P0 DAC! 0.404
    30 #P0 DAC! 0.606
    40 #P0 DAC! 0.808
    50 #P0 DAC! 1.009
    60 #P0 DAC! 1.210
    70 #P0 DAC! 1.412
    80 #P0 DAC! 1.613
    90 #P0 DAC! 1.811
    95 #P0 DAC! 1.874
    96 #P0 DAC! 1.886
    97 #P0 DAC! 1.899
    98 #P0 DAC! 1.911
    99 #P0 DAC! 1.923
    100 #P0 DAC! 0.002

    Now I just need to scale it so I can obtain the 2.75v that I need, but that's ok, I have plenty of options there; 74HC245 etc.

    @Peter I'm liking Tachyon more every day, but I've got a lot more to learn. I should be getting over the hump where my productivity begins to take off.

    Thanks to all. I do need to get more into the counters, they are handy indeed.

    RickInTexas
    Ah Rick, you made the classic mistake and nobody picked it up. You typed 99 and ended up with 1.923 which is above the half way point of 128 or $80 which delivers 1.65V. When you typed in 100 you were actually typing in 0 as that DAC! word accepts an 8-bit value and the default number base of Tachyon is hex. The circuit I described will cover from 0 to 3.3V and the reason for the low value resistor is simply to provide low impedance drive otherwise you might need to buffer the signal. Too high a value of resistor still gives you the correct voltage but will suffer as soon as you hook-up anything more than a meter to it.
  • jmgjmg Posts: 15,173
    edited 2013-06-14 17:34
    The circuit I described will cover from 0 to 3.3V and the reason for the low value resistor is simply to provide low impedance drive otherwise you might need to buffer the signal. Too high a value of resistor still gives you the correct voltage but will suffer as soon as you hook-up anything more than a meter to it.

    220R is quite low tho, and the series pin impedance will start to skew the output, so precision will be lower than it could be.
    It also has a high Icc cost at mid-scale voltages.
  • RickInTexasRickInTexas Posts: 124
    edited 2013-06-14 17:49
    I'm a bit confused. It did not escape my attention that "100 #P0 DAC!" output ~0V. I played with this a bit and I got the same output whether or not I preceded the set point value with a "$" or not. Ithought this was either because the default base was set to "DECIMAL" (which I did once but I don't think I did a "BACKUP" of the system state.) or that the "DAC!" word was just set up to respond to a default decimal, as in %1 to %99. Should have known better than for you to do that though!

    Q: Is there a Tachyon word to inquire what the current default input base is set to?

    So anyways, while experimenting I was using Excel to produce the test data, by 10s, and then when I saw that "100" gave me zero, I went down to steps of 1 from 95 through 100. The resulting output looked quite reasonable, linear steps between 10 and 90, and still linear with correspondingly smaller increments as shown in my experimental data between 95 and 99 inclusive.

    I used a junk-box cap that measured 0.01uF so that's why I chose the 2.2KΩ resistor(s). (Logic check?)

    BTW, I said 22KΩ in post #7. I just double checked, they are indeed 2.2KΩ.

    I'm going to Radio Shack right now to get 0.1uF caps. I have to work tonight so I won't probably get back to the bench 'till tomorrow (Saturday in Texas USA).

    Thanks for your patient help.

    Some good news: Tera Term 4.78 is working well. I was able to paste the "Sines" code and run it. Cool stuff.

    RickInTexas
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2013-06-15 06:34
    Hi RickInTexas;

    Some thoughts:
    1. The product of R * C, the RC time constant, defines how fast the output voltage can change in response to a change in the digital value.
    2. The actual values of R or C can be quite loose. Almost anything can be used and the accuracy will not suffer.
    3. Of course if R * C is to low there will be lots of jitter.
    4. If R is to small the props pin output resistance, which is not a fixed value, will interfere with accuracy.

    Duane J
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-06-15 07:30
    Hi Rick,
    You didn't say what you needed this for because knowing a little bit more should yield more suitable values or circuit. But once again the low value resistance is better than too high a value that gets loaded too easily which introduces way more error. Remember, the DAC it not just so you can measure it with a meter, it's got to do something.

    BTW, if it's a certain voltage that you are after then just add this word.
    pub V ( volts.00 -- ) 
         #255 * #330 / #P0 DAC!
        ;
    
    
    \ Usage (scaled to decimal places, dp is redundant):
    #2.67 V     \  set the output voltage to 2.67 volts
    
    
    
  • RickInTexasRickInTexas Posts: 124
    edited 2013-06-15 14:27
    Hi Rick,
    You didn't say what you needed this for because knowing a little bit more should yield more suitable values or circuit. But once again the low value resistance is better than too high a value that gets loaded too easily which introduces way more error. Remember, the DAC it not just so you can measure it with a meter, it's got to do something.
    The purpose is for a USB charging setup. I need to set the USB's D+ and D- lines to fixed DC voltages that are programaticallly selected. I think that these lines should be rather Hi-Z, so I should not need much drive current. I need to check the USB spec on this.

    RickInTexas
  • RickInTexasRickInTexas Posts: 124
    edited 2013-06-15 14:55
    Hello Duane J
    Hi RickInTexas;

    Some thoughts:
    1. The product of R * C, the RC time constant, defines how fast the output voltage can change in response to a change in the digital value.
    2. The actual values of R or C can be quite loose. Almost anything can be used and the accuracy will not suffer.
    3. Of course if R * C is to low there will be lots of jitter.
    4. If R is to small the props pin output resistance, which is not a fixed value, will interfere with accuracy.

    Duane J

    Thanks for the analog refresher. On point 4 can you elaborate on the prop's output resistance? Are you alluding to a (sharp) rise in the IR drop of the Props output drivers once this current reaches a certain level? I don't recall seeing a spec on output impedance. I know that the outputs can source/sink 40ma. Is there a lower practical limit in terms of this application?

    Rick

    RickInTexas
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2013-06-15 19:38
    Hi Rick;
    Thanks for the analog refresher.
    On point 4 can you elaborate on the prop's output resistance?
    Are you alluding to a (sharp) rise in the IR drop of the Props output drivers once this current reaches a certain level?
    While this can happen, that is not the effect I was referring to as the Prop pin should, with this application, have the output FETs operating near saturation.
    Even when saturated the FETs still have some ON resistance.
    Unlike conventional resistors where the resistance is constant with changing current, the ON resistance of FETs changes somewhat with changing current in the linear region.
    I don't recall seeing a spec on output impedance. I know that the outputs can source/sink 40ma.
    I don't think there is one. The spec suggests the normal operating current should be kept less than 10mA.
    There was a thread a while ago where someone, (anyone? anyone?), did some accurate measurements of pin output resistance.
    As I recall, it was something like 140Ω or was it 170Ω or so.

    The 40mA current is probably way outside saturation and generally you should never go there.
    Is there a lower practical limit in terms of this application?
    As a practical mater, the current depends on the require accuracy desired of the DtoA.
    With higher R values the output resistance change will be smaller because the voltage across the FET will be less.
    The only practical way to investigate this is experimentation. Use a pot, say 10KΩ or so, along with a bunch of capacitors and see what works for your application.

    Duane J
Sign In or Register to comment.