servo control via pot ?


Closed Thread
Results 1 to 11 of 11
  1. #1
    n0oxv's Avatar
    n0oxv Guest

    Default servo control via pot ?

    Question from a newbe !

    I have a 5K pot I would like to control a servo with it
    I know I can use the pot command with the scale function
    but is there a better way ? using adcin ?

    I am not using any regulator and just running from a 4.8 V nicad battery pack and 4 mhz

    currently using a 16f628
    Using the pot command really seems to slow down sending pulses to the servo

    <RC Servo 1 - 2 ms>

    Thank You
    Gary

  2. #2
    magix's Avatar
    magix Guest


    Did you find this post helpful? Yes | No

    Default

    It is a good idea to convert a voltage with AD converter, but microcontroller 16F628 does not have internal AD converter, So you can not use instruction ADCIN in this case.
    You can try 16F873 or sth. like that.
    Last edited by magix; - 15th September 2004 at 01:47.

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


    Did you find this post helpful? Yes | No

    Default

    You'll need a PIC with onboard A/D to use ADCIN. This works on an F876.

    Code:
    DEFINE  OSC 4
    DEFINE	ADC_BITS 8      ' Set number of bits in result
    DEFINE	ADC_CLOCK 2     ' Set clock source (3=rc)
    DEFINE	ADC_SAMPLEUS 50 ' Set sampling time in uS
    SVO_POS VAR BYTE
    
        ' 90 deg horn rotation (adjust for servo)
        'LEFT    CON 100       ' Left position 1mS
        'RIGHT   CON 200       ' Right position 2mS
    
        ' 180 deg horn rotation (adjust for servo)
        LEFT    CON 70         ' Left position 0.70mS
        RIGHT   CON 240        ' Right position 2.4mS
    
        TRISA = %00001001 ' RA0 = A/D input
        ADCON1.7 = 0      ' RA.3 = +Vref, Set PORTA analog and left justify result
        LOW 0             ' Setup RB0 for high-going pulseout
    
    Loop:
        ADCIN 0,SVO_POS   ' Read A/D channel
        IF SVO_POS < LEFT THEN SVO_POS = LEFT
        IF SVO_POS > RIGHT THEN SVO_POS = RIGHT
        PULSOUT 0,SVO_POS ' Move servo
        PAUSE 15            ' ~60Hz update-rate
        GOTO Loop         ' Forever
    Regards,

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

  4. #4
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default Control 4 Servos - 4 Pots - Same PIC

    I am interested in controlling 4 Servos, sensing 4 Pots Connected to the 4 Analog Inputs of 16F873.

    I tried with just one Pot and One Servo , works just fine , But with 4 Pots and four Servo's, it jerks.

    I am sure , i am doing some thing wrong and need some help. I am running the PIC @ 4Mhz.

    Mainloop:

    LOW SERV1 : LOW SERV2 :LOW SERV3 :LOW SERV4 :

    GOSUB READ_POTS
    '-----------------------------------------------------------------
    SERVO = 150*TEMP1 : SERVO = SERVO / 255 : SERVO = SERVO + 90
    pulsout serv1 ,servo : PAUSE 15
    '-----------------------------------------------------------------
    '-----------------------------------------------------------------
    SERVO = 150*TEMP2 : SERVO = SERVO / 255 : SERVO = SERVO + 90
    pulsout serv2 ,servo : PAUSE 15
    '-----------------------------------------------------------------
    '-----------------------------------------------------------------
    SERVO = 150*TEMP3 : SERVO = SERVO / 255 : SERVO = SERVO + 90
    pulsout serv3 ,servo : PAUSE 15
    '-----------------------------------------------------------------
    '-----------------------------------------------------------------
    SERVO = 150*TEMP4 : SERVO = SERVO / 255 : SERVO = SERVO + 90
    pulsout serv4 ,servo : PAUSE 15
    '-----------------------------------------------------------------
    pause 18

    GOTO Mainloop

    END

    READ_POTS:

    Adcin 0, TEMP1 ' Read FIRST POT
    Adcin 1, TEMP2 ' Read SECOND POT
    Adcin 2, TEMP3 ' Read THIRD POT
    Adcin 3, TEMP4 ' Read FOURTH POT

    RETURN

    regards

  5. #5
    blainecf's Avatar
    blainecf Guest


    Did you find this post helpful? Yes | No

    Thumbs up add a little more code so you only react to changes

    Performing calculations and a series of reads in a row is your major prob. Here's an idea - (pseudo code):

    #1:

    define prev_value vars

    Loop:
    for i = 1 to 4

    read one pot (based on i)

    check to see if it changed (compared to a previously saved value)

    if changed, calc new value

    pulse_out each of your motors
    next i
    goto loop


    This way you're only doing one A/D read per loop, and only doing the math when the value of the pot changes (multiplication and (even more so) division are clock cycle suckers!

    ------------------

    #2: do away with the gosubs in speed-critical situations. In-line code is harder to read, but faster

    Regards,

  6. #6
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default

    Thanks , I shall give it a try and post the results tomorrow.

    regards

  7. #7
    dhari's Avatar
    dhari Guest


    Did you find this post helpful? Yes | No

    Default Does anyone have a full program (MPLAB) done on project list below

    [QUOTE=charudatt;23362]I am interested in controlling 4 Servos, sensing 4 Pots Connected to the 4 Analog Inputs of 16F873.

  8. #8
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by charudatt View Post
    I am interested in controlling 4 Servos, sensing 4 Pots Connected to the 4 Analog Inputs of 16F873.
    Not sure if this is relevant or not, but in the thread I started on using a PIC as the basis of a model train controller ( http://www.picbasic.co.uk/forum/showthread.php?t=5687 ) I needed to control four independant trains via for pots using PWM.

    This used Darrel's excellent PWM routines and with an 16F676 running at 20 Mhz performed very well. This used 4 x AD convertors and used the value to adjust the PWM, and I'm sure with a simple bit of modification it would do what you want

    Also have a look at this thread http://www.picbasic.co.uk/forum/showthread.php?t=3251
    Last edited by malc-c; - 28th February 2007 at 22:29. Reason: added link to DT's interrups thread

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Disregard below. I didn't notice the dates on the posts above...ya know, the ones from 2004 !


    You've got 78ms worth of pause's in your loop. At best, 78ms worth of pause's limits you to an update rate of just over 12hz. Servo's want an update rate of about 50hz or so.
    Try this:

    Mainloop:
    GOSUB READ_POTS
    SERVO = 150 * TEMP1 : SERVO = SERVO / 255 : SERVO = SERVO + 90 : pulsout serv1 ,servo
    SERVO = 150 * TEMP2 : SERVO = SERVO / 255 : SERVO = SERVO + 90 : pulsout serv2 ,servo
    SERVO = 150 * TEMP3 : SERVO = SERVO / 255 : SERVO = SERVO + 90 : pulsout serv3 ,servo
    SERVO = 150 * TEMP4 : SERVO = SERVO / 255 : SERVO = SERVO + 90 : pulsout serv4 ,servo
    GOTO Mainloop

    READ_POTS:
    Adcin 0, TEMP1:Adcin 1, TEMP2:Adcin 2, TEMP3:Adcin 3, TEMP4 : RETURN
    Last edited by skimask; - 28th February 2007 at 23:17.

  10. #10
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default

    Thanks Skimask,

    Information is never old. The project still stands where it was , and you seem to have put in new life after so many years.

    At present I don't have that many servo's but would surely give it a try with what ever I have.

    OK just a small querry. I am planning to make a Servo Signal reader, Any inputs on it. Just a servo input and display on a LCD.

    regards

  11. #11
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by charudatt View Post
    ...I am planning to make a Servo Signal reader, Any inputs on it. Just a servo input and display on a LCD.

    regards


    Pulsout & Pulsin
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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