Go Down

Topic: Can the Servo lib be made to control more than 12 servos per timer? Maybe! (Read 1 time) previous topic - next topic

Graynomad

Quote
It seems to me that every 20ms, one could toggle all the servo pins high at once and then turn them off one by one as needed when a particular servo's time is up.

That's how I'd do it.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

DuaneB

Quote

That's how I'd do it.


No, you would not.

the reason it is not done this way is that you would need to loop through the servos at every pin change to see who should go next, with 20 servos that would be a lot of 16 bit operations.

alternativley you could try and sort the servos at the start of each frame but again lots of 16 bit operations.

The current servo library uses around 1% of arduino processing power for 12 servos, my library is more efficient but has a less friendly interface - I would only consider using it if you want those extra servos, a higher refresh rate or smoother RC signal interrupts.

Duane B


scswift


the reason it is not done this way is that you would need to loop through the servos at every pin change to see who should go next, with 20 servos that would be a lot of 16 bit operations.


You are mistaken.

You see this? 
http://www.youtube.com/watch?v=Klh7bslfpBI

That is a circuit I built, which has an array of 64 multiplexed LEDs.  Nothing special about that you might think, and I wouldn't blame you since the video doesn't demonstrate it very well, but if you look closely, you may notice the LEDs that aren't brightly lit are displaying a gradient.  That's pulse width modulation.  On a multiplexed display.  How did I achieve this?  By sorting the LEDs so as I illuminated each column of the display I needed only check the time against the next LED to turn off. 

Quote
alternativley you could try and sort the servos at the start of each frame but again lots of 16 bit operations.


There's no need to sort the servos each frame as long as you keep your list sorted.  When you set a new angle, all you need to do is a quick binary search to the left or the right of where the previous position was in the list to figure out where to insert the value, and you're done.  Yes, this requires a few operations.  But setting the servo position doesn't need to be super fast.  Servos can't respond within microseconds to a change in position anyway.  Where speed is important is in the servo interrupt, and that would be super fast with the list already sorted for it.

DuaneB

Fair enough - as arduino is single threaded and you only need to re sort if a servo position changes, you can safely figure out the sort order with interrupts still enabled and then just disable them to do the update - should be smooth and simple.

Duane B



dhenry

Quote
This seems really inefficient to me however.


The advantage of that is that it is inherently PPM, if you output the pwm pulses on the same pin.

The disadvantage is that those pwm pulses are not phase aligned and there are channel limitations.

It is not hard to write pwm output on any arbitrary number of channels. I think I provided one example somewhere. Basically you establish a counter that counts up to a the period. At each increment for the counter, you test for overflow and output pins; At the roll-over of the counter, you re/set all pins.

Go Up