Beginner + Servo


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2007
    Location
    Maryland, USA
    Posts
    15

    Post Beginner + Servo

    Hello,

    Am in my first month of learning to program, and have completed most projects in the " PicBasic Projects - Book, by : Dogan Ibrahim ".

    I am currently trying to control a servo motor(Tower Hobbies: STD TS-53) via a toggle switch. Switch one way to turn the servo Clockwise, opposite position for Counter Clockwise. Center position to center the servo

    when power is applied my servo spins to the center and then vibrates and will not respond to switch. I am new and looking to learn, if I am using code improperly please inform me, I dont want to start off on the wrong foot.

    using pic16F648, my code is as follows :
    Code:
    'PICBasic pro manual servo control program

    symbol switchCW = porta.1
    symbol switchCCW = porta.0
    symbol servo = portb.0


    Position var byte


    start:

    'look at switches on Port A
    IF switchCW = 1 and switchCCW = 1 then goto loop

    Position = 150
    Pulsout servo, Position
    pause 18

    loop:
    if SwitchCW = 0 then
    Position = 130
    Pulsout servo, Position
    Pause 18
    endif

    If SwitchCCW = 0 then
    Position = 170
    pulsout servo, Position
    Pause 18
    endif

    Pause 18
    Goto loop
    *****************
    end of program....

    Thank you, for any feedback
    Last edited by james; - 31st July 2007 at 20:46.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Hi,

    Could not find the code you are using in my manual?
    But, the chip you are using 16F648 does not show up at MICROCHIP, the A version does. If it is the "A" version there are a couple of comparators on PORTA.

    You will need to turn the comparators off to make PORTA.0 and PORTA.1 regular I/Os.
    Code:
    CMCON = 7
    Should be at the top of your code.

    If this is the problem here are two post that will explain more.
    http://www.picbasic.co.uk/forum/showthread.php?t=561
    http://www.picbasic.co.uk/forum/showthread.php?t=562

    POTRA has some different things than the other PORTS.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jul 2007
    Location
    Maryland, USA
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    thank you for your quick response!

    please excuse my typo earlier, PIC16F648A is the chip Im using.

    and the "CMCON = 7" at the beginning of my code fixed the problem with my switches not responding.

    My servo will now respond to the switch being toggled, but I would like for my servo to center itself when the switch is in it's center position. I have been reading different versions of controlling servo's via switches, and buttons and have tried my best to combine, into my idea of a logical procedure(not to say the others are not), just trying to write my first bit of code

    again thank you for your response.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Try this-- UNTESTED
    Code:
    start:
    
    'look at switches on Port A
    IF (switchCW = 1) and (switchCCW = 1) then
    GOTO HOME
    ELSE
    GOTO LOOP
    ENDIF
    GOTO start
    
    HOME:
    Position = 150
    Pulsout servo, Position
    pause 18
    GOTO start
    
    loop:
    if SwitchCW = 0 then
    Position = 130
    Pulsout servo, Position
    Pause 18
    endif
    
    If SwitchCCW = 0 then
    Position = 170
    pulsout servo, Position
    Pause 18
    endif
    
    Pause 18
    Goto loop
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. More Servo Woes
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 13th May 2009, 08:40
  2. saving RCREG to word
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th September 2008, 13:51
  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. Servo does not move
    By ruijc in forum General
    Replies: 12
    Last Post: - 12th November 2007, 19:14
  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 : 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