Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

urgent servo help

Status
Not open for further replies.

aruna1

Member
hi
i just received two metal gear servos i ordered two weeks ago from ebay
**broken link removed**

my problem is both servos only rotate in clock wise direction.that is they can move from 1500us--> 2200us but fail to move 2200us-->1500us. so i have to rotate arm manually by hand.

this is the code I'm using (CCS C v4.084 on 12F675)

Code:
#include "G:\Aruna\My Electronic projects\servo tester\main.h"

void main()
{
   INT16 preset = 0;
   INT16 time = 1500;
   INT16 temp1 = 0;
   INT16 temp2 = 0;
   INT16 i = 0;
   INT16 j = 0;
   setup_adc_ports (sAN2|VSS_VDD);
   setup_adc (ADC_CLOCK_INTERNAL);
   setup_timer_0 (RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1 (T1_DISABLED);
   setup_comparator (NC_NC);
   setup_vref (FALSE);
   //set_adc_channel (2);
   //delay_us (100);
   
   // TODO: USER CODE!!
   
   WHILE (1)
   {
 
      
         output_high (PIN_A4);
         delay_us (2000);
         output_low (PIN_A4);
         delay_us (20000 - 2000) ;

      
   }
}

can someone tell is there anything I'm doing wrong or are these servos faulty coz i need to return them asap if they are faulty
 
I think the problem is your code. It appears to generate the same duty cycle, as the values for delay are hardcoded. To reverse your motors, you need to change those values. But I'm not an expert on whatever system you're using. Just what I see in the code.
 
ya i know.i changed them but only changes in clockwise direction will work.anti clock wise direction codes wont work
 
What values are you using? I've only played with servo motors, but I've only used duty cycles of 10% or less. Maybe you're using too much high time. Try using aournd 5% - 15% duty cycles.
 
As I've said, I'm not an expert in your system, but this:

output_high (PIN_A4);
delay_us (2000);
output_low (PIN_A4);
delay_us (20000 - 2000)

Looks like 2000us hight and 18000us low. Ok that looks about right. Well, I just don't know then. All I can say is make sure you're not doing something stupid, like forgetting for rebuild your code each time you change the settings. (by "stupid" I mean the kinds of things I do all the time) You can also try a program that moves from one position to another, with a long dealy in between. Here is my basic stamp program excerpt:

Code:
DO
  DEBUG "Counterclockwise 10 o'clock"
  FOR counter = 1 TO 150
    PULSOUT 14, 1000
    PAUSE 20
  NEXT

    DEBUG "Clockwise 2 o'clock"
  FOR counter = 1 TO 150
    PULSOUT 14, 500
    PAUSE 20
  NEXT

     DEBUG "Center 12 o'clock"
  FOR counter = 1 TO 150
    PULSOUT 14, 750
    PAUSE 20
  NEXT
LOOP
 
after Do:

First 5 lines uses 2ms high and 20ms low, does it 150 times ( see the "for" command )
next 5 lines uses 1ms high and 20ms low, also 150 times
next 5 lines uses 1.5ms high and 20ms low, also 150 times.

"Do" and "Loop" creates a forever loop, just as your while(1) does.
 
that code partially works,
that is servo moves to three positions but doesnt come to starting position after all three for loops
 
It should just keep going to the same 3 positions over and over. It it doesn't, make sure your "forever" loop is coded correctly.
 
Last edited:
why is that?

after executing
"next 5 lines uses 1.5ms high and 20ms low, also 150 times."
then infinite loop moves to
"First 5 lines uses 2ms high and 20ms low, does it 150 times ( see the "for" command )"

so servo shoult\d move to initial position
 
If you code is containes within the while(1) loop, then it will just continue to cycle through the same 3 positions until you stop the program.
 
that is correct. It should change directions between the first-second position and second-third position. Don't know if that makes any sense. Show your new code.
 
here is the new code

Code:
#include "G:\Aruna\My Electronic projects\servo tester\main.h"

void main()
{
   INT16 preset = 0;
   INT16 time = 1500;
   INT16 temp1 = 0;
   INT16 temp2 = 0;
   INT16 i = 0;
   INT16 j = 0;
   setup_adc_ports (sAN2|VSS_VDD);
   setup_adc (ADC_CLOCK_INTERNAL);
   setup_timer_0 (RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1 (T1_DISABLED);
   setup_comparator (NC_NC);
   setup_vref (FALSE);
   //set_adc_channel (2);
   //delay_us (100);
   
   // TODO: USER CODE!!
   
   WHILE (1)
   {
      /* preset = read_adc ();

      WHILE ( ! adc_done ())
      {
      }

      
      temp1 = preset / 1023;
      temp2 = 1800 * temp1;
      time = 600 + temp2;
      temp1 = 0;
      temp2 = 0; */
      
      FOR (i = 0; i < 150; i++)
      {
         output_high (PIN_A4);
         delay_us (2200);
         output_low (PIN_A4);
         delay_us (20000);
      }

      FOR (i = 0; i < 150; i++)
      {
         output_high (PIN_A4);
         delay_us (1500);
         output_low (PIN_A4);
         delay_us (20000) ;
      }

      FOR (i = 0; i < 150; i++)
      {
         output_high (PIN_A4);
         delay_us (900);
         output_low (PIN_A4);
         delay_us (20000) ;
      }

      
      
      
      
      
      
      
      
   }
}
 
First of all, I'd get rid of this:
WHILE ( ! adc_done ())
{
}

Just let the damn thing run until you pull the plug. Then, try using the sequence, 2200us, 900us, 1500us, instead of what you presently have. That way, you have a change of direction programmed in every loop, and you should see at least 1 change of direction even if you forever loop isn't working.
 
First of all, I'd get rid of this:


Just let the damn thing run until you pull the plug. Then, try using the sequence, 2200us, 900us, 1500us, instead of what you presently have. That way, you have a change of direction programmed in every loop, and you should see at least 1 change of direction even if you forever loop isn't working.

you may see that i have already commented the part

Code:
WHILE ( ! adc_done ())
{
}

and nope,servo does not change direction.
so is this conclude that servos are faulty?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top