PDA

View Full Version : servo control problem



superchiku
04-04-2008, 12:59 AM
i really got a big problem controlling my servo , ill say whatevr ihave done with it

type of servo-vegakits vts-08b

connected power to red wire,
ground to brown wire,
signal to orange wire

is the wiring correct?

the code of my program is like this (it is going to take the servo to 90 degrees)



#include <avr/io.h> //for 8mhz internal oscillator controlling servo by centering it
#include <avr/interrupt.h>

unsigned int i=0;

int main (void)
{
DDRC |= (1 << 7); // Set LED as output

TCCR1B |= (1 << WGM12); // Configure timer 1 for CTC mode

TIMSK |= (1 << OCIE1A); // Enable CTC interrupt

sei(); // Enable global interrupts



TCCR1B |=(1<<CS12); // Start timer at Fcpu/256
for(;;);

}

ISR(TIMER1_COMPA_vect)
{

if(i==1)
{
PORTC&=~(1<<7);
OCR1A=625;//give 20ms delay after the servo is given no signal
i=0;
}

if(i==0)
{
PORTC|=(1<<7);
OCR1A=47;//bring servo to the centre by giving nearly 1.5 ms delay
i=1;
}
}


my problem is that the servo only twitches when i turn on the mcu if i keep turning the mcu on and off, the servo twitches from left to right and from right to left, Please tell me what is the problem...

ppppking04
04-04-2008, 07:33 AM
Which pin have you connected your servo to?

debu
04-04-2008, 09:37 AM
@superchiku: Are you able to center your servo, by using a simple code like:



void main(void)
{
while(1)
{
PORTC=(1<<7);
_delay_us(1500);
PORTC=~PORTC;
_delay_us(1500);
_delay_ms(20);
}
}


If this works, then there is something wong in your code before, otherwise there is something wrong with your servo.

Regards,

Debu :)

superchiku
04-04-2008, 12:16 PM
no not even ur code works , i get the same problem the servo keeps twitching and doesnt move properly i dont know what is the problem, plzz help

allbits
04-04-2008, 01:19 PM
there was some discussion on vegakits servos, that they are normally non standard.

Probably you are dealing with some junk servos. The pulse width must be different.

If you have access to a CRO, check the waveform - for 1-2ms pulses @ approx 20ms frequency.

If you dont, assemble astables using 555, and vary the duty cycle using pots.
If still the servo dont rotate, and if the servos were brand new, contact the sales for any datasheet available. check if the servos operate at 1-2ms pulse.

or simply, go for a futaba or a hitec. Believe me, its worth it. IF you dont need much torque, get an HS311. or a Futaba S3003.

superchiku
04-04-2008, 03:02 PM
i dont have the datasheet od the servo but i think the problem is with fuse bits coz the servo twitch when power is applied so they are working correctly isnt it

i programmed my atmega16 mcu fuse bits in this way for internal 8 mhz oscillator along with jtag disable using avr dude the fuse bits code is like this


avrdude -p m16 -c bsd -t

w hfuse 0 0xd9
w lfuse 0 oxd4





now my mcu has a strange problem i programmed it with a flash led program which blinks the led in every one sec my code is like this


# include<avr/io.h>
int main(void) // for 8 mhz internal oscillator 1 sec gap//

{
DDRC|=_BV(0);
TCCR1B|=(1<<CS12);
while(1)
{

if(TCNT1>=31250)

{
PORTC^=(1<<0);
TCNT1=0;
}
}
return(1);
}

but what happens is that sometimes when i switch on the micro sometimes the led blinks, sometimes it doesnt , i hade a similar problem with another atmega16 which now doesnt get programmed coz i get this message

invalid device signature 0xffff

i think the problem lies there , are the fuse bit settings right or the vegakits servos are useless?