Control unlimited servos at the same time


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Posts
    19


    Did you find this post helpful? Yes | No

    Cool

    I've finished the whole code.
    Its contains of:

    1, A Word[] array:
    its for storing each channel value between 1000-2000uS-> 1-2mS
    Or when using 10bit ADC-> we add ~988 to the adc value

    0-1023
    +988
    988-2011 uS -> 0.98-2mS instead of 1-2mS
    engineering is realy a tread of
    maximum resolution is 16bit because of Word is 16bit.

    you can add many channels as your PIC can handle,
    simply extend the numbers of elements of the A array.
    like A var word[10]

    And you also must change the biggest element number
    at line 31.

    2, B Byte[] array:
    it has the same numbers of elements as A.
    I use this array as an index of the A array.

    On startup I fill it up with [0,1,2,3]
    this index is used for "linking" (or pointing) to the A array.

    3. sorting
    the sorting was do it on the B index array,

    4, temp is just a byte because its temporaly holds
    the value of a the B elements, which is far less then
    255.

    5, send out routine
    high all servo pins
    because the B array is the sorted form of the A
    we can easily obtain the lowest channel value.
    calculate the delta times
    pauseus out the delta times
    and low the lowest channel's pin.

    You can learn more on delta timing on my previous posts.
    and more infos are in the code.
    The whole code is just 283 Word
    and its MAX runoff time is 3mS! (at a channel config of:1000,1435,1140,2000uS)
    when you want to sendout like this: pulseout ch1,ch2,ch3,ch4... itt would took

    5,6mS.!!! So my code is really effecient, especially when you use more channels.

    array setup: http://kepfeltoltes.eof.hu/gallery.p...1158505218.gif
    -------------------------------------------------------------------------

    'startup
    counter var BYTE
    Temp var byte
    A var WORD[4]
    B var byte[4]
    trisa=0
    trisb=0

    for counter=0 to 3 'DONT delete!!!!
    b[counter]=counter 'its for fill B[] on start up
    next counter
    'end of startup

    a[0]=1000 'CH0 'assign any value between 1000-2000uS->1-2mS
    a[1]=1435 'CH1 'in 1uS resolution!
    a[2]=1140 'CH2
    a[3]=2000 'CH3

    'sorting routine (from Melanie)
    'B[0] smallest, B[3] biggest
    counter=0
    SortLoop: 'dont delete this label,its for looping

    If a[b[counter]] > a[b[counter+1]] then
    Temp=b[counter]
    b[counter]=b[counter+1]
    b[counter+1]=Temp
    If counter>0 then counter=counter-2
    endif
    counter=counter+1
    If counter<3 then goto SortLoop
    'end sorting of B index array

    'this was 500-725 uS from start,depend a little on
    'how much sorting was needed

    'next routine will be as long as the biggest ch value
    'max 2mS + some uS

    'Sendout:
    high portb.0 'CH0
    high portb.1 'CH1
    high portb.2 'CH2
    high portb.3 'CH3


    for counter=0 to 3
    pauseus a[b[counter]]-a[b[counter-1]]
    'calc delta times
    'if counter=0 -> a[b[0-1]] -> WILL BE 0, TESTED!
    'so it'll be: Pauseus a[b[counter]]-0 !
    Portb.0(B[counter])=0
    'LOW portb# given back from B
    next counter

    end
    ---------------------

  2. #2
    Join Date
    Sep 2005
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Any questions, or ideas?

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Well, here's one...

    What happens with the following array values?

    All servo's at same position.
    [1000,1000,1000,1000]
    <br>
    DT

Similar Threads

  1. 16F877 elapsed time control
    By BerkayT in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 12th February 2009, 17:23
  2. Code to control 4 LEDs and 2 servos
    By The Master in forum Off Topic
    Replies: 2
    Last Post: - 26th November 2008, 13:33
  3. using a pot to control a time range
    By glkosec in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th June 2008, 19:59
  4. Serout2/serin2 Pbp Problem
    By SOMRU in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th December 2006, 19:55
  5. Button pressed time control
    By tanero in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 15th August 2005, 15:17

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts