Tag Archives: compare mode

Timers in Compare Mode – Part I

Hi Friends, In last tutorials we discussed about the basics of TIMERs of AVR. In this tutorial we will go a step further and use the timer in compare mode . In our first tutorial on timer we set the clock of the timer using a prescaler and then let the timer run and whenever it overflowed it informed us. This way we computed time. But this has its limitations we cannot compute time very accurately. To make it more accurate we can use the compare mode of the timer. In compare mode we load a register called Output Compare Register with a value of our choice and the timer will compare the current value of timer with that of Output Compare Register continuously and when they match the following things can be configured to happen. A related Output Compare Pin can be made to go high,low or toggle automatically. This mode is ideal for generating square waves of different frequency. It can be used to generate PWM signals used to implement a DAC digital to analog converter which can be used to control the speed of DC motors. Simply generate an interrupt and call our handler. On a compare match we can configure the timer to reset it self to 0. This is called CTC – Clear Timer on […]