Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Atmega64a using timer3 facing problem

Status
Not open for further replies.

pallavishanta

Newbie level 3
Newbie level 3
Joined
May 14, 2012
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,300
Hi all,

Am using an atmega64a controller and 8MHz crystal and am beginner to avr timers.. can any one pls help me how to use timer3.. i just want to start a timer3 for 10s and once timer is expired i just want to blink led.

Code:
void start_timer3(unsigned int delay) 
{ 
   timer3_delay = delay * 10 
   ETIMSK |= ( 1 << TOIE3); 
   TCNT3 = // what value must be assigned here confused; 
   TCCR3B |= (1 << CS32) | (1 << CS30);      /* select prescalar of 1024 */ 
   timer3_expired = 0; 
   tmr3_count = 0; 
} 

ISR(TIMER3_OVF_vect) 
{ 
   TCNT3 = // this is what where am stucking am not getting what should be the timer/counter tcnt3 value to be assigned; 
   tmr3_count++; 
   if(tmr3_count >= timer3_delay) 
   { 
      timer3_expired=1; // need to reboot gsm and controller.
      tmr3_count=0; 
      blink_led(); 
   } 
}
 
Last edited:

First you calculate each tick of the timer, for 8MHz clock and 1024 timer prescaler the timer frequency is 8000000/1024=7812.5Hz

1/7813Hz = 0.000128 sec

for 1sec you need 1/0.000128 = 7813 so you should start the timer with an initial value of 65536-7813=57723 and it will overflow after 7813 counts which is 1sec.

The only disadvantage of this method is that you need to reload the initial value of the timer after each interrupt, in CTC mode you could avoid that because it resets automatically.

- - - Updated - - -

You cant have a 10 sec delay with timer. Try to have a 100ms delay and increment a counter one time on every interrupt. When counter is 100 then it will be 10 sec delay.

He is doing one second delays and counts ten interrupts to get 10 sec.
The code is there so maybe you should read it before giving suggestions.
 

    V

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top