Servo Control


Closed Thread
Results 1 to 8 of 8

Thread: Servo Control

  1. #1
    zmet68's Avatar
    zmet68 Guest

    Default Servo Control

    Can someone show me how to sweep two servo’s back and forth. I would like to be able to control the speed and distance individually. I am using pbp with a 16F84A IC. I have no idea where to start, any help would be appreciated.

    Thanks Brett

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    to make your back and forth stuff, if your motor don't need much current, it will be easier to use a H-Bridge driver IC like NJM2670 or else.

    By using 2 i/o, you'll be able to do it easy...

    will look something like this
    Code:
    TRISA = 255 ' set PORTA as input
    TRISB=0 ' set PORTB as output
    
    Motor1_a var PORTB.0  
    Motor1_b var PORTB.1
    
    PushButtonForward var PORTA.0 ' Push button connected 
    PushButtonReverse var PORTA.1 ' between vcc and PIC pin
    PushButtonStop Var PORTA.2
    
    PORTB=0
    
    Start:
         If PushButtonForward then 
              Motor1_a = 1
              Motor1_b = 0
         endif
    
         If PushButtonReverse then
              Motor1_a = 0
              Motor1_b = 1
         endif
    
         If PushButtonStop then
              Motor1_a = 0
              Motor1_b = 0
         endif
    
         goto start
    to measure the distance you'll have to use rotary encoder, opto devices or something who will provide you some pulses when motor/wheel is turning. By counting those pulse in background (on RA4 pin using internal Timer/Counter module) you'll have some numbers to do your maths

    For the speed...it's up to you... some will use PWM, some will vary the voltage accross the motor and probably there's many other way to do it... food for brain cells ;o]
    Last edited by mister_e; - 12th February 2005 at 16:06.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    The lower section of this page (link below) explains how to use the PULSOUT command to control hobby servo motors.

    http://www.rentron.com/Micro-Bot/IR_Nav.htm
    Regards,

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

  4. #4
    zmet68's Avatar
    zmet68 Guest


    Did you find this post helpful? Yes | No

    Default

    Can this be done without pushing a button? sorry i'm verry new to this. I'm doing pretty good with the hole blinking LED thing.

    Thanks for all the help

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    it can be done as you wish. You're the boss, you decide what you want to do and how.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    Try this;
    Code:
    @ DEVICE HS_OSC,WDT_OFF,PROTECT_OFF
    DEFINE OSC 20    ' We're using a 20MHz crystal
    
    TRISB=%00000000  ' Set PortB to all outputs
    PORTB=%00000000  ' Clear PortB
    Position    VAR WORD    ' Servo position data
    Y           VAR BYTE    ' Servo position update speed
    Left_Servo  var PortB.4 ' PortB.4 = left servo output
    Right_Servo var PortB.5 ' PortB.5 = right servo output
    
    Y = 20
    Servo:
        FOR Position = 1100 to 400 step-Y
          PULSOUT Left_Servo,Position
          PAUSE 15
        NEXT Position
        FOR Position = 1100 to 400 step-Y
          PULSOUT Right_Servo,Position
          PAUSE 15
        NEXT Position
        FOR Position = 400 to 1100 step Y
          PULSOUT Left_Servo,Position
          PAUSE 15
        NEXT Position
        FOR Position = 400 to 1100 step Y
          PULSOUT Right_Servo,Position
          PAUSE 15
        NEXT Position
        Y = Y-1
        IF Y <=4 THEN Y=20
        GOTO Servo
    Adjust the values 1100 to 400 for your particular servos.

    The resolution of PULSOUT at 20MHz is 2uS. 1100 * 2uS = 2.2mS. 400 * 2uS = 800uS. Most hobby type servos require between 1 to 2mS pulses, but it can vary depending on the servo brand.

    Just experiment until you get the movement you need without slamming the servo into its stops when moving full left or full right. Increase the value of Y to speed up movement. Decrease it to slow down.

    Have fun.....;o]
    Regards,

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

  7. #7
    Join Date
    Feb 2005
    Location
    Revelstoke BC Canada
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    zmet68
    Go to my website and download the "Pic Primer" it will tell you everything you need to know. I wrote it around the 16F628 and the servo section is designed for the 12F675, but you should be able to adapt it to any pic.

    http://www.dragonslair.ca/workstation.html

    Dave

  8. #8
    zmet68's Avatar
    zmet68 Guest


    Did you find this post helpful? Yes | No

    Thumbs up

    WOW, Thanks for the Pic Primer. You have all been very helpful.Being that I’m new to pbp and I have no prior programming skills all the help I can get the better.

    Thanks

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. Help with Servo Control Please!
    By wireman22 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th June 2007, 18:15
  4. Control RC servo via Parallax Servo Control
    By cibotsan in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th September 2005, 08:18
  5. Servo control with 12F629
    By achilles03 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd June 2005, 23:34

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