Need help, strange behaviour on controlling servo motor!

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
i'm making a servo motor controller using ATMega8-16pi running at 16Mhz. I programmed it to produce a pulse at 1.5ms high and around 20ms low. The servo motor should be turned into its center position. But the fact is, it turned into the leftmost position. After i checked using oscilloscope, i probed the pin (without the servo) the pulse output is correctly measured 1.5ms as it is should be. but when the servo connected into the microcontroller, strangely the pulse signal is around 23ms high and 23ms low :shock: . I've tried with another servo motor (i got 4 servos) and they all showed same strange behaviour :? . Can anyone tell me what's wrong :?:

please note that the supply line is clean, i've added bypass cap to reduce noise from servo motor. the servo tipe is futaba s3003

here is the code:

.include "m8def.inc"

.def tmp =r16
.def tmp1=r17

.def rserv1 =r18
.def rserv_1 =r19
.def rserv2 =r20
.def rserv_2 =r21
.equ servo1 =0
.equ servo2 =1

.cseg
.org 0
rjmp start
.org 8
rjmp pwm

start:
ldi tmp,low(RAMEND) ;set stacks
out SPL,tmp
ldi tmp,high(RAMEND)
out SPH,tmp

ldi tmp1,0xff ;setup ports
out DDRC,tmp1
out PORTC,tmp1

rcall init_timer1
ldi rserv1,15 ;initiate servo pulse
ldi rserv_1,15
ldi rserv2,20
ldi rserv_2,20

ulang:

rjmp ulang

init_timer1: ;creating timer1 interrupt
ldi tmp,0xfa ;every 100us
out TCNT1H,tmp
ldi tmp,0x38
out TCNT1L,tmp
ldi tmp,0x00
out TCCR1A,tmp ;mode normal
ldi tmp,0x01
out TCCR1B,tmp ;clock prescale=1
ldi tmp,0x04
out TIMSK,tmp ;overflow interrupt
sei ;enable interrupt
ret

pwm:
cli ;disable interrupt

ldi tmp,0xfa
out TCNT1H,tmp ;reload
ldi tmp,0x38
out TCNT1L,tmp ;value

dec rserv1 ;decrease servo value
brne pwm1 ;if not zero then get the hell out

sbic PINC,servo1 ;
cbi PORTC,servo1 ;these commands is used
sbis PINC,servo1 ;to make a bit complement algorithm
sbi PORTC,servo1 ;

ldi rserv1,0 ;reload the low pulse
sbic PINC,servo1
mov rserv1,rserv_1 ;reload the high pulse
pwm1:
dec rserv2
brne done
sbic PINC,servo2
cbi PORTC,servo2
sbis PINC,servo2
sbi PORTC,servo2
ldi rserv2,20
sbic PINC,servo2
mov rserv2,rserv_2
done:
sei
reti

longdelay: ;this delays around 1s
ldi r20,80
d1:
ldi r21,0
d2:
ldi r22,0
d3:
dec r22
brne d3
dec r21
brne d2
dec r20
brne d1
ret

KISS - Keep It Simple Stupid!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So, times are ok without load.
I think problem is load which is inductive, keeps voltage level higher then resistiv load and affect times.
What you use to drive servo, FET?

Regards
heguli

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

no, i dont use any driver. just connect the servo directly to my atmega8. but i dont get it, i was make the same kind of controller but using AT89S51. i controlled up to 12 servos simultaneusly and nothing was wrong. just as additional info, i'm making a six legged robot that have 2 DOF per leg so there must be 12 servos connected to the avr. should i interface all these servos using FET/optocoupler/BJT? that would increase overall efficiency and cost :? .

KISS - Keep It Simple Stupid!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Considering that the PWM signal is generated digitally, and the PWM control line of the servo is digital, I doubt that the PWM signals themselves, are at issue.

Looking at the 23ms-23ms ratio of the PWM signal when the servo is connected to the controller, I'd suspect that the microcontroller is resetting repeatedly and the 23ms is some coincedent time based on resistance, inductance and other parasitic variables in the system.

Look at the grounding and VCC supplies really hard. Make sure that the microcontroller power is not shareing the servo power. I.E. make sure that the power supply lines for the microcontroller and servo make seperate and distinct VCC and GND connections to the power source. Also, make sure that the power supply can source enough current to regulate the target voltage for which it was designed.

Make sure that there is a 10 to 100 microfarad capacitor connected to the power terminals of both, the microcontroller power terminals and the servo power connections as well, it possible.

There is absolutely no way the servo could influence the microcontroller's PWM timing, except external disturbance such as to cause an external reset or external intrrupt that is not vectored. Ground currents may cause similiar effects.

Hope this helps...

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

if you want to modify port output value, then i recommend reading in "PORTC" instead of "PINC".
"PINC" is used if you want to read the port state as an INPUT.

On the first sight it should be no difference, but the PIN is delayed. Pleas read datasheet - PORTC is not delayed.

If you insist on using PINC, then you have to include one NOP between changeing PORTC and reading back PINC.

@heguli:
this are servos. Power is connected to power and position is controlled with a logic PWM signal. I hope so....

Klaus
********************************
Look at: www.megausb.de (German)
********************************

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
@heguli:
this are servos. Power is connected to power and position is controlled with a logic PWM signal. I hope so....

learning something new every day, thanks

Regards
heguli

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Great, Thanx! I'll try your suggestions tomorrow in my lab. About the power supply separation is right and seems logical.

KISS - Keep It Simple Stupid!