go away spammer

Author Topic: Programming a servo - what could the problem be? (using $50 robot board)  (Read 2770 times)

0 Members and 1 Guest are viewing this topic.

Offline TheDarkLordTopic starter

  • Jr. Member
  • **
  • Posts: 46
  • Helpful? 0
Hello, I've successfully (to a certain extent, save for some problems with the servos) built the $50 robot, and now I'm trying to explore different possibilities using the same board. I wanted to make a servo which responds to sound, and so I built an amplifier circuit with a microphone and connected it to the Atmega8, following the instructions here: http://tinkerlog.com/2007/05/20/cheap-sound-sensor-for-avr/

I then modified the code posted on that same website, and successfully got an LED to turn on when I clap, and then off when I clap a second time. Now I want to introduce into this code a servo, so that when I clap the first time, the servo spins in one direction, and the second time, in the other direction.

I copy-pasted some of the code from the $50 robot in order to try and create this. However, it seems that whatever value I put into the servo_left(); function (I'm only using one servo) the SPEED of the servo does not change. Instead, it seems the servo is 'on' for whatever value I put in. Even this does not seem consistent. When I first clap, the servo is on for, let's say x seconds. The second time, it's on for y seconds. Then the third time, instead of being on for x seconds (because it is on a loop) the servo seems to be on for an arbitrary amount of time. The speed of the servo in all cases seems to be fixed.

What could the problem be? If you want me to upload the code, please say so and I will.
Thanks a lot!

Vignesh R.

Offline richiereynolds

  • Full Member
  • ***
  • Posts: 112
  • Helpful? 3
Re: Programming a servo - what could the problem be? (using $50 robot board)
« Reply #1 on: September 03, 2011, 03:04:32 PM »
Yes, please show the code.

Offline TheDarkLordTopic starter

  • Jr. Member
  • **
  • Posts: 46
  • Helpful? 0
Re: Programming a servo - what could the problem be? (using $50 robot board)
« Reply #2 on: September 03, 2011, 04:21:55 PM »
Okay. Sorry that I could not do so earlier.
The project file (zip) is attached.

I'm using AVR Studio 4.
Also, if it will help in making the behavior of the servo more clear, I could upload a video.

Thanks,
Vignesh R.

EDIT: I have large sections of the code commented out; it refers to stuff I tried but didn't work. You can ignore these please. Also, I'm sorry for the lack of comments on the program itself, but it seemed relatively straightforward..

EDIT #2: As I continued testing, I found that the servo doesn't change direction even while using the original $50 code. So is this a hardware problem?
« Last Edit: September 03, 2011, 05:19:07 PM by TheDarkLord »

Offline joe61

  • Supreme Robot
  • *****
  • Posts: 417
  • Helpful? 16
Re: Programming a servo - what could the problem be? (using $50 robot board)
« Reply #3 on: September 04, 2011, 06:35:42 AM »
I'm not following what happens in your servo_left() function. Servos are normally controlled by PWM, and I'm not clear on how a single pulse would do anything to them. They want a signal with a 20ms frequency, and duty cycle of between 1ms and 2ms.

Take a look at http://www.societyofrobots.com/member_tutorials/node/228 that has examples of driving a servo with PWM. I think that's what you want to do.

Joe

Offline TheDarkLordTopic starter

  • Jr. Member
  • **
  • Posts: 46
  • Helpful? 0
Re: Programming a servo - what could the problem be? (using $50 robot board)
« Reply #4 on: September 04, 2011, 09:32:21 AM »
Thanks for the quick reply.
I simply copied the servo_left() function from the Photovore_v1 source code, which was created by Admin. Could I not simply modify it to make the servos work properly?

That tutorial says to use PB0 or PB1.. However I cannot connect the servos here because my programmer connects to these pins.
And apparently, the timer only works for those two pins, but I want my servo to be connected on either PD0 or PD1..

Any ideas on how to proceed?

Thanks,
Vignesh R.

Offline joe61

  • Supreme Robot
  • *****
  • Posts: 417
  • Helpful? 16
Re: Programming a servo - what could the problem be? (using $50 robot board)
« Reply #5 on: September 04, 2011, 11:16:18 AM »
I looked at the source, but I honestly don't know what it's doing. I'm guessing that it sends one pulse of the appropriate length rather than using PWM. Apparently that works, but I'm not familiar with the technique.

I've always used PWM to control servos, which means using a timer. In that case you'd have to either use the predefined pins, or setup an interrupt handler to pulse the pin of your choice. For what you're doing, admin's way is probably better. Perhaps he'll explain.

Joe

Offline TheDarkLordTopic starter

  • Jr. Member
  • **
  • Posts: 46
  • Helpful? 0
Re: Programming a servo - what could the problem be? (using $50 robot board)
« Reply #6 on: September 04, 2011, 11:26:14 AM »
Well, thank you anyway :)

As a side note.. you mention "setup an interrupt handler to pulse the pin of your choice".
Would you be able to briefly explain how I would go about doing this? Or would you happen to know of any tutorials that explain this clearly? (for a beginner)

Thanks,
Vignesh R.

Offline greywanderer012345

  • Robot Overlord
  • ****
  • Posts: 133
  • Helpful? 2
I'm asking the same question in a newer post. If your looking for this answer go here:

http://www.societyofrobots.com/robotforum/index.php?topic=15926.0

Offline greywanderer012345

  • Robot Overlord
  • ****
  • Posts: 133
  • Helpful? 2
I got my $50 robot setup working with my servo code if you want to look at it in the above post. The make the delay 1000 for one direction and 2000 for the other. I couldn't get the delay functions to work when passed a variable, but you should be able to alter my code for your purpose.

 


Get Your Ad Here