So you’ve got a microcontroller and you want to use it to control something analog. That’s a common task, and a number of good solutions exist, depending on exactly what you need to do.
Most microcontrollers do not include built-in digital-to-analog conversion (DAC) hardware, and external converters cost money. There is, however, a quick, easy, and cheap little trick of a solution that can be played by averaging a digital output.
This is a short tutorial on making useful (but crude) analog output signals with a low-cost microcontroller. The analog signals will be made by averaging a digital pulse width modulation (PWM) output from one of the counter/timer units in the microcontroller, and do not require any dedicated digital to analog conversion hardware. We will first introduce some aspects of the counter/timer and discuss how it can be used to generate the pulse width modulation signal. After that, we’ll implement the scheme on an AVR microcontroller and use it to make a simple and slow little function generator circuit.
Continue reading Quick and Dirty D to A on the AVR: A timer tutorial