Maker Pro
Maker Pro

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

A.L.Z

Apr 3, 2015
4
Joined
Apr 3, 2015
Messages
4
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
Nov 17, 2011
13,744
Joined
Nov 17, 2011
Messages
13,744
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.
 

A.L.Z

Apr 3, 2015
4
Joined
Apr 3, 2015
Messages
4
@Harald Kapp Hi . I just want to thank you for taking the time , thanks again for your helpful answer. I appreciate you for your knowledge
 

alex Chiu

Apr 1, 2015
14
Joined
Apr 1, 2015
Messages
14
Another alternative is using the 60Hz power line. Use interruption of a MPU is OK, but may be complicated!
 
Top