Introduction: Arduino 10 Bit Analog Output
Standard pwm output from the Arduino has an 8 bit resolution. This project improves the resolution for an analog output to around 10 bits, plus has a much faster settling time and allows up to six analog outputs. The project uses only one resistor and one capacitor and one arduino pin, and uses a software trick where an analog input pin can be turned into an output, then used to charge or discharge a capacitor, and then turned back into an input to read back the value.
If you add a standard RC low pass filter to the pwmout signal on an arduino the output looks noisy on a CRO, and fluctuates considerably if another arduino samples the voltage. Fancy multipole filters use lots of components. Adding a very large RC filter (eg 100k and 100uF) means it can be ten seconds for the output to stabilise, plus you have to be careful about internal leakage within the capacitor, using tantalum capacitors instead of electrolytics.
This circuit does all the clever work in software and uses a 10k resistor and a 1uF greencap capacitor. Sample the voltage on the capacitor, rapidly charge or discharge to near the correct value, eg 50 millivolts, then apply brief charge or discharge pulses of around 1 microsecond to keep the value correct. Settling time is around 1 millisecond which is 100,000 times faster than using a large RC on pwmout. The self discharge of a greencap polyester capacitor or a tantalum means that 1 microsecond adjustments are only needed every five or ten seconds.
Stray RF can be an issue so it helps to keep the leads short. Even so, there can be some errors with the ADC on an arduino so to improve this, take twenty samples and take the average.
Perhaps this has already been done before? Anyway, it is a nifty little circuit and code that I am using in a couple of practical circuits, mainly as a simple way of sending information between Arduino's as an analog voltage.
We have a be nice policy.
Please be positive and constructive.