Servo loosing my mind...


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2006
    Posts
    91

    Default Servo loosing my mind...

    Ok I'm loosing my mind here!

    The code below works fine sorta.

    Code:
    @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
    DEFINE OSCCAL_1K 1
    INCLUDE "modedefs.bas"
    TRISIO.0 = 0         'Set GPIO.0 to output.
    ANSEL = 0            'disable ADCs
    CMCON = 7            'disable comparator
    T1CON = %00000110          
    ANSEL.1 = 0    'Set GPIO.1 to digital
    Pulselen     Var byte
    ValidCode    Var byte
    I            var byte
    clear
    
    goto main
    
      
    Main:
    validcode=200
    If validcode=200 then
       for I = 1 to 20
       Pulsout GPIO.0, 200
       next I
    endif
    
       validcode=0
          
    goto main
    Whats happening is I compiled it and have a hex file. I load it into flash kit starter, came with my pic kit V1

    I burn a chip
    12F675 and half the time it sends out a .005ms pulse instead of a 2 ms pulse.
    If I take the same chip reburn it, it works maybe if not reburn it and it works...

    What am I doing wrong here that sometimes works perfectly and others not? I'm using the same hex file...

    Any ideas?

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


    Did you find this post helpful? Yes | No

    Default

    Hi,
    What is it you want the code to do?
    You have a FOR-NEXT Loop with PULSOUT but you dont have any PAUSE in there so basicly there will be 20 2mS pulses right after each other with very little time between them. These 20 pulses will be present on the pin for roughly 40mS and then they will stop because you set Validcode to 0 after 20 pulses. So is it possible that you miss seeing the pulses all together?

    HTH

    /Henrik Olsson.

  3. #3
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Thanks for the reply. What I was acutally tying to accomplish is a servo pulse of 2mS that should repeat every 20mS.
    This should basically be a full one way signal for a servo.

    I realize now that I didn't have a delay but still when I hook this to my scope

    Code:
       for I = 1 to 20
       Pulsout GPIO.0, 200
       pause 18
       next I
    I don't get a nice clean 2mS square like I see from a known servo signal.

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Why not just use a plain ol' pause statement for the testing part of your project? It'll at least eliminate the possibility of pulsin causing your problem.
    Code:
    main:
    gpio.0 = 1
    pause 2
    gpio.0 = 0
    pause 2 (then switch it over to 18 after you've verified a good square wave)
    goto main
    It's basically the same ol' blinky led program, but it'll get the ball rolling...

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


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Yes but you will still only get 20 pulses because of the FOR-NEXT lopp. What if you try this:
    Code:
    GPIO.0 = 0
    Main:
       Pulsout GPIO.0, 200
       pause 18
    Goto Main
    /H.O

  6. #6
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    are you scoping it with the servo connected? Servos can put out some pretty nasty noise when running - and need to be seperatly regulated and filtered

  7. #7


    Did you find this post helpful? Yes | No

    Default Preset state of Pulsout pin PLUS add a pause

    Yes you need a pause to pace the servo pulses to approximately 50 per second. In addition, note that Pulsout is only a toggle. Unless you force the pin to a zero at the start of the loop, there is a good chance that sometimes the line will idle high instead of idling low. That drives a servo nuts.

    Try
    for i = 0 to 20
    low servopin
    pulseout servopin, 200
    pause 18
    next i

    Note that 95+% of the time you may get away without forcing the servopin low but there WILL be times when the line idles high. It cost me a plane crash.

    HTH
    Brian

  8. #8
    Join Date
    May 2006
    Location
    Kedah, Malaysia
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    Geckorotto do you connect the servo directly to batteries or you use a LM7805 regulator?

    for I = 1 to 20
    Pulsout GPIO.0, 200
    pause 18
    next I

    This code should work fine. Sometime servo become nut because of the current is not enough.

    That is base on my experience.

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