Society of Robots - Robot Forum

Software => Software => Topic started by: harisankarsa on April 15, 2008, 10:54:34 AM

Title: How to use functions in timer.h of avrlib?
Post by: harisankarsa on April 15, 2008, 10:54:34 AM
Can anyone pls give me sample codes for using functions in timer.h...i have to use timer for calculating time in sec between two interrupts...i also need to do a loop after 5 mins...pls give me some valid codes..its urgent...
Title: Re: How to use functions in timer.h of avrlib?
Post by: superchiku on April 15, 2008, 11:14:45 AM
is there any timer.h in the avr library??

are u talking abt delay.h?
Title: Re: How to use functions in timer.h of avrlib?
Post by: Trumpkin on April 15, 2008, 03:17:51 PM
there IS a timer.h.
Title: Re: How to use functions in timer.h of avrlib?
Post by: pomprocker on April 15, 2008, 03:28:53 PM
there is also a timerx8.h if your running at 8mhz


Check out the timer tutorial under programming here on the site. There is sample code in there.
Title: Re: How to use functions in timer.h of avrlib?
Post by: harisankarsa on April 16, 2008, 07:04:43 AM
I actually need to know how to use the real time clock on the atmega8 chip...pls give me some sample code...its for my final yr project..
Title: Re: How to use functions in timer.h of avrlib?
Post by: superchiku on April 16, 2008, 07:54:55 AM
this is a sample code which i have written  for u which will make the led blink

this is for atmega16 so just change the port and pin no in the ddr... line and ull know how timers will work

Code: [Select]
# include<avr/io.h>
int main(void)  // for 8 mhz internal oscillator 1 sec gap//

{
 DDRC|=_BV(0);//set port c pin 0 as output
 TCCR1B|=(1<<CS12);//start 16 bit timer at prescaler of 256 where 1 sec=31250 clock ticks
 while(1)
  {
 
    if(TCNT1>=31250)

{
  PORTC^=(1<<0);//toggle the pin on and off
  TCNT1=0;//make tcnt1 as 0 for restarting the counter
}
 }
 return(1);
}
Title: Re: How to use functions in timer.h of avrlib?
Post by: Admin on April 25, 2008, 07:36:03 AM
The timer.h file explains exactly how to use it.

Just include the proper files in the makefile and in the header, and just call the functions as described in the AVRlib documentation.

For example, if I wanted to delay 1ms, I'd just call this one line:
delay_ms(1000);
Title: Re: How to use functions in timer.h of avrlib?
Post by: superchiku on April 25, 2008, 08:03:10 AM
i think that is delay.h header file or does it vary from versions to versions