Go Down

Topic: Servo and Analog Question (Read 763 times) previous topic - next topic

Ben1234

Is it possible to use analogWrite() to control a servo? Can you use an analog pin instead of a digital PWM pin to control the position of a servo and if so how? I have read the PWM tutorial but am still a confused.

AWOL

You can, but you shouldn't.
PWM from an analogWrite runs at just short of 500Hz, but the servo expects 50Hz.
Even if you do get it down to 50Hz, eight bit resolution isn't really good enough to give fine enough control.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Ben1234

Will it damage the servo or Arduino? Do you think it would be fine to run continuos servos off of them if I did not care about the speed. Really all I want them to do is be able to run forward and backward.

oric_dan

What you need to control a servo are pulses 1000-2000 usec long which repeat every 20-msec,
and ideally with 1-usec resolution. IE, 1000 usec, 1001 usec, etc. As AWOL indicated, that's
difficult to get using analog.write(). You notice it's only a 5-10% duty-cycle on a PWM signal,
assuming you can get one to go as slow as 50-hz.

BTW, 1000-2000 usec moves the servo +/-45 degrees from center. And in actuality, most servos
can be driven close to +/-90 deg off center with a wider pulsewidth range, approx 750-2250 usec,
but this varies with the specific servo.

PaulS

Why not use the Servo library? What you want to do (make a servo move) is exactly what it was designed for.

AWOL

The servo will probably consume more current at 500Hz than it would at 50Hz, and it could overheat.
Why do you want to do this?
Why not just use the Servo library?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Grumpy_Mike

It was often said by some members here that PWM will damage a servo because it needs PPM, pulse position modulation.

AWOL

In multi-channel R/C, the multiplexed signal carrying all channels between transmitter and receiver is PPM, but by the time it is demultiplexed and reaches the servo or ESC, it really is PWM, but very low duty cycle.
However, the default PWM frequency of the Arduino is far too high for common R/C equipment.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Ben1234

If I use the servo library and have myservo.attach(9) that is saying it is on digital pin 9. How could I change that to analog pin A1?

zoomkat

Quote
Will it damage the servo or Arduino? Do you think it would be fine to run continuos servos off of them if I did not care about the speed. Really all I want them to do is be able to run forward and backward.


With continous rotation servos, the servo probably won't be damaged, it just won't operate as you expect. With a regular servo bad control signals can make the servo rotate until it is against the hard stop, where damage then can occurr. Give it a try and see how it works.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

oric_dan

Quote

The servo will probably consume more current at 500Hz than it would at 50Hz, and it could overheat.


The internal control loops in standard analog servos will not operate at 500Hz. They will operate to
about 100Hz [10-msec update], but any faster than that and the servos goes bonkers under loaded
conditions because the control loops crash. Digital servos can accept faster control updates, but
I'm not up on the details.

DuaneB

Hi,
   The Servo library is very good and allows you to control a large number of servos on more or less any pin.

Here is some background -

http://rcarduino.blogspot.com/2012/01/can-i-control-more-than-x-servos-with.html

There are some aliases in Arduino which allow you to refer to the analog pins in digital functions, I haven't tried this myself, but the following may work for you

myServo.attach(A1); // A1 is the alias for analog pin 1, use An for whichever analog pin you want where n = 0 to 5

Duane B

rcarduino.blogspot.com
Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

Go Up