Servo motor does not work correct


Closed Thread
Results 1 to 38 of 38

Hybrid View

  1. #1
    Join Date
    Aug 2008
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: Servo motor does not work correct

    As I said the command RX does not work.
    Here's a video made ​​in proteus.

  2. #2
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Servo motor does not work correct

    The code you are running is not the code in #5 and #19.

    Please post the code you are using.

  3. #3
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Servo motor does not work correct

    As I said the command RX does not work.
    RX is not a command. RX is a variable which is assigned an ASCII code when serin2 is executed.

    I see you changed IF THEN to SELECT CASE. SELECT CASE is for values and not ASCII characters like "A".

    Did it stop working when you made these changes?
    Did you make these changes because it did not work with IF THEN?
    Is the servo working if not has the servo ever worked?

  4. #4
    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
    Here is the code

    @ 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

    RX VAR BYTE
    POS VAR word

    PROG:
    serin2 RX_inp,84,500,MODATA,[wait("PC"),RX,DEC POS]

    SELECT CASE RX
    CASE "1"
    GOSUB FRE
    CASE "2"
    GOSUB TRA
    CASE "3"
    GOSUB DIR
    CASE "4"
    GOSUB ESQ
    CASE "5"
    HIGH PORTB.0
    pauseus 1000 + pos
    LOW PORTB.0
    Pause 16
    END SELECT
    GOTO PROG

    FRE:
    PORTC.0 = 0
    PORTC.1 = 1
    PORTC.2 = 1
    PORTC.3 = 0
    RETURN
    TRA:
    PORTC.0 = 1
    PORTC.1 = 0
    PORTC.2 = 0
    PORTC.3 = 1
    RETURN
    ESQ:
    PORTC.0 = 1
    PORTC.1 = 0
    PORTC.2 = 1
    PORTC.3 = 0
    RETURN
    DIR:
    PORTC.0 = 0
    PORTC.1 = 1
    PORTC.2 = 0
    PORTC.3 = 1
    RETURN

    MODATA:

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


  5. #5
    Join Date
    Aug 2008
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: Servo motor does not work correct

    Here the right code.
    Please dis me if I'm on track.
    sorry

    @ 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

    RX VAR BYTE
    POS VAR word

    PROG:
    serin2 RX_inp,84,500,MODATA,[wait("PC"),RX,DEC POS]

    SELECT CASE RX
    CASE "1"
    GOSUB FRE
    CASE "2"
    GOSUB TRA
    CASE "3"
    GOSUB DIR
    CASE "4"
    GOSUB ESQ
    CASE "5"
    HIGH PORTB.0
    pauseus 1000 + pos
    LOW PORTB.0
    Pause 16
    END SELECT
    GOTO PROG

    FRE:
    PORTC.0 = 0
    PORTC.1 = 1
    PORTC.2 = 1
    PORTC.3 = 0
    RETURN
    TRA:
    PORTC.0 = 1
    PORTC.1 = 0
    PORTC.2 = 0
    PORTC.3 = 1
    RETURN
    ESQ:
    PORTC.0 = 1
    PORTC.1 = 0
    PORTC.2 = 1
    PORTC.3 = 0
    RETURN
    DIR:
    PORTC.0 = 0
    PORTC.1 = 1
    PORTC.2 = 0
    PORTC.3 = 1
    RETURN

    MODATA:

    PORTC.0 = 0
    PORTC.1 = 0
    PORTC.2 = 0
    PORTC.3 = 0
    GOTO PROG


  6. #6
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Servo motor does not work correct

    Quote Originally Posted by EarlyBird2 View Post
    RX is not a command. RX is a variable which is assigned an ASCII code when serin2 is executed.

    I see you changed IF THEN to SELECT CASE. SELECT CASE is for values and not ASCII characters like "A".

    Did it stop working when you made these changes?
    Did you make these changes because it did not work with IF THEN?
    Is the servo working if not has the servo ever worked?
    Thanks for the code but you have not answered the questions.

  7. #7
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Servo motor does not work correct

    Looking at the code "CASE "1" is saying CASE = "1" not CASE = 1 there is a big difference. "1" is a string with ASCII value of 49 and 1 is a value of 1.

    CASE works with a value and not with strings but you can use the ASCII value.
    So CASE "1" should be CASE 49
    and CASE "A" should be CASE 65

    for example.

  8. #8
    Join Date
    Aug 2008
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: Servo motor does not work correct

    Quote Originally Posted by EarlyBird2 View Post
    Looking at the code "CASE "1" is saying CASE = "1" not CASE = 1 there is a big difference. "1" is a string with ASCII value of 49 and 1 is a value of 1.

    CASE works with a value and not with strings but you can use the ASCII value.
    So CASE "1" should be CASE 49
    and CASE "A" should be CASE 65

    for example.
    Hello
    About your question
    I modified the program to SELECT CASE.para get better to understand the program.

  9. #9
    Join Date
    Aug 2008
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: Servo motor does not work correct

    Hello
    Now already understand what you said.
    on the servo seems to me that something is missing he is without direction
    Here is the corrected code.
    thank you
    @ DEVICE PIC16F876A
    @ DEVICE PIC16F876A,WDT_OFF
    @ DEVICE PIC16F876A,PWRT_OFF
    @ 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

    RX VAR BYTE
    POS VAR word
    POS = 1500

    PROG:
    serin2 RX_inp,84,600,MODATA,[wait("PC"),RX,DEC POS]

    SELECT CASE RX
    CASE 65 'A
    GOSUB FRE
    CASE 66 'B
    GOSUB TRA
    CASE 67 'C
    GOSUB DIR
    CASE 68 'D
    GOSUB ESQ
    CASE 69 'E
    HIGH PORTB.0
    pauseus 1500 + pos
    LOW PORTB.0
    Pause 20
    END SELECT
    GOTO PROG

    FRE:
    PORTC.0 = 0
    PORTC.1 = 1
    PORTC.2 = 1
    PORTC.3 = 0
    RETURN
    TRA:
    PORTC.0 = 1
    PORTC.1 = 0
    PORTC.2 = 0
    PORTC.3 = 1
    RETURN
    ESQ:
    PORTC.0 = 1
    PORTC.1 = 0
    PORTC.2 = 1
    PORTC.3 = 0
    RETURN
    DIR:
    PORTC.0 = 0
    PORTC.1 = 1
    PORTC.2 = 0
    PORTC.3 = 1
    RETURN

    MODATA:
    PORTC.0 = 0
    PORTC.1 = 0
    PORTC.2 = 0
    PORTC.3 = 0
    GOTO PROG

  10. #10
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: Servo motor does not work correct

    If the PC is not sending A, B, C and D in the proper sequence, the motor will not turn, MODATA will hold the motor in place.

    Robert

Similar Threads

  1. Servo motor control
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th July 2010, 23:44
  2. servo motor control??help
    By HYETİK in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th April 2009, 08:41
  3. servo/motor problem
    By griffin in forum mel PIC BASIC
    Replies: 10
    Last Post: - 10th February 2009, 21:07
  4. Servo motor problem
    By dboy in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 20th September 2008, 16:54
  5. contorlling servo motor
    By shirleyz in forum General
    Replies: 10
    Last Post: - 1st June 2008, 00: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