go_away

Author Topic: Controlling 18 or more servos using AVR 8-bit in software  (Read 2351 times)

0 Members and 1 Guest are viewing this topic.

Offline madmax_707Topic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Controlling 18 or more servos using AVR 8-bit in software
« on: September 18, 2012, 10:45:11 AM »
Hi all,
I am trying to make a hexapod with 18 servos(3 servos Per leg. So 3*6 legs). Would like to have an additional 2 just for sake of it, if I decide to add some sensor or even a camera. I have read some implementations and have only come across code snippets which control 8 servos using timer interrupts. I have also read (just very little.. and did not understand) on the Webbot lib. I would like to learn the process of creating one myself in software rather than use a ready made one. I have also come across a SSC32 board made by lynxmotion which uses atmega8 and shift registers to control 32 channel. But I think that getting 20 servos should not be difficult and can be done. For some reason I cant get my head around it and since I am a beginner in this field I would request you all to help me in any way possible.
Thanking you all in advance 

Offline Gertlex

  • Supreme Robot
  • *****
  • Posts: 742
  • Helpful? 23
  • Nuclear Engineer Roboticist
Re: Controlling 18 or more servos using AVR 8-bit in software
« Reply #1 on: September 18, 2012, 10:51:04 PM »
I've generally seen robots with lots of hobby servos (e.g. hexapods) use the SSC32 or similar products.  These boards have the advantage of taking care of supplying power to the servos (You wouldn't want to run 18 servos directly from an Axon, for example), and maintaining the PWM pulsing without taking up processing cycles on your MCU.

I've not done more than 3 hobby servos with WebbotLib (because I moved to AX-12 digital servos), so I can't share any experience on that end, other than everything I've done with WebbotLib being awesome...
I

Offline madmax_707Topic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Re: Controlling 18 or more servos using AVR 8-bit in software
« Reply #2 on: September 19, 2012, 06:28:32 AM »
Thanks for your reply Gertlex. I agree using the board like the ssc32 would be easier, but i have seen a particular hexapod video on youtube which was using webbot lib to drive all the servos and that is how I got to know about the the webbot lib. I would actually like to know how we can achieve this in software using e.g Atmega32.  may be some code snippets? I know if i download the webbot lib and get it setup successfully may be i will get ta robot working in a  couple of days but, i really want to understand how.  I have used the pwm modes for the timers in an Avr  however, if someone could explain me how we can achieve this (perhaps the creator the Webbot lib) then that would be awesome. I have also read the entire tutorial written by Webbot which was awesome by the way. However, the last sections which is about achieving pwm in software simply says use my library :(. Hence my reason for posting this question on the forum.
Thanks again !

Offline Gertlex

  • Supreme Robot
  • *****
  • Posts: 742
  • Helpful? 23
  • Nuclear Engineer Roboticist
Re: Controlling 18 or more servos using AVR 8-bit in software
« Reply #3 on: September 19, 2012, 08:50:46 AM »
You should link to the vid you're referring to. Some of us might recognize it.
I

Offline newInRobotics

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Re: Controlling 18 or more servos using AVR 8-bit in software
« Reply #4 on: September 19, 2012, 10:52:07 AM »
[...] pwm in software [...]
PWM using timer works in the following way (simplified explanation):
  • Set top value to say 100.
  • Set compare value to 50
  • Start timer (timer starts with current value equal to 0
  • With every clock cycle current value gets incremented by 1
  • When current value is equal to compare value, designated PWM pin is set to HIGH
  • When current value is equal to top value, designated PWM pin is set to LOW
  • Timer resets to 0, everything start all over
By changing compare value You set duty cycle (how long PWM pin stays HIGH).
By changing top value You set frequency (how many times per minute PWM cycle repeats).

All what's above can be done in software, only instead of timer counting from 0 to top value, You simply count that in Your main loop, use if() statements to check if current value is equal to compare value or top value and flick any IO pin if before mentioned conditions are met.

Problem with software PWM is that the more You have in Your main loop, the bigger error You get in Your PWM signal. This can be avoided if You're willing to program in ASM, take into consideration how many commands Your main loop has, how long they take to execute and manually compensate for cycles lost executing them. Also, there are interrupts that interrupt main loop, hence they also interrupt Your software PWM causing error in timing.

Hope that helps  :)
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

Offline madmax_707Topic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Re: Controlling 18 or more servos using AVR 8-bit in software
« Reply #5 on: September 19, 2012, 11:25:25 AM »
Hi
@Gertlex
I think the link to that videos is this
   
Self-Transforming Mobile Robot


@newInRobotics
   Thanks for your explanation. I know how that works actually but I was having difficulty going above 8 servos. I was also referring to Low-Jitter Multi-Channel Software PWM (www.atmel.com/Images/doc8020.pdf) but RC servos require a 20 ms pulse and i was getting confused. So i thought i could post in the forum. But thank you so much for replying.


Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,653
  • Helpful? 169
    • Society of Robots
Re: Controlling 18 or more servos using AVR 8-bit in software
« Reply #6 on: November 11, 2012, 08:32:14 AM »
These boards have the advantage of taking care of supplying power to the servos (You wouldn't want to run 18 servos directly from an Axon, for example), and maintaining the PWM pulsing without taking up processing cycles on your MCU.
You can run 18 servos on an Axon, no problem. Unless of course they are all drawing 1 amp continuous, in which case you'd want to use a second parallel battery located far from the first on the same power bus. That divides the current to half.

WebbotLib uses software interrupts to pulse the servos so it takes almost no processing cycles to achieve.

 


Get Your Ad Here

data_list