NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Basic Electronics » Digital servo issues!

March 13, 2012
by ThomasH
ThomasH's Avatar

Hi All,

I recently purchased some digital servos ()

I've been having real troubles getting the servo to work! I've read the servo squirter tutorial and have even cut and paste the code, but my servo motor still doesn't respond.

Using the following bit of code below, my servo just appears to move randomly! I have a separate wall power supply for the servo motor.

Does anyone have any ideas? Is there a difference in control between analog and digital servos for the purposes of controlling it via the atemga168?

Thanks!

Tom.

define F_CPU 14745600

#include <stdio.h>
#include <math.h>

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <inttypes.h>

#include "../libnerdkits/delay.h"
#include "../libnerdkits/uart.h"

int main()
{
    //set up timer and PWM mode for servo control
    TCCR1A |= (1<<COM1A1) | (1<<WGM11); // non-inverting mode for OC1A
    TCCR1B |= (1<<WGM13) | (1<<WGM12) | (1<<CS11); // Mode 14 (Fast PWM), Prescaler 8
    ICR1 = 36864; //14745600 / 50 / 8 (50 = 50hz, and 8 is the prescalar)

    //set up pin to signal servo
    DDRB |= (1<<PB1);

    while(1)
    {   
            OCR1A = 3686;
            delay_ms(1000);

            OCR1A = 2764;
            delay_ms(1000);

            OCR1A = 1844;
            delay_ms(1000);
    }

    return 0;
}
March 13, 2012
by ThomasH
ThomasH's Avatar

Sorry - I forgot to include the link to the digital servo. I may be useful to someone who is more knowledgeable that me! There are 2 links, but both are the same servo model (D90MG)

http://www.geningrc.com/ProductsView.Asp?id=50

http://www.twig.com.au/store/product_info.php?products_id=139&osCsid=17eae35ad2bfa19ffb3c96e596d57b2f

March 13, 2012
by JimFrederickson
JimFrederickson's Avatar

I think, at the very least, you will need to post the Manufacturer and Model of the Servos in question.

A link to a location to find the spec-sheet would be helpful as well.

March 13, 2012
by ThomasH
ThomasH's Avatar

Hi Jim, I hope the 2 links to the servo are sufficient. That's all I have. I don't have a data sheet or spec sheet other than those links. Thanks for your help!

Tom.

March 13, 2012
by ThomasH
ThomasH's Avatar

Hello again! I think I solved the issue. I didn't connect the 2 grounds of each of the power supplies together.

I read this somewhere on the internet that the servo power supply and the microcontroller power supplier need to have a common ground.

I do have another question though - why is this the case? Is this so the PWM signal (high and low) that the microcontroller produces has the same point of reference for both the microcontroller and servo?

Tom.

March 13, 2012
by Rick_S
Rick_S's Avatar

Hi Tom,

Digital and analog hobby servo's both communicate the same way. So the servo squirter code should work.

You stated that you used a separate power supply for the servo. While this is fine, you do have to tie the ground wire of the servo supply to the ground of your kit. I'm guessing you didn't do this since you didn't say you did. Without sharing a common ground, the signal from the nerdkit will be at a different potential than the servo and you will have issues.

If you did share a common ground, take a couple of photo's of your setup and post them. We may see something you missed.

One last thing. I noticed you are using OCR1A instead of OCR1B as in the servo squirter. While I'm sure you are aware, since you changed the code, this requires the signal wire from the servo to connect to pin 15 (PB1/OC1A) instead of pin 16 as in thier tutorial.

Rick

March 14, 2012
by Rick_S
Rick_S's Avatar

Tom,

I was wondering. Did you have a chance to try the suggestions or did you got it working?

Rick

March 14, 2012
by ThomasH
ThomasH's Avatar

Hi Rick,

I'm not sure if my previous post got through, but it did solve the problem. I didn't have a common ground!

Must be a frequent newbie problem! Thanks for your help.

Tom.

March 15, 2012
by Rick_S
Rick_S's Avatar

Not a problem, glad it worked for you.

Rick

Post a Reply

Please log in to post a reply.

Did you know that a NerdKit can take control of a remote-controlled car? Learn more...