Using AVR Timer/Counters: Pulse Width Modulation Modes
Two excellent tutorials have already been written about the AVR timer/counters, and I want to fully acknowledge this excellent work. The tutorials are by abcminiuser (aka Dean Camera) on the this forum. It's not my purpose to steal any of Dean's thunder, since I know he plans to explain PWM and has already started that section of his tutorial. It seems to me that PWM is complex enough that it can bear explaining twice, and it seems that Dean's approach is to explain it from the audio and analog waveform creation viewpoint. My viewpoint will deal much more with motor and appliance control techniques with PWM.
While Dean's tutorials very thoroughly cover Normal and CTC Modes of the AVR timer/counters, I want to recap these modes briefly so we’re all on the same page. The discussion may seem redundant, but will serve as a useful refresher and makes sure that all the basics are covered to provide the background needed for this tutorial. We're going to be looking at some figures which will help explain the workings of PWM mode. For these figures to make sense, we'll develop them one step at a time from the simplest timer/counter modes to the more complicated. Some timer/counter basics need to be explained so we can build on them as well. I hope you find this approach will make the PWM modes easier to understand.
Note that everything Dean tells us about the Atmega16 timer/counter 1 applies to timer/counter 1 on the ATtiny2313. The only difference is the actual pin numbers of the output pins.
Let's get started!
Let’s start with a basic definition. What is a timer/counter? A counter is one of many registers in a modern microprocessor and simply counts events, that is, electrical pulses. Each time a pulse is applied to a counter, the value in the counter increments by one. If the pulses are applied at a known, constant rate, then the counter becomes a timer. Knowing the pulse rate and a...
Please join StudyMode to read the full document