Servo troubles.


Closed Thread
Results 1 to 28 of 28

Thread: Servo troubles.

Hybrid View

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

    Default Servo troubles.

    Hi, this is my first message, and I hope my problems isnt too stupid..

    Anyway, I'm building something with RC-servos and stumbled upon PBP wich looked like an very easy way for me to control them, however, my first little test aint working, and I have no idea why, I given up with my original code and hammered it down to just some testroutine that, in my opinion SHOULD work..

    Here is the testcode:

    Code:
    @ device INTRC_OSC_NOCLKOUT,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
    '@ device HS_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
    DEFINE OSC 4
    
    ct var byte
    
    ct = 150
    
    pause 250
    
    low portb.1  ' force the status-LED off.
    
    pulsout portb.0, ct   ' this should place the servo in middle position.
    
    pause 1000  ' Wait a while..
    
    loop:
    
    for ct = 1 to 255 step 1
    
    pulsout portb.0, ct  ' put the value of the counter to the servo.
    
    Next ct
    
    high portb.1  ' turn the status-LED on.
    
    pause 1000 ' Wait..
    
    low portb.1  ' Turn the status-LED off again.
    
    goto loop
    ..This little code would in my opinion first put my servo in middle position, wait 1000, and then start to step it from one end position to the other. ..Then the status-LED should light up, wait 1000, and then go black again, and after than it should start to move the same again.

    ..This is not what happens, the servo does NOT enters the middle position, its goes to a position very near one end, then it moves back and forward a few millimeters, the LED acts as excpected.

    Why ? ..first I thought that it was the internal oscillator that was the problem so I put a xtal with two caps at pin 15 and 16, and changed the first line to use an external clock, no difference at all.

    Any idea ?

    ..Even more strange is that if I try to set the servo to 150 permanently it goes to one endstop and stops there ?


    ..I have a feeling that everything kinda works, but are completly " off scale", and I have no idea why.

    ..Oh, forgot, the pic is an 16F628A and the xtal is 4MHz.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Servo's need to be continuously updated about 50 times per second.
    Those pauses are screwing with your servo causing it to lose it's mind.

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


    Did you find this post helpful? Yes | No

    Default

    Aha.. Hmm, but my original code didnt have those pauses, and still doesnt work..

    But I'll change my testcode and remove the pauses and makes it update continuosly.

    ..Also, if I make a loop that just send 150 to the servo, it stands in one of the nedpositions.. shouldnt that (150) be the middle position ?

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Glenn View Post
    Aha.. Hmm, but my original code didnt have those pauses, and still doesnt work..
    But I'll change my testcode and remove the pauses and makes it update continuosly.
    ..Also, if I make a loop that just send 150 to the servo, it stands in one of the nedpositions.. shouldnt that (150) be the middle position ?
    If your original code was going too FAST, you might see the same results.
    And a middle position of 150 (1.5ms) is almost an arbitrary number...might be 160, might be 140-ish. Depends on the servo and what day of the week it was made...
    Code:
    @ device INTRC_OSC_NOCLKOUT,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
    DEFINE OSC 4
    ct var byte : ct2 var byte : ct = 150 : low portb.1
    main:
         for ct = 150 to 250 step 1    'sweep one way
              for ct2 = 1 to 50
                   pulsout portb.0, ct
                   pause 18
              next ct2
         next ct
         for ct2 = 1 to 50    'hang out there for a bit
              pulsout portb.0, ct
              pause 18
         next ct2
         for ct = 250 to 150 step -1     'sweep the other way
               for ct2 = 1 to 50
                    pulsout portb.0, ct
                    pause 18
               next ct2
         next ct
         for ct2 = 1 to 50     'hang out there for a bit
              pulsout portb.0, ct
              pause 18
         next ct2
    goto main

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


    Did you find this post helpful? Yes | No

    Default

    Hmm, well that works, sort of.. its not centering and its not full to the ends..

    I tried my old "center the servo" code with slightly modifications too:

    Code:
    ' servocenter
    @ device INTRC_OSC_NOCLKOUT,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF
    DEFINE OSC 4
    
    start:
    	pulsout portb.0, 150
    	pause 18
    	goto start
    ..Well, this is strange..

    The first time I tried it it seemed to work.. but if i moved the servoarm (with power disconnected ofcourse) it gives very strange results.

    If its in 180 degrees position, or close to that, it will work, it will center (more or less) the arm and hold it there.. HOWEVER.. if its in another position, it will just hold the current position ??

    this is so strange.

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


    Did you find this post helpful? Yes | No

    Default

    Ok, now I suspected the servo, so I changed the brand new chinese servo to an old one from my box of "old RC stuff", and with two different (working) hitec servos (different models) I get another result, they go to one endpoint and stay there, regardless of the original position ??

Similar Threads

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

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