I'm having a bit of an issue with the simple (well I thought it was going to be simple) task of controlling a servo motor with an AVR micro. I have it in my head to make a much larger project out of this but wanted to get just one motor controlled first; glad that I did given it's not working.
I understand the basics (I think) all I should need to do is generate a
1-2ms pulse every 20+-ms (according to the specs the motor's I've got say 0.9-2.1 every 16-23ms) I have written some simple code to do just that (and nothing else). I don't have a scope to truly verify the pulse duration or frame time but according to my calculations and the simulator they are correct.In case it matters to anyone I'm using GWS Servos and an ATMega8515 internally clocked at 8MHz, that gives me 8MIPs so that means 1 instruction(ck) take 125ns, meaning 1ms=8000ck right? given that, and let me know if I'm wrong there, the code take the output high then delay slightly less than 8000 ck then start decrementing a counter 0-FF times taking 32 ck per cycle, finally taking the output low again. By my calculations and what I see in AVR Studio's Simulator that gives me aprox. 0.99-2.01ms pulse every 20.002ms which seems like it would work, yet all the motor will do is turn CW... and seems to try to keep trying to turn even after hitting the stop at +90 deg. This seems like it should mean my pulse is too short but it doesn't behave any better when I arbitrarily increase the pulse. I've tried a number of different combinations, even orders of magnitude off, in both directions, for both pulse width and framing, and still get the same results.
Sample code provided if requested (don't want to spam anyone if no one cares to see it) Any help would be appreciated; Thanks
-john