View Full Version : Serial Digital to Analog - Voltage Out
09-11-2008, 11:52 PM
Hello everybody. I'm looking for an easy to use device that will allow me to send digital data from a Stamp and have it converted into a voltage value between 0 and 10 volts dc.
I know someone has done this before. So instead of reinventing the wheel I was hoping someone could share their experience and knowledge on this subject.
A quad DAC with serial input and voltage output is what I'm really looking for.
- Thane http://forums.parallax.com/images/smilies/smilewinkgrin.gif
09-12-2008, 12:07 AM
There's already a wealth of information on this sort of thing.
1) Download the "Basic Analog and Digital" tutorial from Parallax. Go to their main web page, use the Resources tab, choose Downloads, then choose Stamps in Class Downloads.
2) Look through the Nuts and Volts Columns for the several columns on digital to analog conversion. The Nuts and Volts index is off the Resources tab.
09-12-2008, 01:23 AM
Thanks Mike for the infomration. I'll check it out.
09-12-2008, 02:08 AM
Most digital to analog converters operate at 3.3V or 5V. With a Stamp, you'd use a 5V device which typically produce a 0-5V output. You'd need an op-amp on the output to amplify that to a 0-10V range and the op-amp would need to operate from a 10V or 12V or higher supply voltage. The manufacturer's datasheets for many digital to analog converters often have examples of this shown.
09-12-2008, 03:28 AM
I have never used this before, but the PWM command is designed to output analog voltage from an I/O pin.
Pulse-width modulation (PWM) allows the BASIC Stamp (a purely digital device) to generate an analog voltage. The basic idea is this: If you make a pin output high, the voltage at that pin will be close to 5V. Output low is close to 0V. What if you switched the pin rapidly between high and low so that it was high half the time and low half the time? The average voltage over time would be halfway between 0 and 5V (2.5V). PWM emits a burst of 1s and 0s whose ratio is proportional to the duty value you specify.
The proportion of 1s to 0s in PWM is called the duty cycle. The duty cycle controls the analog voltage in a very direct way; the higher the duty cycle the higher the voltage. In the case of the BASIC Stamp, the duty cycle can range from 0 to 255. Duty is literally the proportion of 1s to 0s output by the PWM command. To determine the proportional PWM output voltage, use this formula: (Duty ÷ 255) x 5V. For example, if Duty is 100, (100 ÷ 255) x 5V = 1.96V; PWM outputs a train of pulses whose average voltage is 1.96V.
In order to convert PWM into an analog voltage we have to filter out the pulses and store the average voltage. The resistor/capacitor combination shown below will do the job. The capacitor will hold the voltage set by PWM even after the instruction has finished. How long it will hold the voltage depends on how much current is drawn from it by external circuitry, and the internal leakage of the capacitor. In order to hold the voltage relatively steady, a program must periodically repeat the PWM instruction to give the capacitor a fresh charge.
Just as it takes time to discharge a capacitor, it also takes time to charge it in the first place. The PWM command lets you specify the charging time in terms of PWM duration. The timing for the units in Duration is shown in in the table above. So, on the BS2, to charge a capacitor for five milliseconds, you would specify five units in Duration.
How do you determine how long to charge a capacitor? Use this rule-of-thumb formula: Charge time = 5 x R x C. For instance, the circuit below uses a 10 kΩ (10 x 103 ohm) resistor and a 1 µF (1 x 10-6 F) capacitor:
Charge time = 5 x 10 x 103 x 1 x 10-6 = 50 x 10-3 seconds, or 50 milliseconds.
Since, on the BS2, each unit in Duration is approximately a millisecond, it would take at least 50 units to charge the capacitor. Assuming the circuit is connected to P0, here's the complete PWM instruction: