Maker Pro
Maker Pro

Servo Issue

J

-john

Jan 1, 1970
0
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
 
M

Matthias Melcher

Jan 1, 1970
0
-john said:
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.

Get a scope. I have built a controller for 14 servos with a pic and
played around for three weeks, tearing many of my hairs out until I
finally got a scope for $40 on E Bay (anything will do, you are
measuring really low frequencies). After that, I finished the task in
two more days. And the scope became my best friend in many projects that
followed.

The scope will also tell you if your pulses are actually 0V to 5V,
rectangular, etc. . You may need an in line resistor (300Ohm) and a
second pull up (3kOhm) to make the signal nice for your servo.

If you really don't want to spend money on a scope, then write a routine
that makes an LED blink at 1Hz or so, and use a stopwatch to verify your
assumptions on instruction timing. This will also tell you if your
processor actually does run at the frequency you think it does, or if
you oscillator needs help... .
 
Top