Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6766571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:50:50+00:00 2026-05-26T14:50:50+00:00

On atmega2560 (STK600 board), I am using Timer0 which is 8-bit timer. I want

  • 0

On atmega2560 (STK600 board), I am using Timer0 which is 8-bit timer. I want to generate an overflow every 4ms…how do I set the timer for 4ms? (the clock speed is 8MHz, I am aware of setting up a timer by diving (clock speed)/(prescaler) and when the counter resets, it generates an overflow interrupt. But not sure about setting for 4ms!

Secondly, once the timer overflows and generates an OVERFlOW interrupt, calculate 1 second..How to do that?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:50:50+00:00Added an answer on May 26, 2026 at 2:50 pm

    4ms won’t be possible with the OVERFLOW interrupt:

    F_CPU = 8,000,000hz

    F_OVERFLOW = 1/0.004s = 250hz

    CYCLES_PER_OVERFLOW = F_CPU / F_OVERFLOW = 32,000, i.e.: An overflow should occur each 32,000 CPU clock cycles

    CYCLES_PER_TIMER_TICK = 32,000 / 256 = 125 = prescaler value

    125 is not available as prescaler, but you can use 128 if that’s close enough for your purpose (4.096ms).
    If not, you can consider to use a timer compare interrupt instead of the overflow int. – Or change F_CPU…

    Once you have your interrupt each 4ms, you can increment a global variable on each interrupt and each time the variable’s value reaches 250, another second has passed and the variable can be re-set to 0 to count towards the next second.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I am developing a largish project using at Atmel AVR atmega2560. This project
I connected a device to the UART0 of the AtMega2560. I want to transfer
I am trying to write and read data from EEPROM (microcontroller ATmega2560 ), which
I am trying to write and read data from EEPROM (microcontroller ATmega2560 ), which
For last 2 weeks am trying to learn timer & interrupt & wrote a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.