Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: Gophermofur on March 24, 2010, 06:27:30 PM

Title: Modify servo - No rotation
Post by: Gophermofur on March 24, 2010, 06:27:30 PM
I'm having a fair bit of trouble trying to modify the servo.

Info:
Servo: HS-311 (same one as Tutorial)
Microcontroller: Atmega88PA

Modifications:

I no longer have the programmer on the PCB as I have another PCB I use to do the programming. So at the moment, I only have a few pins connected: Pin 7 (VCC), Pin 8 (Ground), Pin 1 (PD0), 20&21 to VCC, 22 to Ground.

Program:
I've loaded the hold_servo.hex file to the microcontroller.

Problem:
When I figure it up, the servo doesn't rotate at all. It never has. I opened it up and thought that it might already be centered, so I rotated the potentiometer and it still doesn't move. If i unplug it and re-plug it in, I the servo jitters and it rotates for about half a second and stops.

Voltage readings with the multimeter indicate that there is no voltage on the signal line, 5+ volts on the power line and 0 volts on the ground (servo connector).

I'm not quite sure where to go from here. Would the change from Atmega8 to Atmega88PA make a difference at all? Does not having the programmer attached mess up the circuitry in any way?

Thanks for your help!
Title: Re: Modify servo - No rotation
Post by: Soeren on March 24, 2010, 06:38:22 PM
Hi,

Voltage readings with the multimeter indicate that there is no voltage on the signal line, 5+ volts on the power line and 0 volts on the ground (servo connector).
You need a 'scope to see the servo signal.


Would the change from Atmega8 to Atmega88PA make a difference at all? Does not having the programmer attached mess up the circuitry in any way?
2 x No!
Open the servo and go over it real carefull with a magnifying glass - whenever a hobbyist has had his pinkies in a piece of electronics, there's allways a chance that something came loose or shunted  ;)
Title: Re: Modify servo - No rotation
Post by: Gophermofur on March 24, 2010, 06:48:25 PM
Perhaps I'm looking at it from the wrong perspective, but I'm looking at the very base gear (gold coloured one) attached to the motor. That's the one that isn't spinning. I can understand if the gears were lose, then they wouldn't connect properly and wouldn't spin -- but would that be the case with the main gear? Unless you are referring to me opening up the back and taking a look at the electronics?
Title: Re: Modify servo - No rotation
Post by: Gophermofur on March 25, 2010, 07:05:18 AM
Bit of an update here. I fiddled around with it a bit more last night and it looks like, for whatever reason, the code isn't executing.

When i was practicing on my breadboard a while back, I noticed the LED wouldn't come on after I uploaded the hex file to the micro. It's pretty much the very first line of code, not counting configuration, so I didn't see any reason why it would fail. I thought maybe I blew up my microcontroller, so I tried code from Sparkfun which essentially makes an LED blink and it worked perfectly fine (required a minor circuit change).

Yesterday in an attempt to determine if i destroyed my servo, I used the same blinking LED program but this time I attached my servo to the pin where the LED was supposed to be and I noticed it would rotate, stop, rotate, stop, etc as expected.

Now I need to figure out why the commands in the Admin's tutorial doesn't play nice with my microcontroller. I've tried both writing and compiling the code myself and also uploading the pre-made HEX file and neither of them work. So today's job will be trying to figure out why some code that seems to work for everyone doesn't play nice with the Atmega88PA (or perhaps MY atmega88PA).

So far, my first two thoughts are this:
Sparkfun sets the value of the port/bit differently than SoR. Sparkfun basically sets all the values at once whereas it looks like SoR uses some bitwise operations to turn on/off a specific bit on the port

Sparkfun - [PORTD = 0xFF],
SoR - [#define PORT_ON( port_letter, number )         port_letter |= (1<<number)]

My second idea is the Makefile. The only real difference I see in the Makefile between the two projects is the CPU frequency and the MCU. But I'm not sure how much that would affect the HEX File.
- MCU: Sparkfun sets the MCU to Atmega168, while SoR sets it to Atmega8.
- F_CPU: Sparkfun sets it to 8000000, Sor = 3686400

Thoughts?

Thanks.
Title: Re: Modify servo - No rotation
Post by: Revlex on March 26, 2010, 04:39:17 AM
I never have made a robot before in my hole life but i am a programmer so i will share my thoughts about the make file.

The problem in your makefile from SoR is: you say the MCU is an atmega 8 while it is a other MCU try figuring out wich one you need(I'd say copy the one from sparkfun "Atmega168").
also copy the F_CPU value from sparkfun to the SoR code.
Title: Re: Modify servo - No rotation
Post by: Gophermofur on March 26, 2010, 01:09:47 PM
Yesterday I modified the sparkfun project and tried to replicate what the $50 robot tutorial source code was trying to accomplish and had some success. I managed to get the PWM for the Servo working using delay_ms instead of delay_cycles(x).

Essentially, it was
Code: [Select]
while(1)
{
      PORTD= 0xFF; //Turn on PortD pins
      delay_ms(1.5); //Delay 1.5 milliseconds

      PORTD=0x00; //Turn off PortD pins

      delay_ms(20);

      //There may have been another delay here. I can't remember.

}


I managed to center the servo using that code and glue'd it. However, in retrospect, I probably should waited until I got delay_cycles working to verify that it really is zero'd. Oh well.

I'll probably dig around a bit more today and see if I can pinpoint what exactly between the two projects is preventing the SoR implementation from running correctly.