Servo motor does not work correct


Closed Thread
Results 1 to 38 of 38

Hybrid View

  1. #1
    Join Date
    Aug 2008
    Posts
    81

    Angry Servo motor does not work correct

    Hello
    Can someone help me.
    I can not control a servo motor he is without direction.
    here's codgo I'm using.
    In the PC program I have a range between 700 a 2300.
    Thank you.
    RX VAR BYTE
    POS VAR BYTE
    X1 VAR BYTE

    PROG:
    serin2 RX_inp,16468,[wait("PC"),RX,POS]

    IF RX = "A" THEN FRE
    IF RX = "B" THEN TRA
    IF RX = "C" THEN ESQ
    IF RX = "D" THEN DIr
    if RX = "E" THEN PAR
    IF RX = "X" THEN SERV
    GOTO PROG

    FRE:
    PORTB.0 = 0
    PORTB.1 = 1
    PORTB.2 = 1
    PORTB.3 = 0
    GOTO PROG
    TRA:
    PORTB.0 = 1
    PORTB.1 = 0
    PORTB.2 = 0
    PORTB.3 = 1
    GOTO PROG
    ESQ:
    PORTB.0 = 1
    PORTB.1 = 0
    PORTB.2 = 1
    PORTB.3 = 0
    GOTO PROG
    DIR:
    PORTB.0 = 0
    PORTB.1 = 1
    PORTB.2 = 0
    PORTB.3 = 1
    GOTO PROG

    PAR:
    PORTB.0 = 0
    PORTB.1 = 0
    PORTB.2 = 0
    PORTB.3 = 0
    GOTO PROG

    SERV:
    high SERVO1
    pauseus X1*10:X1 = pos
    low SERVO1
    GOTO PROG

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,601


    Did you find this post helpful? Yes | No

    Default Re: Servo motor does not work correct

    Did you make port B digital?

    What PIC?

    What CONFIG settings?

    Do you want default oscillator settings?

    What is RX_inp and SERVO1?

    Do you want X1 to have initial value?

    Robert
    Last edited by Demon; - 15th June 2014 at 21:00.

  3. #3
    Join Date
    Aug 2008
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: Servo motor does not work correct

    Hello all well
    I have a program on the PC that controls the motor ac
    I trackbar that for servo motor with avariaves 700-2300
    This half confused,

    @ DEVICE PIC16F876A
    @ DEVICE PIC16F876A,WDT_ON
    @ DEVICE PIC16F876A,PWRT_ON
    @ DEVICE PIC16F876A,PROTECT_off
    @ DEVICE PIC16F876A,XT_OSC
    define OCS 4
    ADCON1 = 7
    TRISC=%10000000:PORTC=%10000000
    TRISA=%11111111:PORTA=%11111111
    TRISB=%00000000:PORTB=%00000000
    SYMBOL SERVO1=PORTB.0 'SERVO1
    SYMBOL RX_INP=PORTC.7 'RF
    Last edited by cesar35; - 15th June 2014 at 21:18.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Servo motor does not work correct

    Hi,
    A couple of issues of the bat:
    If, by servo, you mean your typical RC servo it's not enough to send it one pulse. If you want it to move you need to send it pulses, usually at around 50Hz repetition rate, for at least as long as it tkaes for the servo to move to the new position but ideally you send it pulses all the time so that it can keep its position. As far as I can see you're only sending a single pulse - I don't think that's going to work.

    You have POS declared as a BYTE but you're trying to store a value between 700 and 2300 - that's not going to work.

    pauseus X1*10:X1 = pos
    A typical RC servo want pulses with a width of 1-2ms. If you assign 2000 to POS (after changing it to a WORD) you're going to get a pulsewidth of 20000us or 20ms - I don't think that's going to work.

    If you change POS to a WORD check the documentation of SERIN to see if it can handle WORD variables directly or if you need to give it the high and low byte separately. And, finally, I'm not sure what the purpose of copying POX to X1 but if there's a specific reason for it make sure you change X1 to WORD as well.

    /Henrik.

  5. #5
    Join Date
    Aug 2008
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: Servo motor does not work correct

    Thanks for the reply
    I made you the servant said he moved to the left and and stop.
    I cho I'm really confused.
    Could you tell me what is wrong in this program
    @ DEVICE PIC16F876A
    @ DEVICE PIC16F876A,WDT_ON
    @ DEVICE PIC16F876A,PWRT_ON
    @ DEVICE PIC16F876A,PROTECT_off
    @ DEVICE PIC16F876A,XT_OSC
    define OCS 4
    ADCON1 = 7
    TRISC=%10000000:PORTC=%10000000
    TRISA=%11111111:PORTA=%11111111
    TRISB=%00000000:PORTB=%00000000

    SYMBOL SERVO1=PORTC.0 'SERVO1
    SYMBOL RX_INP=PORTC.7 'RF

    RX VAR BYTE
    POS VAR word
    X1 VAR word

    PROG:
    serin2 RX_inp,16468,[wait("PC"),RX,POS]

    IF RX = "A" THEN FRE
    IF RX = "B" THEN TRA
    IF RX = "C" THEN ESQ
    IF RX = "D" THEN DIr
    if RX = "E" THEN PAR
    IF RX = "X" THEN SERV
    GOTO PROG

    FRE:
    PORTB.0 = 0
    PORTB.1 = 1
    PORTB.2 = 1
    PORTB.3 = 0
    GOTO PROG
    TRA:
    PORTB.0 = 1
    PORTB.1 = 0
    PORTB.2 = 0
    PORTB.3 = 1
    GOTO PROG
    ESQ:
    PORTB.0 = 1
    PORTB.1 = 0
    PORTB.2 = 1
    PORTB.3 = 0
    GOTO PROG
    DIR:
    PORTB.0 = 0
    PORTB.1 = 1
    PORTB.2 = 0
    PORTB.3 = 1
    GOTO PROG

    PAR:
    PORTB.0 = 0
    PORTB.1 = 0
    PORTB.2 = 0
    PORTB.3 = 0
    GOTO PROG

    SERV:
    high SERVO1
    pauseus X1*10:X1 = pos
    low SERVO1
    GOTO PROG

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Servo motor does not work correct

    Hi,
    Could you tell me what is wrong in this program
    I thought I did bring up least a couple of things that might be wrong.
    You've corrected the variable size, that's good.

    But,
    * You are still doing the times 10 thing in the SERV subroutine, if the PC sends 700 you'll get a 7ms delay, what's the reason for it?
    * You are still only sending a single pulse to the servo
    * I took a brief look at the manual and as far as I can see SERIN2 can not directly handle WORDs, you need to split it, SERIN2 RX_inp,16468,[wait("PC"),RX,POS.HighByte, POS.LowByte] watch out for big vs little endian. Which brings me to the last thing...
    * How is the PC sending the data? If it's sending it as ASCII, ie "1","2","3","4" instead of two bytes 4,210 then you need to use the DEC modifier in the SERIN2 statement.

    /Henrik.

Similar Threads

  1. Servo motor control
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th July 2010, 22:44
  2. servo motor control??help
    By HYETİK in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th April 2009, 07:41
  3. servo/motor problem
    By griffin in forum mel PIC BASIC
    Replies: 10
    Last Post: - 10th February 2009, 20:07
  4. Servo motor problem
    By dboy in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 20th September 2008, 15:54
  5. contorlling servo motor
    By shirleyz in forum General
    Replies: 10
    Last Post: - 31st May 2008, 23:53

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