Shop OBEX P1 Docs P2 Docs Learn Events
DAC Help — Parallax Forums

DAC Help

mynet43mynet43 Posts: 644
edited 2010-10-12 05:46 in Propeller 1
I need to generate two DAC voltage values from the Prop.

In Chip's MCP3208 driver, there is code to do this, using 32 bit values as input. I'm already using the MCP3208 for ADC, so this seems like a perfect fit.

Does someone have sample code, along with the R/C values used to generate output voltages between 0 and 3.3V? Also, do you know the accuracy of the output?

I'm using these voltages to drive ADC inputs on another microprocessor (MPS430).

It looks like I just call start2( ), and then call out(x,y) to set the values. I'm not sure what to use for X and y to get the voltage values. Can you give me an example?

Thank you for your help.

Jim

Comments

  • LeonLeon Posts: 7,620
    edited 2010-10-09 08:18
    You seem a bit confused; the MCP3208 is an ADC, not a DAC! I'd use PWM in your application, rather than a DAC chip. Perhaps that's what you tried to say.
  • mynet43mynet43 Posts: 644
    edited 2010-10-09 09:08
    Hi Leon,

    I don't think I'm confused :). Here's the code from Chip's MCP3208.spin routine.
    PUB start2(dpin, cpin, spin, mode, xpin, ypin) : okay
    
    '' Like start, but sets up 2 extra pins as 32-bit sigma-delta DACs
    ''
    ''   xpin  = pin connected to RC filter for 'x' DAC
    ''   ypin  = pin connected to RC filter for 'y' DAC
    ''
    ''   R and C values can be 1K and .1uF
    
      return startx(@dpin, (ypin & $1F | $80) << 8 + xpin & $1F | $80)
    
    PUB out(x, y)
    
    '' Update DACs with 32-bit values
    
      dacx := x
      dacy := y
    

    I'm still looking for how to use it and how to connect the R/C components.

    Jim
  • LeonLeon Posts: 7,620
    edited 2010-10-09 09:20
    He's using a 1k resistor and .1 uF capacitor for the delta-sigma DAC, and measuring the voltage with the ADC. Try those values and see what happens.
  • mynet43mynet43 Posts: 644
    edited 2010-10-09 09:55
    Hi Leon,

    The code doesn't look like he's measuring the value with the ADC. He's trying to generate the voltage by pumping the frequency into the R/C network.

    I think I understand how to connect the R/C. Connect the resistor to the pin, connect the other side of the resistor to the cap, connect the other side of the cap to ground and measure the voltage out of the junction of the resistor and capacitor. Does this sound right? I think it's just a low-pass filter.

    What I don't understand is what digital value to send it to get a desired output voltage. He says it's a 32 bit number. But I don't know how to interpret the 32 bit number. Is it treated as a fraction between 0 and 1, or is it like an adc value from 0 to some power of 2, like a 12 bit adc would be 0 to 4095.

    I'm sure someone has done this before :).

    Thanks for the help.

    Jim
  • T ChapT Chap Posts: 4,223
    edited 2010-10-09 10:05
    If you just need to set a voltage to a fixed value and leave it, or update it as needed, then connect a 10k and .1 like you already have figured out and run this code.

    Put a meter on it and change the values to see the result. The voltage will range from 0 to 3v3 and you will have very precise control. Experiment with the values to get an idea of what the output is.
    PUB Main
         dira[pin] := 1
         Setlevel(4_220_000_000)
         'Setlevel(0)
         repeat
    
    
    PUB SetLevel(freq)         
        ctra := %00110 << 26 + pin    'change to your pin
        frqa := freq
    
    
  • LeonLeon Posts: 7,620
    edited 2010-10-09 10:35
    Jim,

    You have the connections to the RC correct, just run the program with x and y values and check the voltages. If you need to know how delta-sigma DACs work here is a useful Xlinx app note:

    http://www.xilinx.com/support/documentation/application_notes/xapp154.pdf

    You presumably don't need the ADC code, so it might be a good idea to strip out all the MCP3208 stuff.
  • mynet43mynet43 Posts: 644
    edited 2010-10-09 11:44
    Hi Leon,

    Thanks for sticking with me on this one. I think I just solved the problem. I ran across a paper I forgot I had. It's called AN001-Propeller Counters v1.0.

    It gives a good example of using the counters to get a DAC. The formula is:
    V = 3.3*FRQA/2^32, which is pretty simple.

    It looks like the 32 bit value I send it is just the FRQA value.

    I noticed in this example, they use a 10K resistor. In the code, they recommend 1K. Do you know which one makes the most sense? I won't be changing the voltage often, but when I do, I want it to be as smooth and accurate as possible.

    By the way, I do need the ADC code too, so Chip's routine makes sense.

    Thanks again,

    Jim
  • LeonLeon Posts: 7,620
    edited 2010-10-09 12:06
    That is simply PWM, rather than delta-sigma, but it might do just as well for your purposes. I think that is why the two resistor values are different - delta-sigma uses a much higher frequency.

    I might try out Chip's code for myself, just one DAC output.
  • AribaAriba Posts: 2,690
    edited 2010-10-10 00:51
    The values of R and C depends on the max. signal output frequency and the input resistance of the connected circuit.

    The R and C build a lowpass filter with the frequency: fc = 1 / (2*pi*R*C)
    I.e. for an audio DAC the values can be 220 Ohm and 47nF, so you hear also the higher audio frequencies.

    In your case, the voltage seems to change only all seconds or so. With 10kOhm and 1uF you get a filter frequency of 16 Hz which should result in smooth changes.

    Andy
  • mynet43mynet43 Posts: 644
    edited 2010-10-10 06:07
    Andy,

    Thank you for the explanation. It makes complete sense.

    I'm using the DAC to inject a voltage into an ADC, based on human input, so slow and smooth is perfect!

    If I use 1K * 10uF instead of 10K * 1uF, will this give me the same response and the ability to drive a bigger load?

    Do you know the accuracy and linearity of the output voltage?

    Thank you for your help.

    Jim
  • AribaAriba Posts: 2,690
    edited 2010-10-10 18:36
    Hello Jim

    If you go direct into an ADC of the MSP430 it should work with 1k/10uF or 10k/1uF. I normally prefere ceramic caps for such filters, that's why I suggested a 1uF (but today also 10uF ceramics are available).

    How smooth the resulting voltage is, depends also on the PWM frequency. The frequency should be as high as possible, but the higher PWM the lower is the bit resoluition of the DAC.
    Say you want a 12bit DAC, then the PWM freq is 80MHz / 4096 = 19 kHz. This is with the NCO mode example of the AN0001. The R/C low pass then flters out this 19 kHz, so you get only the DC-part of the PWM signal, which is direct proportional to the pulswith.
    There is also the DUTY mode DAC. DUTY mode has much higher frequencies in the middle of the voltage range but the freuqency varies havy and there are serious EMC problems with this mode.

    The DAC accuracy depends mostly on the accuracy of the 3.3V supply voltage. If this supply is well regulated and has no random spikes on it then the DAC is very accurate. (Periodic spikes will be filtert by the R/C anyway).

    The linearity of a PWM DAC should be very good, if the load has a constant input resitance over the full voltage range.

    If you need a low output impedance you can add a OPAMP to the RC filter:
    attachment.php?attachmentid=74371&stc=1&d=1286760964

    Andy
    300 x 120 - 1005B
  • mynet43mynet43 Posts: 644
    edited 2010-10-10 20:42
    Andy,

    Thank you for the great explanation.

    I'm using the DUTY mode, because that's what's in Chip's MCP3208.spin routine to generate DAC output. I also need the ADC code, which is why I'm doing it this way.

    I am hoping this will give me reasonably good results. I guess I could adjust the output by feeding it back into my ADC and adjusting the frequency until it matches the desired voltage. Do you think the DUTY mode will give fairly accurate results?

    Thanks again.

    Jim
  • AribaAriba Posts: 2,690
    edited 2010-10-10 22:47
    What DAC resolution do you aim?

    What kind of human input is this (Poti, up/down switch ...)

    I have used DUTY mode only for audio so far, for that it's ideal.
    I have a bit more confidence in normal PWM when it comes to accuracy, but DUTY will also not be bad. In DUTY mode the shorter pulslength is always only 1 clock cycle (12,5ns @ 80MHz), so asymmetrical switching times and such errors will have more influence.

    With a Multimeter you can test this easy, just measure direct at a Prop pin which outputs the PWM signal. The Multimeter integrates the PWM like the R/C filter.

    Andy
  • mynet43mynet43 Posts: 644
    edited 2010-10-11 06:29
    Andy,

    I'd like to get 12 bit accuracy if I can, but it's probably not critical. I'm using it to simulate a voltage that is normally generated by an analog pressure sensor. It's used to test a medical device that has two small air pumps.

    What do you think of the idea of feeding the DAC voltage back into my ADC as a feedback loop to adjust the voltage? I have spare ports on my MCP3208.

    Thank you for the help.

    Jim
  • AribaAriba Posts: 2,690
    edited 2010-10-11 16:30
    mynet43 wrote: »
    Andy,
    What do you think of the idea of feeding the DAC voltage back into my ADC as a feedback loop to adjust the voltage? I have spare ports on my MCP3208.

    Why not, it can also be useful to test the ADCs. If you have a stable reference voltage for the ADCs then this may be more accurate than just the 3.3V supply voltage.

    But I don't think that you really need such a high resolution for this application. One bit of a 12 bit DAC is 0.025%. Are the pumps or the pressure sensors nearly as accurate?

    Andy
  • mynet43mynet43 Posts: 644
    edited 2010-10-12 05:46
    Andy,

    Thanks for the feedback. The design spec requires the pressure to be accurate to 0.5 mm Hg, which seems ridiculous, and is really not needed for this application. They are using a pressure sensor with an analog output range of 100 mv. They amplify this about 3X with an op-amp circuit. They do calibrate their ADC values at zero and 90 mm Hg, so it should be fairly accurate. The ADC on the MSP430 is 12 bit.

    That's a good idea about using the feedback to also calibrate the ADC's.

    Thanks for the help.

    Jim
Sign In or Register to comment.