Control unlimited servos at the same time
I have an idea to control lots of (>10) servos from a PIC at the same time.
Normaly everbody would choose this way to control multiple servos:
High Ch1pin 'Or pulseout pin,ch1
Pause ch1
low Ch1pin
High Ch2pin
Pause ch2
low Ch2pin
High Ch3pin
Pause ch3
low Ch3pin
This is uneffecient, and its also limits the maximum servo number
becasuse a servo needs to update its position in every 18ms (19mS) (~50Hz).
When using this technic we must run allover every signal sendout.
Its limited to max ~11 servos (@50Hz)
Here is the normal way to send out control signals:
http://kepfeltoltes.hu/view/060913/O...toltes.hu_.gif
There is a another solution, when we set High all Ch pins
and give out a pause command, length of the first pause is the lowest ch time ,after the pause, Low the smallest ch pin.
Then we have to figure out wich is the next lowest ch,then subtract the previous ch from this.
We get a delta time. Give pause out for delta time, then Low the second lowest ch pin. Then search for the third lowest ch, subtrack the previous ch, pause delta time,low pin, search for the 4th lowest... and all over for all n servos.
Here is the Faster way:
http://kepfeltoltes.hu/view/060913/M...toltes.hu_.gif
we have ch1,ch2,ch3,ch4,ch5,ch6,...ch(n) VAR byte 'for 8bit control
ch1 is RB0,ch2 is RB1 ............
1, High all servo pins (RB0,RB1....)
2, find the smallest ch
3, pause for smallest ch time
4, low smallest ch pin
5, find next! smallest ch
6, subtract the previous from it
7, pause for delta time
8, low the ch pin
9, goto 5
it would be very nice when we could put in a loop (for,repeat,while)
The limits of the servo number is really just the pin number of the microcontroller:)
Some idea for the structure, to find the lowest ch:
'---------
For i=0 to (# of the servos)
Select case Ch# 'current servo
case is > ch1
..?
case is > ch2
..?
case is > ch3
..?
.
.
.
End select
Next i
'--------
of course its not so simple, but please help me how to code this.
Thx
excellent thinking process!
I love to see people analyzing problems, breaking them down into their core components, and discovering that things don't have the limitations previously thought. (i.e. the limitation was really me, not the hardware!)
I'm thinking a gotcha on this is the amount of calculation and decisions being made. And, obviously, things (servo positioning) will change over time.
So, you have calculations, optimizing the data for an algorithm, and allowing for something to signal changes.
The good news: things won't be changing that often (especially when viewed from MCU mhz perspective), or at least you hope that's the case (see below).
Let's say, for the sake of argument, that you were to create three parallel arrays. One array for priority, one for on-time, and one for off-time. Then make an algorithm that will step through the arrays and set the pins accordingly.
The first array functions like a database index, so, rather than (re-)sorting your arrays everytime something changes, you just change the index.
A problem you'll run into is when managing multiple waveforms of different frequencies, you'll have to use something like a least-common-denominator concept to artificially time-slice/time-share. Hard to explain without a bunch of math; but simply draw a few different square waves of different frequencies on a whiteboard, one-above-the-other. Then, draw vertical lines that represent the action points. Conceptually, you'd need infinite resolution, but engineering is trade-offs, so you'll wind up picking (through calculations or trial-and-error) a minimum time increment to deal with.
Why? When will you take time to check for changes and then re-calculate the array values.
------------------
Where's the code!!!!!!!!!
I'll watch this posting to see how things go.
bcf