Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
#include "timer.h"//im not using a crystal on my atmega644setup_timer //prescaling and stuffwhile(1){reset_timer //make timer go to zerowhile(timer < 2ms) //i dont care for anything above 2ms so no need to track overflows { do_stuff(); }do_other_stuff();}
#include "timer.h"void do_other_stuff(void); //define this lattervoid init(){ //setup the timer0 with appropriate bits timerAttach(SIG_OVERFLOW0, do_other_stuff); //other initialzation stuff}int main(void){ init(); while(1) { //just do_stuff() and the timer will automaticaly run do_other_stuff() }}void do_other_stuff(void){ //the other stuff you want to do}
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8); //Set Timer1 prescaler to 8set_timer1(0); //reset timerwhile(get_timer1() < 2000) //~2ms has passed { timing=get_timer1(); do_stuff(); printf("Time passed: %d", get_timer()); //logs the time it took to do_stuff() }