Servo control with 12F629


Closed Thread
Results 1 to 4 of 4
  1. #1
    achilles03's Avatar
    achilles03 Guest

    Default Servo control with 12F629

    I'm having some trouble with a continuous rotation servo and a 12F629. I've managed to have a BS2 control the servo at different speeds in both directions, but everytime I try to use the 12F629 to control the servo, it only operates in one direction (counter-clockwise) at the same speed (fast). A typical program I'd use with the BS2 was:

    loop
    pulsout 0, 750
    pause 20
    goto loop

    The code I used for the 12F629 was:

    loop
    pulsout 0, 150
    pause 20
    goto loop

    I tried varying the 150 to 100, 180, 750, etc... with the same direction and speed everytime. I'm using the 12F629's internal RC oscillator (4Mhz), which is why I use the 150 instead of the 750 (for the BS2). I even included a "Define OSC 4" to make sure the pulsout was correct.

    Does anyone have any suggestions or advice as to what I'm doing wrong?

    Thanks in advance!
    Dave

    P.S. Also, everytime I touch any of the leads with my finger (ground, +5V, etc), the servo stops. Is this because my finger is interfering with the capacitance of the internal RC oscillator, effectively stopping the 12f629?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Turn off analog comparators so your pins can be used for digital I/O.

    CMCON = 7

    PULSOUT toggles the pin twice, so the initial state of the pin determines
    the logic of the pulse.

    LOW 0 ' We want a high-going pulse or low-high-low with pulsout.

    Code:
    @ DEVICE MCLR_OFF,INTRC_OSC,WDT_OFF,PROTECT_OFF
    
    Define	OSCCAL_1K 1  ' Load factory value into OSCCAL
    CMCON = 7                  ' Turn analog comparators off
    
    X VAR BYTE
    LOW 0        ' Setup GPIO,0 to output a high-going pulse with pulsout
    
    Main:
        FOR X = 1 to 50
        pulsout 0, 100
        pause 15
        NEXT X
        
        pause 1000
        
        FOR X = 1 to 50
        pulsout 0, 200
        pause 15
        NEXT X
        
        pause 1000
        
        goto Main
    
        end
    You may want to tweak the pulsout periods, but that should get you started.

    Make sure you use a separate power supply for your servo. Using the same PS as the PIC will cause problems.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    achilles03's Avatar
    achilles03 Guest


    Did you find this post helpful? Yes | No

    Default Re: Servo control with 12F629

    Bruce,
    Thanks for the help! The CMCON = 7 I think is what did the trick (i.e. it works). However, it works only intermittently. It seems that the microchip is only executing the full program when I have my finger on the +5V lead (and then only sometimes). I'm wondering what's causing this? I'm using the INTRC (IN) configuration option. I am also using the same PS for the servo and the chip (wall wart to a 1A, 5V regulator). Is the cause of this most likely due to sharing of the power source, a touchy internal oscillator, or something else?

    Thanks again for the help.

    Dave

    Quote Originally Posted by Bruce
    Turn off analog comparators so your pins can be used for digital I/O.

    CMCON = 7

    PULSOUT toggles the pin twice, so the initial state of the pin determines
    the logic of the pulse.

    LOW 0 ' We want a high-going pulse or low-high-low with pulsout.

    Code:
    @ DEVICE MCLR_OFF,INTRC_OSC,WDT_OFF,PROTECT_OFF
    
    Define	OSCCAL_1K 1  ' Load factory value into OSCCAL
    CMCON = 7                  ' Turn analog comparators off
    
    X VAR BYTE
    LOW 0        ' Setup GPIO,0 to output a high-going pulse with pulsout
    
    Main:
        FOR X = 1 to 50
        pulsout 0, 100
        pause 15
        NEXT X
        
        pause 1000
        
        FOR X = 1 to 50
        pulsout 0, 200
        pause 15
        NEXT X
        
        pause 1000
        
        goto Main
    
        end
    You may want to tweak the pulsout periods, but that should get you started.

    Make sure you use a separate power supply for your servo. Using the same PS as the PIC will cause problems.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    You don't want to run a servo from the same power supply your PIC runs on unless it's a bench type power supply or one that can handle a ton of current without dropping its output.

    Use a separate supply or batteries for the servo motor. Should take care of the problem.

    You might also want to strap a 0.1uF cap across the PIC Vcc & gnd pins too. Helps filter spikes from the supply, and it can keep the PIC from resetting at odd times.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. More Servo Woes
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 13th May 2009, 08:40
  2. Replies: 10
    Last Post: - 26th May 2008, 07:00
  3. Problem with 12F629, servo and EEPROM
    By Atom058 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 1st March 2008, 09:53
  4. Help with Servo Control Please!
    By wireman22 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th June 2007, 18:15
  5. Control RC servo via Parallax Servo Control
    By cibotsan in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th September 2005, 08:18

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