How would i write this in pic basic pro (Servo controller)


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005
    Posts
    28

    Talking How would i write this in pic basic pro (Servo controller)

    Hi there i am trying to create a program to control two servo inputs to control one servo.

    The jist of it is. There are two servo inputs

    Servo input 1
    Servo input 2

    And one output

    Servo output 1

    when input 1 is centerd the output 1 = Input 2
    and when input one is not centered i.e its more or less then 1.5ms pulse then Output 1 = Input 2


    I have enclosed a flow diagram which i think will help.

    Please i need some help as it is kritical in my r/C project
    Attached Images Attached Images  

  2. #2
    Join Date
    Mar 2003
    Posts
    41


    Did you find this post helpful? Yes | No

    Wink One servo - two inputs

    I think your verbal description is wrong. As written, your output is always driven by input 2.

    How are you making the transition from pot position to pulsewidth? Analog or digital input?
    How are you driving the output? Let's assume PULSOUT and further assume a 20 MHz clock for a 2 uSec PULSOUT step size.

    Assuming two pots, their ends each connected to +5V and ground, with the wiper coming to analog inputs, then the input will be a word between 0 and 1023.

    The output needs to be a word between 500 and 1000 centred on 750 to allow for the servo range of 1000 uSec to 2000 uSec with 2 uSec steps.

    Psuedocode follows

    Servo var portb.0 ' or whatever
    Position1 var word
    Position2 var word
    Output var word

    Start:
    GetPot1Position:
    read analog value where 512 = pot central
    store in word variable Position1
    GetPot2Position:
    read analog value and store in word Position2

    Width1 = (Position1 - 12)/2 'now in the range 0 to 506 with 250 = centre
    Width2 = (Position2 - 12)/2 ' don't worry about the small offset

    if (width1 < 248) OR (width1 > 252) then ' allow for non exact centering
    output = width1 + 500
    else
    output = width2 + 500
    endif
    LOW servo ' VITAL you set servo to 0 beforehand - try not doing it!
    PULSOUT pin, Output
    pause 20
    goto start
    Last edited by btaylor; - 10th February 2006 at 01:20.

  3. #3
    Join Date
    Sep 2005
    Posts
    28


    Did you find this post helpful? Yes | No

    Default reply

    hi there thanks for the reply.

    Input 1 is an analouge input and input 2 is a pwm signal from a futarba reciver.

    the clock frequeny is 4mhz with this make a big differance to the code and what would it look like?

  4. #4
    Join Date
    Sep 2005
    Posts
    28


    Did you find this post helpful? Yes | No

    Default reply

    hi there here is the code i have at the moment

    'servo control prog

    'set variables

    ch1 var byte
    ch2 var byte
    s1 var byte
    s1 = 150

    start:

    pulsin portb,1,7000,Ch1
    pot portb,2,200,Ch2

    if ch1 < s1 then output1
    if ch1 > s1 then output1
    if ch1 = s1 then output2


    output1:

    pulsout portb.3,ch1
    pause 18
    goto start

    output2:

    pulsout portb.3,ch2
    pause 18
    goto start

    end

    i have compiled it and it seams to work. not tried it out on any hardware yet .

Similar Threads

  1. PIC BASIC or PIC BASIC PRO
    By kirkmans in forum USB
    Replies: 3
    Last Post: - 20th April 2007, 00:52
  2. Turbo Encoding with Pic Basic Pro
    By obaskirt in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 15th November 2006, 09:22
  3. converting assemble to pic basic pro
    By Jhdgkss in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 30th April 2006, 19:55
  4. PIC basic and rc servo signals
    By BCIcdrz in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 11th May 2003, 14:51
  5. How to use 93C46 Type EEPROM using PIC Basic PRo
    By in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 1st April 2003, 04:07

Members who have read this thread : 1

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