Hi, i'm a newbie, I just learn about Arduino. I'm already working on the Servo and have some questions to ask:
As I understand the Servo received PPM (Pulse Position Modulation) to find the location. Why receive pulses PPM to controller? Using PWM pulses, rotary servo do not? The difference between PPM and PWM pulse?
The servo expects to receive a pulse every 20 milliseconds roughly but only from 1-2 milliseconds to controller 180 degree. Why so ??
Servo communicate with Arduino using which protocol? Protocols that how it works?
<Servo.cpp>
#define usToTicks(_us) (( clockCyclesPerMicrosecond()* _us) / 8)
int Servo::read() // return the value as degrees
{
return map( this->readMicroseconds()+1, SERVO_MIN(), SERVO_MAX(), 0, 180);
}
int Servo::readMicroseconds()
{
unsigned int pulsewidth;
if( this->servoIndex != INVALID_SERVO )
pulsewidth = ticksToUs(servos[this->servoIndex].ticks) + TRIM_DURATION ; // 12 aug 2009
else
pulsewidth = 0;
return pulsewidth;
}
I do not understand the above code? Can you explain it?
#define usToTicks(_us) (( clockCyclesPerMicrosecond()* _us) / 8) This line means how?
The name(s) used to describe servo control signals are unfortunately confusing. Strictly speaking it is Pulse Width Modulation (PWM). A pulse with of 1000 microsecs (usecs) represents 0 degrees, 1500 usecs represents 90 deg and 2000 usecs represents 180 deg. Normally these pulses are repeated 50 times per second. In the Arduino these pulses are produced by the Servo.write() and Servo.writeMicroseconds() functions and can appear on any pin.
PPM is used in a very confused way to describe the string of pulses for several servos that is sent by an R/C transmitter.
However PWM is also used to mean a system to control the amount of power transmitted to an LED or an electric motor - and in the Arduino this is done with the analogWrite() function. The duty cycle can vary between 0 and 100% using values from 0-255. The pulse frequency is much higher than for a servo and it is only available on the PWM pins
The Arduino does have a Servo.read() instruction but it only gives you the value you last sent with Servo.write().
RC Servos originate from a time when RC was done with analog electronics. What the transmitter did was reading its controls sequentially and assigning a pulse length proportional to each controls setting and transmitting these pulses. The receiver then multiplexed the received pulses to the different servos.
As mentioned, the standard "protocol" for Servos is a pulse of ~1000-2000 microseconds, spaced inside a cycle of 20ms. It's not a law of nature, just the way it was decided.
Arduino "analogWrite" PWM is done within a cycle of ~2ms overall (HIGH time + LOW time) so it's not appropriate for Servos.
The code line defines a Macro to return a calculation: you give it a number ("_us") that represenst, I guess, Microseconds, and it returns the number of Arduino system clock ticks that match that period... divided by 8, I'm not entirely sure why.
The attached o'scope screenshot shows the repeating pulse. This particular shot is immediately after a servo.attach(), which centres the servo with a 1500us pulse by default. The result for a write with any value from 1000-2000 would be similar, with different width of course.
Sorry to jump into this ques with another ques but I was thinking that if I ask another question about servos on this Forum topic " Some questions about Servo? " it will be useful for others.
Q1 Does the comparator circuit contained in the electronics compare the PWM input signal and a PWM signal generated by the Pot ? or does it like compare the voltage converted from the PWM input to the voltage acquired by the pot ?
Also, Q2 what is the difference apart from the dimension and shape of the Hobby Servo Motor and the DC Servo motor like in this link DC Servo Motor ?
Continuation for Question 2. What is the difference in the control methods employed by the DC servo motor and the hobby Servo motor ?
Izzy92:
Sorry to jump into this ques with another ques but I was thinking that if I ask another question about servos on this Forum topic " Some questions about Servo? " it will be useful for others.
Q1 Does the comparator circuit contained in the electronics compare the PWM input signal and a PWM signal generated by the Pot ? or does it like compare the voltage converted from the PWM input to the voltage acquired by the pot ?
Also, Q2 what is the difference apart from the dimension and shape of the Hobby Servo Motor and the DC Servo motor like in this link DC Servo Motor ?
Continuation for Question 2. What is the difference in the control methods employed by the DC servo motor and the hobby Servo motor ?
Both the PWM value and the arm position are values that are compared internally by the servo inner workings, these can be analog or digital but normally of little interest for the user. I guess that in a analog hobby servo the PWM value is converted to a voltage by some ramp and hold circuit
A DC servo differ from a hobby servo in that it has continuous rotation, better and more exact positioning by feedback through encoders or resolvers and higher power. The control is often issued by sending position or speed commands throug a serial protocol (RS485). There are also DC servos intended to replace a stepper motor, these take step and direction pulses. Often the parts of a DC servo system are bought separate, motor, encoder and electronics
By example default , Servo.attach(9); // attaches the servo on pin 9 to the servo object (~PWM)
But i try to Servo.attach(7); (not ~PWM) Servo is still running.
Why so???
I was wondering also. When the input signal asks for the arm of the hobby servo to go to 90 degrees, does the 90 degrees correspond to 90 degrees movement of the arm from the centre and/or does this 90 degrees correspond to the movement of 90 degrees(regardless of direction) of the shaft of the motor in the Hobby Servo motor?
Strictly speaking, the pulse is not set to a number of degrees, it's microseconds where 1000 is fully one way and 2000 is fully the other way, with 1500 in the middle.
The servo.write() method sends 1000 if you say 0, 1500 if you say 90 and 2000 if you say 180.
So the degrees you command is a "move to x degrees" not a "move by x degrees".
The above assumes a conventional 0-180 servo, not a continuous rotation "servo".
So in a sense lets say i input a command 180. and the pwm send will be 2000. all well and good. but does the the shaft of the dc motor contained 'inside' the hobby servo motor rotate continuously until the arm (above the servo's containment) reaches the 180 degree mark( lets say full right) ?
Yes, assuming it's not there already, and assuming it has the torque to do that.
If it's there already, the pulse just keeps it there so to speak, and in fact the Arduino library does send a repeat command to hold the servo in place every 20ms (50Hz) as long as you don't send a new position or a servo.detach().
See my reply #4 earlier for o'scope screen shot.
If the servo physically can't get to where you want it to go, eg if it's too weak, you won't know that; most servos have no feedback to the world outside the servo. Internally it will know it's not there yet and will keep driving, but you will most likely assume it arrived.
One needs to remember that what controls servo positioning is the electronics in the servo responding to an electronic signal, and not the concept of "degrees" and such. The gearing in the servo is sometimes different making for different positioning of the servo horn. The below shows some of the electronics in a typical analog servo.