Society of Robots - Robot Forum
Software => Software => Topic started by: Admin on February 15, 2007, 11:08:38 AM
-
since im moving from PIC to AVR, im having issues with the syntax . . . below is the code i want to use on my atmega644, preferably with the timer.h library that comes with AVRlib . . .
can someone put in the correct syntax for me? im sure someone has some source they can quickly reference . . .
#include "timer.h"
//im not using a crystal on my atmega644
setup_timer //prescaling and stuff
while(1)
{
reset_timer //make timer go to zero
while(timer < 2ms) //i dont care for anything above 2ms so no need to track overflows
{ do_stuff(); }
do_other_stuff();
}
-
I'm kinda confussed on what you want your timing to look like.
What you could do is attach your do_other_stuff() function to a timer and when that timer trips
(every 2ms or whatever you set it up to be) it will run with out fail.....
Does that help? void timerAttach(u08 interruptNum, void (*userFunc)(void) );
So if you set up timer0 to overflow every 2ms, in your setup before
your main loop you would do this:
timerAttach(SIG_OVERFLOW0, do_other_stuff)
#include "timer.h"
void do_other_stuff(void); //define this latter
void 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
}
You can also detach the function if you want to stop doing other things.
-
hmmmm ok perhaps I explained it poorly.
first, i want to set up the prescaler so that my timer does not overflow in less than 2ms.
second, i want to know what the timer value actually is. that way i can print out the exact time over serial for a datalogger, and do other things with that value.
this is the working PIC code I want converted to work on AVR:
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8); //Set Timer1 prescaler to 8
set_timer1(0); //reset timer
while(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()
}
-
ever figure this out?
-
yeap
this post was back when i was developing the $50 Robot
(the solution is in the $50 Robot source code)
-
All I see in the SoR_Utils header file is
//timerInit(); // initialize the timer system
I don't see any commands for starting, stopping, reseting, etc...
So I started playing around with TCNT0, TCCR0, etc...
-
oops sorry I wasn't thinking in my last post . . . :-X
This question was for a *very* early Axon prototype. Originally I was using the 644, and had no plans to make it a product.
The solution is in the current Axon code.
If you want to see the alpha Axon, its in the video here:
http://www.societyofrobots.com/sensors_accelerometer.shtml