DAC Help
mynet43
Posts: 644
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
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
I don't think I'm confused . Here's the code from Chip's MCP3208.spin routine.
I'm still looking for how to use it and how to connect the R/C components.
Jim
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
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.
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.
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
I might try out Chip's code for myself, just one DAC output.
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
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
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:
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
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
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
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
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