Servo motor swing is only 90 degree

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

I have SG90 servo motor purchased from ebay.com. I wrote below code, but I am able to get swing of 90 degree instead of 180 degree. I verified that servo is of 180 degree by running arduino code. I also verified PB1 pin that PWM is of 50 Hz and ON time changes between 1 and 2 msec correctly. What could be happening here? I am using ardiono nano board (Atmega328P)


#include <avr/io.h>
#include <util/delay.h>

void initialize_timer1(void);
int main(void)
{
    initialize_timer1();
    OCR1A=93;      // almost 1.5 ms
  _delay_ms(2000);
    while(1)
    {
        OCR1A=62;      //1 ms
        _delay_ms(2000);
        OCR1A=124;      //2 ms
        _delay_ms(2000);

    }
}
void initialize_timer1(void)
{
    //TIMER1 INITIALIZATION

    DDRB|= 1<<PB1; //OC1A AS PWM OUTPUT
    TCCR1A &= ~((1<<WGM10)|(1<<COM1A0)); // FOR FAST PWM mode 14
    TCCR1A|=(1<<COM1A1)|(1<<WGM11); // FOR FAST PWM mode 14
    ICR1 = 1249;  //TOP VALUE for 20msec (50Hz)
    TCCR1B |= (1<<CS12) | (1<<WGM13)|(1<<WGM12);  //PRESCALER 256, MODE 14
}

 

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

Buy a $10 logic analyser from ebay and google "sigrok"

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

Could not follow your answer for the need of logic analyzer. I used scope and saw that ON time is 1 msec and 2 msec inside the while loop. Servo swing is 90 degree only. 

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

If you have a scope and it shows 1ms .. 2ms and yet the thing only swings 90deg then what does the scope show when you drive it from Arduino ? Clearly it must be going outside the 1ms..2ms range if it does succeed in 180deg. When you know the upper limit you will probably need to adjust:

        OCR1A=124;      //2 ms
        _delay_ms(2000);

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

Checked the pin with Arduino code. Swing is between 560 micro second (0.5 msec) and 2.3 msec. When I run arduino code I see humming noise at one end and I am worried if my servo will go bad. 

I changed my code to set OCR1A between 30 and 124. Things seem to work. Most of the articles on servo motors tell us to use 1msec, 1.5 msec (90 degree) and 2 msec. Not sure if it depends on servo motor also! So for SG90 it looks we have to use 500usec, and 2 msec for 180 degree swing.

 

Will servo motors go bad if wrong signals are given?

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

Servos differ. The 1ms..2ms is just a general guideline to use as a starting point. You will risk damaging servos if you try to drive them beyond their design limits.

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

joneewheelock wrote:
Will servo motors go bad if wrong signals are given?

Most will tolerate quite a wide range of signals with out harm.

 

joneewheelock wrote:
I see humming noise at one end and I am worried if my servo will go bad

Most likely the servo has been driven to a mechanical stop, that may damage it eventually, just adjust your drive time to prevent that.

 

Have fun, experiment with it. 

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

What do you expect from a USD 1.20 Servo?

Speed, power, reliability, accuracy?

 

I find it pretty amazing you can buy (and have shipped) something that sort of works without falling apart within a day.

 

Also, in this price range, do not expect 2 servo's to react the same to your input.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

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

Are there lots of SG90 servos out there?  This datasheet http://www.ee.ic.ac.uk/pcheung/t... says 1ms to 2ms.  How does your Arduino sketch know to drive 1/2 ms? 

 

No datasheet to go with your eBay purchase?  [Sheesh--no datasheet even on the TowerPro site]

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.