[AVR] 500ms delay using timer in ATMEGA8

Status
Not open for further replies.

djc

Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,554
Hi,

Can somebody guide me how to generate 500 ms delay using any of the timer like Timer 0 or Timer 1 of ATMEGA8.
 

For ATMEGA8 at 8 MHz Clock.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Timer1 Prescaler = 64; Preload = 62499; Actual Interrupt Time = 500 ms
 
//Place/Copy this part in declaration section
void InitTimer1(){
  SREG_I_bit = 1; 
  TCCR1A = 0x80;
  TCCR1B = 0x0B;
  OCR1AH = 0xF4; 
  OCR1AL = 0x23; 
  OCIE1A_bit = 1; 
}
 
void Timer1Overflow_ISR() org IVT_ADDR_TIMER1_COMPA {
  //Enter your code here 
}

 

Thank you jayanth and nick, i am able to generate 500ms interrupt now.
 

hi jayanth,

I am again facing a problem in timer reload value. Now i want to generate 1sec output compare interrupt. So how to calculate timer reload value. Please guide me.
 

Thanx alexan,

I found the fault where i was actually lacking.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…