microcontroller-actuated servo, number of steps / precision?
#1
Senior Member
Thread Starter
Join Date: Mar 2005
Location: , CA
Posts: 4,900
Likes: 0
Received 0 Likes
on
0 Posts
microcontroller-actuated servo, number of steps / precision?
Right now I am using an Atmel AVR microcontroller (atmega16 series, clock speed = 8MHz) to actuate a servo.
To actuate the servo, the microcontroller generates the PWM signal (instead of an RC receiver).
My question is, how many individual 'steps' (positions) does an individual servo have; is it 256 or is it more? And is it standard or does it differ from servo to servo?
Right now I am using a Futaba S3004 and even with 256 different PWM pulse settings it still seems to jerk a bit rather than move smoothly.
I know it has a least 256 since I already tried 1/256 and 1/1024 timer prescaler settings (see below) and there is a definate improvement in smoothness going to the 1/64 timer prescaler setting. Will I gain even more precision if I go to a timer prescaler setting of 1/8, which will also force me to use the 16-bit timer? I figured I'd ask first, maybe someone else has already done the same thing and I don't want to have to rework everything for no benefit.
This is my interrupt handler that actually moves the servo:
prescaler is set in this line: "TCCR0 = _BV (CS01) | _BV (CS00); // prescaler = 1/64"
SIGNAL (SIG_OUTPUT_COMPARE0) {
/*
// full interrupt-driven implementation
if (cp_state == CP_STATE_DOWN) {
PORTA |= 0x80;
cp_state = CP_STATE_UP;
OCR0 = TIME_INITIAL + servo_up;
} else if (cp_state == CP_STATE_UP) {
PORTA &= 0x7f;
cp_state = CP_STATE_DOWN;
TCNT0 = 0;
OCR0 = TIME_INITIAL;
}
*/
// blocking implementation
TCCR0 = _BV (CS01) | _BV (CS00); // prescaler = 1/64
PORTA |= 0x80;
cp_state = CP_STATE_UP;
TCNT0 = 0;
while (TCNT0 < (SERVO_PREWAIT))
;
TCNT0 = 0;
if (servo_up < 128) {
while (TCNT0 < servo_up * SERVO_MULTIPLIER)
;
} else {
while (TCNT0 < 128)
;
TCNT0 = 0;
uint8_t servo_up_minus;
servo_up_minus = servo_up - 128;
while (TCNT0 < servo_up_minus * SERVO_MULTIPLIER)
;
}
PORTA &= 0x7f;
cp_state = CP_STATE_DOWN;
TCCR0 = _BV (CS02) | _BV (CS00);
TCNT0 = 0;
}
I know the blocking implementation is non-optimal but I don't think a full interrupt-driven implemention could later be expanded to control multiple servos.
To actuate the servo, the microcontroller generates the PWM signal (instead of an RC receiver).
My question is, how many individual 'steps' (positions) does an individual servo have; is it 256 or is it more? And is it standard or does it differ from servo to servo?
Right now I am using a Futaba S3004 and even with 256 different PWM pulse settings it still seems to jerk a bit rather than move smoothly.
I know it has a least 256 since I already tried 1/256 and 1/1024 timer prescaler settings (see below) and there is a definate improvement in smoothness going to the 1/64 timer prescaler setting. Will I gain even more precision if I go to a timer prescaler setting of 1/8, which will also force me to use the 16-bit timer? I figured I'd ask first, maybe someone else has already done the same thing and I don't want to have to rework everything for no benefit.
This is my interrupt handler that actually moves the servo:
prescaler is set in this line: "TCCR0 = _BV (CS01) | _BV (CS00); // prescaler = 1/64"
SIGNAL (SIG_OUTPUT_COMPARE0) {
/*
// full interrupt-driven implementation
if (cp_state == CP_STATE_DOWN) {
PORTA |= 0x80;
cp_state = CP_STATE_UP;
OCR0 = TIME_INITIAL + servo_up;
} else if (cp_state == CP_STATE_UP) {
PORTA &= 0x7f;
cp_state = CP_STATE_DOWN;
TCNT0 = 0;
OCR0 = TIME_INITIAL;
}
*/
// blocking implementation
TCCR0 = _BV (CS01) | _BV (CS00); // prescaler = 1/64
PORTA |= 0x80;
cp_state = CP_STATE_UP;
TCNT0 = 0;
while (TCNT0 < (SERVO_PREWAIT))
;
TCNT0 = 0;
if (servo_up < 128) {
while (TCNT0 < servo_up * SERVO_MULTIPLIER)
;
} else {
while (TCNT0 < 128)
;
TCNT0 = 0;
uint8_t servo_up_minus;
servo_up_minus = servo_up - 128;
while (TCNT0 < servo_up_minus * SERVO_MULTIPLIER)
;
}
PORTA &= 0x7f;
cp_state = CP_STATE_DOWN;
TCCR0 = _BV (CS02) | _BV (CS00);
TCNT0 = 0;
}
I know the blocking implementation is non-optimal but I don't think a full interrupt-driven implemention could later be expanded to control multiple servos.
#2
My Feedback: (5)
Join Date: Jan 2002
Location: San Tan Valley,
AZ
Posts: 5,768
Likes: 0
Received 0 Likes
on
0 Posts
RE: microcontroller-actuated servo, number of steps / precision?
Since it really is an analog servo, the S3004 theoretically has infinite steps. PCM systems found that 512 digital steps was not adaquate so switched to 1028. There is a system now available that has 2048 steps but I think that is gilding the lilly.