Originally Posted by moppedclean
Well, I am very familiar with programming PIC's but I'll see if I can lend some of experience to use with AVR's.
To be honest, I use loops for all of my timing. The easiest way I've found is to create a subroutine that has a timing delay of 1ms. Just look at the instruction set summary and see how many clock cycles each instruction takes. Each clock cycle should take 1/4 us. Once you have the subroutine of 1ms, timing is really easy. In lame programming it would look like this:
move #ms in to count1
loop
call subroutine for delay of 1ms
decrement count1 by 1
test to see if count 1 is zero
if not zero, go back to loop
if zero, timing operation done.
It depends on what you have interrupts doing to determine whether you should worry about them happening during a timing loop and screwing it up. In my case, I have only used interrupts for turning the gun off, so as you can see in this case, it really isn't an issue. But say, if you had a button that was an interrupt used for turning the eye on/off, and it flashed an led to indicate that, then yes it could throw off your timing if it happened in the middle of the loop.
The free counting timers as mentioned are also another valid option. Just from my experience with PIC's, it is an 8-bit register that increments every cycle unless some type of scaler that was mentioned is put on the timer- and then when it overflows an interrupt is triggered. What I would do is set the mutiplier/prescaler to 1024. Then an interrupt would be triggered approximately every .25 ms. Then you can use an inner loop of 4 to time 1ms and the outer loop to time the # of ms you want.
I think I might have to get in to programming AVR's. I've always wanted to program a new chip for my Tribal BBT and it might be kind of fun to get in on this project.