Check out the new projects site for A-i-S www.adventuresinsilicon.com

Wednesday, July 15, 2009

Timer problem, timer solution

With an AVR Mega32, when using a timer such as Timer2 (8-bit), you do not want to toggle the output pin as this will only give you a 50% duty cycle and you will only be able to control the frequency of that 50% cycle.

This is because the pin is cleared on reaching TOP. So you want to set the pin on match and let it automatically clear on top.

So for Timer2 on the Mega 32 you want to set the TCCR2 register to something like this

TCCR2 = 0b01111011; //0x7B

No comments: