Author Topic: $50 Robot Modify the Servo  (Read 2638 times)

0 Members and 1 Guest are viewing this topic.

Offline RobotiCurlTopic starter

  • Beginner
  • *
  • Posts: 1
  • Helpful? 0
$50 Robot Modify the Servo
« on: June 02, 2013, 05:29:40 PM »
I am currently trying to set the HS-311 servo toit's zero degree posisiton before I modify it mechanically. I have the ATmega8 attached to a sparkfun breadboard. And I don't know how to hook up the servo to this configuration.

I would like to be able to communicate with the ATmega8, but don't know how to use the software.

Thanks!

Offline jwatte

  • Supreme Robot
  • *****
  • Posts: 1,345
  • Helpful? 82
Re: $50 Robot Modify the Servo
« Reply #1 on: June 02, 2013, 10:29:31 PM »
What software are you talking about?

To drive a hobby servo to 0-position from an Atmega, do this:

1) tie ground to the Atmega and the servo and your battery -
2) tie battery + to the center servo wire, and to the input to your voltage regulator
3) tie the output of the voltage regulator the to Atmega VCC and AVCC
4) tie the control wire of the servo (final wire) to the pin for PORT B pin 2 (port value 0x4)
5) run code like the following on the Atmega:

Code: [Select]
int main() {
  setup_timers();
  DDRB |= 0x4;
  while (true) {
    sei(); // enable interrupts
    delayus(20000);
    cli(); // disable interrupts
    PORTB |= 0x4;
    delayus(1500);
    PORTB &= ~0x4;
  }
  return 0;
}

You need to implement setup_timers() and delayus() to do the right thing. Typically, I run Timer1 at fuor ticks per microsecond. delaysus() then would read the timer value, multiply the input by 4, and wait until (timervalue - initialreadvalue) >= (calculatedvalue). Compensate for the cycles used for set-up if you want super accuracy.