Maker Pro
Maker Pro

How can I configure an AVR microcontroller timer to generate periodic interrupt events at 60 Hz rate

I just want to use timer / counter of AVR microcontrollers and crystal 14,750 MHz to configure 60 Hz frequency . Is there any one who can help me ?
 

Harald Kapp

Moderator
Moderator
Welcome to electronicspoint.

You will not be able to achieve exactly 60 Hz without some tricks. A timer can only divide by an integer number of cycles.14.75MHz/60Hz=245833.33333, the next integer divisor is 245833 Since 245833 exceeds the capability of a 16 bit timer, you need to activate the prescaler. Use e.g. prescaler = divide-by-8, that leaves you to count to 30729 (8*30729=245832) to let the counter run at 60 Hz.

Set the timer to "Clear Timer on Compare Match (CTC) Mode" operation with an output compare value of 30729. Set the OC1A output to toggle on each comare match. The output frquency is defined by
fOCnA = fclk_I/O / (2*N*(1 + OCR1A)) where N is the prescaler (8) and OCR1A is the output compare value.
Note: you want to toggle the output at 60 Hz, that is 2* within a 60Hz cycle, therefore you need to set OCR1A to 1/2*30729=15365.

The details of implementation depend on the type of AVR you use and the programming language.
 
Top