I'm trying to figure out a good way to drive a stepper motor's step input fairly quickly (due to a large gearing ratio that has to be used). This is on a board with an atmega64 running at 16 MHz. I've tried two ways so far, both with timer/counter 1 in CTC mode. Using the "Toggle OCnA/OCnB/OCnC on Compare Match" option, I can get it to operate very quickly, up to a few MHz stepping frequency. But the problem is that I need to know how many steps have happened. To facilitate this, I added an interrupt on the CTC match to increment a volatile global integer, and performed the actual toggling of the bit during this interrupt. Unfortunately, this can only run up to around 150 kHz. The only other possibility that I can think of is not counting steps directly, but timing it with another counter to calculate steps from the frequency, but this kind of sucks. If the frequency changes during a timing cycle, or if something was reset oddly, it would become inaccurate. Any suggestions on getting a fast, countable frequency output? At the current motor settings and gearing ratio, there are 4915200 steps/revolution. At 150 kHz, it would take about 32 seconds to make a full revolution, which is a bit slower than I would like.
Edit: I just realized that this isn't necessarily AVR GCC related... I guess I posted this here out of pure habit. Not sure how to change its location now.
Edit: I guess a possible solution could be to decrease the stepper motor driver board's number of steps per revolution. It's currently set to 51200, which is multiplied by 96 by the gearing. If I set this to 25600 instead, 150 kHz means 16 seconds per revolution. I should only need so much resolution anyways. If I'm able to move about 0.01 degrees per step, I'll be good.