Go Down

Topic: microsecond interrupt? (Read 5 times) previous topic - next topic

Hoeken

hey, just wanted to say thanks again for your help.  with this function, i was able to get non-blocking stepper control working!!!  if you've ever used the built-in stepper library for arduino, you know that its blocking... ie you either have to call each step manually, or just deal with waiting until the steps are done to do more stuff.

using this function, i made a class so that you simply do if(stepper.canStep()) stepper.step();  and the stepper will step at the appropriate time, at the appropriate RPM.  this is nice because you can do things like control multiple steppers independently, etc.

more info, video, and code in blog post: http://builders.reprap.org/2007/11/non-blocking-stepper-control.html

MikeD

This code doesn't seem to work any more.  I get an error when compiling: undefined reference to 'timer0_overflow_count'

Any suggestions on how to fix this?

Thanks,
Mike

MikeD

I managed to work out my own solution, but I'd still be interested in why timer0_overflow_count doesn't seem to exist anymore.

My code for the curious:
Code: [Select]
 double tElapsed=0;
 
 //Refer to document http://www.atmel.com/dyn/resources/prod_documents/doc7530.pdf
 TCCR1A=0; //set WGM mode to normal. Refer to table 15-4 of above doc
 TCCR1B=B100; //set prescaler = 256.  Refer to table 15-5 of above doc
 int prescaler=256;
 TCNT1=0; //set timer to 0. This is a 16 bit timer. Timer overflows at 1.048 seconds with prescaler=256

//...time an event or some code
 
 tElapsed = TCNT1*1.0/16E6*prescaler; //time in seconds

mem

#8
Dec 24, 2008, 02:00 pm Last Edit: Dec 24, 2008, 02:01 pm by mem Reason: 1
Hi MikeD,

Floating point is wasteful processing time (and memory) and should be avoided if possible in code that is time critical. Also, the code posted above uses a prescaler of 256 so with a 16mhz clock it can have an error of up to 127 microseconds.

Here is a thread that has a discussion on precise timing on the Arduino: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1226014847

westfw

Quote
I'd still be interested in why timer0_overflow_count doesn't seem to exist anymore.

The old timer0/millis() algorithms had a significant problem with integer overflows after sketches had been running for "a while."  In 0012, the way times were calculated was changed to fix this, and in the process it eliminated the timer0_overflow_count()

Go Up