Monday, 4 June 2012

Stable Analog Output

It took me a while to remember about RC circuits. A really key thing is to avoid sourcing any current out of the circuit. Keep the power way down and keep everything that's measuring really high impedance is probably good all-round advice.

Connect a resistor to the analog output (red wire). Connect a capacitor (crimped end positive) from the resistor to ground (green wire). Measure the voltage where the capacitor and the resistor meet (yellow wire) with a high impedance device like an analog input.

The time constant tau = RC is in microseconds if the resistance is in Ohms and the capacitance is in microFarads,  so a 10K resistor and a 33uF capacitor gives tau = 330,000 us or about a third of a second for really smooth transitions. Switching down to a 2.2 uF makes it 22 ms which follows human scale pretty well while still averaging over many PWM cycles at 1 kHz. The graph below shows results for different resistor and capacitor combinations. The direct connection seems to have its frequency response compromised by the other circuits. The 2.2ms yellow squares are noisy, while the 33 ms red exes and 47 ms triangles respond quickly, yet follow closely. The 330 ms grey diamonds lag substantially. The sampling rate wasn't high enough to resolve the PWM, so connecting the dots would give an aliased apparent oscillation frequency.

If you need to drive anything with the with the analog voltage, then it will need something to isolate it from the current draw, like a transistor, or an op amp as a voltage follower.