Simple Servo Position Control Program - Is this right?


Results 1 to 11 of 11

Threaded View

  1. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Hi, Marcus

    this one should work as desired ...

    Code:
    '****************************************************************
    '*  Name    : GrassBurner.BAS                                   *
    '*  Author  : Acetronics                                        *
    '*  Notice  : Copyright (c) 2010                              *
    '*          : All Rights Reserved                               *
    '*  Date    : 23/12/2010                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    '
    @ __config _CONFIG1, _INTRC_IO & _WDT_ON & _LVP_OFF & _CP_OFF
    ' DEFINES
    Define OSC 8
    Define BUTTON_PAUSE 0
    ' Internal Osc 8Mhz
    OSCCON = %01110010
    ' Turn off A/D conversion - Digital Inputs
    ADCON0 = 0
    ANSEL = 0
    ' Comparators Off
    CMCON  = 7
     
    'Define variables and pins
    I         VAR BYTE
    Position var WORD
    Delay  var Byte
    OldButton  var bit
    PORTA  = 0
    TRISA   = %11111101
    BUTTON_  VAR PORTA.0
    SERVO  VAR PORTA.1
     
    buttonloop:     ' Button check loop
     OldButton = 0
     LOW Servo
     Pulsout SERVO, 300  ' pulse to place servo to neutral
     Pause 19
     
    BUTTON BUTTON_,1,255,0,Delay,0,Buttonloop
     OldButton = 1       ' Launched ... We've pressed it !!!
    '******************************************************************************
    positionloop:  'Servo position control loop
     
    I = 0       ' Reset time counter
    While ( OldButton  AND ( I < 75 ))   '  if button has been pushed and time < 1.5s
     
     IF I >= 50 THEN     ' 1 second is ... 50 x 20 ms !    
      position = 300
     ELSE 
      POSITION = 200
     ENDIF 
     
     LOW Servo
     Pulsout SERVO, Position  ' pulse to servo 
     
     PAUSEUs 19813 - ( Position * 5 )        ' time between pulses
     
     I = I+1                         'Increase Time counter
    Wend                                ' go for seeking a new button push ...
     
    goto buttonloop
    End         'end of program supposed never reached
    may be you'll have to modify a bit the " @ __config ......" line if you use PM as an assembler.

    Also correct " IF I >= 50 ..." to i.e. " IF I >= 55 " to take servo positionning time into account ... knowing 1 unit is 20 ms.

    Alain
    Last edited by Acetronics2; - 23rd December 2010 at 13:17.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts