Author Topic: How to use functions in timer.h of avrlib?  (Read 3935 times)

0 Members and 1 Guest are viewing this topic.

Offline harisankarsaTopic starter

  • Jr. Member
  • **
  • Posts: 23
  • Helpful? 0
How to use functions in timer.h of avrlib?
« 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...

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 952
  • Helpful? 5
  • cooll
Re: How to use functions in timer.h of avrlib?
« Reply #1 on: April 15, 2008, 11:14:45 AM »
is there any timer.h in the avr library??

are u talking abt delay.h?
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline Trumpkin

  • Supreme Robot
  • *****
  • Posts: 1,176
  • Helpful? 5
Re: How to use functions in timer.h of avrlib?
« Reply #2 on: April 15, 2008, 03:17:51 PM »
there IS a timer.h.
Robots are awesome!

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
Re: How to use functions in timer.h of avrlib?
« Reply #3 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.
« Last Edit: April 15, 2008, 03:29:28 PM by pomprocker »

Offline harisankarsaTopic starter

  • Jr. Member
  • **
  • Posts: 23
  • Helpful? 0
Re: How to use functions in timer.h of avrlib?
« Reply #4 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..

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 952
  • Helpful? 5
  • cooll
Re: How to use functions in timer.h of avrlib?
« Reply #5 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);
}
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to use functions in timer.h of avrlib?
« Reply #6 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);

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 952
  • Helpful? 5
  • cooll
Re: How to use functions in timer.h of avrlib?
« Reply #7 on: April 25, 2008, 08:03:10 AM »
i think that is delay.h header file or does it vary from versions to versions
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"