Servo troubles.


Closed Thread
Results 1 to 28 of 28

Thread: Servo troubles.

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Code:
    @ device HS_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
    DEFINE OSC 4
    'Use b1 to hold pulse width variable for servo 1
    b1 var byte
    'initialize variables
    b1 = 150
    low portb.0		' put the servoport low.
    main:
            low portb.0
    	pulsout portb.0, b1		'send current servo 1 position out
    	if porta.0 = 0 then left1	'check for pressed switch 0
    	if porta.1 = 0 then right1	'check for pressed switch 1
    	if b1 > 150 then
                   b1 = b1 - 1
            else
                   b1 = b1 + 1
            endif
            pause 18 : goto main
    left1:  b1 = b1 + 1 : if b1 >254 then max1
    	goto main
    right1:  b1 = b1 - 1 : if b1 <75 then min1
    	goto main
    max1:  b1 = 75 : goto main
    min1:  b1 = 254 : goto main
    END
    This should go left with one button, go right with the other button, and if no buttons are pressed, should 'walk' back to center.
    Note the BOLDED statements

  2. #2
    Join Date
    Sep 2008
    Location
    Stockholm
    Posts
    80


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    This should go left with one button, go right with the other button, and if no buttons are pressed, should 'walk' back to center.
    Note the BOLDED statements
    Unfortunatly it gives exactly the same result, the servo goes to the endpoint and stay there..

    ..And just like in my program, if I uncomment the if-lines it "works" as in it stands in the middle position (more or less)

    Strange.

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    Just place

    PAUSE 18

    just after PULSOUT command ...

    instead of Before " GOTO Main" .

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Sep 2008
    Location
    Stockholm
    Posts
    80


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi,

    Just place

    PAUSE 18

    just after PULSOUT command ...
    No, exactly the same result

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    That was to get a decent frame duration whatever you do with the buttons.

    Seems the pot cursor is out of its lane ... or see PS !!!

    Now, you should place the Max value for b1 to 200 and min value to 100 ... I know servos not responding for values out of this range.

    something possible is the méchanical travel is over the pot travel ... not good at all.

    and remember Futaba analogic servos MECHANICAL center is +/- 1300µs. you must take this into account if you try more than the +/- 500µS trip ...

    Now ... an interesting question ...


    Where do your servo take its power ???

    Alain

    PS1: you sure PORTA.0 AND PORTA.1 can't be 0 together ???
    PS2: you sure your comparators are disabled ??? ... 16F628 !!!

    ... Lol ...
    Last edited by Acetronics2; - 21st September 2008 at 19:12.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Sep 2008
    Location
    Stockholm
    Posts
    80


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    That was to get a decent frame duration whatever you do with the buttons.

    Seems the pot cursor is out of its lane ... or see PS !!!

    Now, you should place the Max value for b1 to 200 and min value to 100 ... I know servos not responding for values out of this range.
    Well but it work with the lines uncommented, and stands fairly in the middle.

    I also tried three different servos.

    Now ... an interesting question ...
    Where do your servo take its power ???
    Well, my testsetup is built on an breadboard, and the servo is connected via a pinstrip and directly to the same power as the rest of the setup, which is powered from the +5V 2A output on my lab power supply.

    Btw I'm using a pickit2 from microchip to program the pic via ICSP, and its permanently connected to the pic.


    PS1: you sure PORTA.0 AND PORTA.1 can't be 0 together ???
    Yes, I used a switch with three positions, (on)off(on) first, but now I just use a cable directly on the breadboard.

    PS2: you sure your comparators are disabled ??? ... 16F628 !!!
    No idea, how do I do that ?
    Last edited by Glenn; - 21st September 2008 at 21:33.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Ok, try this...
    Code:
    @ device HS_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
    DEFINE OSC 4
    temp var byte
    main:
            for temp = 0 to 255
            pulsout portb.0, temp
    	pause 18
            next temp
            for temp = 255 to 0 step -1
            pulsout portb.0, temp
            pause 18
            next temp
            goto main
    END
    This should do nothing more than swing the servo back and forth, from endpoint to endpoint. It'll probably hang up for a bit at the endpoints and might even move too fast or jerk around a bit trying to catch up to the program.
    If it doesn't, you've got something else going on.
    It all boils down to breaking it down to it's simplest form and building it back up again.
    Try it and report back...

  8. #8
    Join Date
    Sep 2008
    Location
    Stockholm
    Posts
    80


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    This should do nothing more than swing the servo back and forth, from endpoint to endpoint. It'll probably hang up for a bit at the endpoints and might even move too fast or jerk around a bit trying to catch up to the program.
    If it doesn't, you've got something else going on.
    It all boils down to breaking it down to it's simplest form and building it back up again.
    Try it and report back...
    Well, it swings the servoarm to one endpoint, stops for a while, then all the way to the other endpoint (or near it anyway) and directly start to go back again and repeats everything.

    Its not a very smooth movement but it looks ok.

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Glenn View Post
    Well, it swings the servoarm to one endpoint, stops for a while, then all the way to the other endpoint (or near it anyway) and directly start to go back again and repeats everything.

    Its not a very smooth movement but it looks ok.
    Ok, that's good...at least you know stuff is working.

    Now take the program and modify it to 'pull the endpoints' in a bit until you get to the actual endpoints.
    When it 'stops for awhile', the program is probably trying to drive the servo past it's endpoints. The program goes to 0ms pulse width, but the servo can only actually drive to a 1ms pulse width, actually it'll probably drive farther than that, a lot farther, just not all the way to zero, or by the same token, won't drive all the way to 2.55 ms pulse width.

    Code:
    @ device HS_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
    DEFINE OSC 4
    temp var byte
    main:
            for temp = 100 to 200
            pulsout portb.0, temp
    	pause 17 'try lower numbers until it starts acting even stupider than it's acting now
            next temp
            for temp = 200 to 100 step -1
            pulsout portb.0, temp
            pause 18 'try lower numbers until it starts acting even stupider than it's acting now
            next temp
            goto main
    END
    Decrease the 100 until it starts pausing at one end (meaning the PIC is trying to over-drive the servo) and increase the 200 until it starts pausing at the other end (again, meaning the PIC is trying to over-drive the servo in the other direction).

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Hi, Glenn

    This one Should run

    Code:
    @ device HS_OSC,MCLR_OFF,LVP_OFF,WDT_ON,PROTECT_OFF
    DEFINE OSC 4
    
    CMCON = 7 ' Disable comparators
    
    PORTA = %00000011
    PORTB = 0
    
    TRISA = %00000011
    TRISB = 0
    
    'Use b1 to hold pulse width variable for servo 1
    
    b1 var byte
    
    'initialize variables
    b1 = 150
    
    low portb.0		' put the servoport low.
    main:
    
            low portb.0
    	pulsout portb.0, b1		'send current servo 1 position out
    	if porta.0 = 0 then left1	'check for pressed switch 0
    	if porta.1 = 0 then right1	'check for pressed switch 1
    
    bugtrap:
    
            if b1 > 150 then
                   b1 = b1 - 1
    
            else
                   if b1 < 150 then b1 = b1 + 1
                  
            endif
            pause 18 : goto main
    
    left1: 
             IF porta.1 = 0 Then bugtrap
             b1 = b1 + 1 
             if b1 > 199 then max1
             Pause 8 : goto main
    
    right1:  
               IF Porta.0 = 0 Then bugtrap
               b1 = b1 - 1 
               if b1 < 100 then min1
               Pause 8 : goto main
    
    max1:  b1 = 100 : goto main ; jump to other side
    
    min1:  b1 = 200 : goto main ; jump to other side
    
    END
    and do not forget : courtesy SKI !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  11. #11
    Join Date
    Sep 2008
    Location
    Stockholm
    Posts
    80


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Glenn

    This one Should run
    Well, it kind of works, the servo stands still until I touch the switch, but it moves in very strange ways, I'll try to adjust the values a bit and see if it changes anything.

    But it sure looks like the comparators was the problem, great!

  12. #12
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by Glenn View Post
    Well, it kind of works, the servo stands still until I touch the switch,
    Looks it should be in the 1500µs position ...

    but it moves in very strange ways, I'll try to adjust the values a bit and see if it changes anything.
    should reach slowly one end, then RUN to the other end, then slowly to the other end , Then RUN ...

    WHILE pushing a button

    and going back to center if buttonS realeased ... or both buttons pushed.


    But it sure looks like the comparators was the problem, great!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  13. #13
    Join Date
    Sep 2008
    Location
    Stockholm
    Posts
    80


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Decrease the 100 until it starts pausing at one end (meaning the PIC is trying to over-drive the servo) and increase the 200 until it starts pausing at the other end (again, meaning the PIC is trying to over-drive the servo in the other direction).
    Well, as you said before the values depends on which servo I use, I settled for the servo that I'm going to use (the brand new china-made) and with that 75 and 255 seem to be the correct values, however, when its 255, its still not at the endpioint, its a few mm more left. ..However this doesnt matter.

  14. #14
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Glenn View Post
    however, when its 255, its still not at the endpioint, its a few mm more left. ..However this doesnt matter.
    Change your BYTE variable to a WORD variable and you'll be able to go beyond 2.55 ms. But that sounds a bit goofy since a 2.55ms pulse width is out of spec for most servo's. But hey, if it works for you, go with it...

  15. #15
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Hi, SKI

    The maximum I ever reached is 250 µs to 2600 µs ... with a Futaba S3001 or a Robbe RS100 ...

    not linear at all between 250 and 600µs !!!

    regards
    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. More Servo Woes
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 13th May 2009, 09:40
  2. Problem with 12F629, servo and EEPROM
    By Atom058 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 1st March 2008, 10:53
  3. Servo does not move
    By ruijc in forum General
    Replies: 12
    Last Post: - 12th November 2007, 20:14
  4. Beginner + Servo
    By james in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st July 2007, 22:31
  5. Help with Servo Control Please!
    By wireman22 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th June 2007, 19:15

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