Connect with us

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

Discussion in 'Microcontrollers, Programming and IoT' started by A.L.Z, Apr 3, 2015.

Scroll to continue with content
  1. A.L.Z


    Apr 3, 2015
    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 ?
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    Nov 17, 2011
    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.
    Arouse1973 likes this.
  3. A.L.Z


    Apr 3, 2015
    @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
  4. alex Chiu

    alex Chiu

    Apr 1, 2015
    Another alternative is using the 60Hz power line. Use interruption of a MPU is OK, but may be complicated!
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day