Stepper Motor Driving

Hey All,

Okay, so I'm wanting to drive some steppers with Arduino, and I've looked at the Stepper library. The steppers I'm trying to drive are 200 step motors, and I'm pretty sure I can drive them at 30-40 RPM.

Here's the dilemma: the delay time between steps is calculated like so: 60 seconds * 1000 / 40rpm / 200 steps = 7.5 milliseconds between steps. Since this value is an integer (or technically, unsigned long??) It gets rounded to either 7 or 8 (i havent checked the real value) Also, eventually I'm going to want to do half-stepping. That doubles the number of steps, and gives me a value of 3.75. at that point the timing becomes crucial.

What I really need is to store this value as microseconds and then do the calculations based on that: then it would be 7500 microseconds between steps. Figuring out how many microseconds between steps to use is the easy part.

The hard part is figuring out how many microseconds have passed. Arduino only provides the millis() function, and I'm wondering if its possible to get something like micros(). All I really need is just a counter of how many microseconds have elapsed. Even if it rolls over every few minutes, thats okay with me. I just need to be able to use it for precise timings.

Is there anything l could do to get that? Is there a better approach to this? I've read a tiny bit about interrupt timers, but I don't know much about them. Any help or suggestions would be appreciated.

I think you should be able to to get 4 microsecond resolution by reading the timer0 count register (256 counts = 1.025ms) You could construct a "high resolution" time by concatenating the timer0 overflow count and the timer register contents ( (timer0_overflow_count << 8) + TCNT0) ?

awesome! that seems like a step in the right direction for me. where should i go to read more about this timer0 count register and how to access it through the arduino software? thanks.

i've dug around some more, and this page is helpful: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1180984367