EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / timer running slow

timer running slow

|

Microcontroller › AVR › timer running slow

  • This topic has 2 replies, 3 voices, and was last updated 11 years, 7 months ago by Ashutosh Bhatt.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • September 10, 2014 at 5:30 am #3251
    himanshu mittal
    Participant

    sir,

         sir i have configure the timer correctly but my timer running slow nearly at 4 mhz. i have used 16 mhz crystal..i have written proper fuse bits to work with 16 mhz crystal (C9FF).I  have given prescaler to 1024. but i can’t understand the problem..

     

    my code is like…

     

    //  digital clock using timer–

     

    #include<avr/io.h>
    #include<avr/interrupt.h>
    #include”avr/LCD2014.h”
    #define BITx (1<<x)
    #define CHECKBIT(x,b) x&b
    #define SETBIT(x,b) x|=b
    #define CLEARBIT(x,b) x&=~b
    #define TOGGLEBIT(x,b) x^=b
    #define BIT0 0x01
    #define BIT1 0x02
    #define BIT2 0x04
    #define BIT3 0x08
    #define BIT4 0x10
    #define BIT5 0x20
    #define BIT6 0x40
    #define BIT7 0x80
     
    unsigned int sec,min,hour,p;
     
    ISR(TIMER0_OVF_vect)
    { p++;
      if (p>61)
    {
          sec++;
     p=0;
    if(sec>59)
    {
    sec=0;
    min++;
    if(min>59)
    {
    min=0;
    hour++;
    }
    }
    }
    lcd_cmd(0x80) ;
    lcd_string(”  “);
    lcd_cmd(0x82);
    lcd_value(hour);
     
    lcd_string(“:”);
     
    lcd_value(min);
    lcd_string(“:”);
    lcd_cmd(0x86);
    lcd_value(sec);
     
     
    }
     
    int main(void)
    {
    lcd_init();
     p=0; 
    sec=0;
    min=0;
    hour=0;
    TIMSK=BIT0;    // enable timer0 overflow interrupt
    TCCR0=BIT2|BIT0;     // sert prescaler to 1024 in normal mode
    TCNT0=0;
     
    sei();
    while(1)
    {
     
    }
    }
    September 10, 2014 at 6:39 am #12143
    AJISH ALFRED
    Participant

    Hi,

    You have included the lcd functions inside the ISR. These functions take more time than the timer firing period, and you will miss a lot of timer interrupts when these functions are executing inside the ISR.

    The solution is to keep the lcd functions in the main code.

    September 11, 2014 at 1:46 am #12148
    Ashutosh Bhatt
    Participant

    ISR should be as short as possible so as to service next ISR. 

    possible solution just update values in ISR dont display

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Getting into an LED bulb April 21, 2026
  • understanding of resonance in time domain April 21, 2026
  • Beginner Questions About CNC Machines – G-code, Control Systems & Accuracy April 21, 2026
  • A Must-Watch Video Showing Dangerous Construction of Cheap Lithium-Ion Cells April 21, 2026
  • S1MJ ? April 20, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise