Actuating Servos on a Schedule/Time Delay


Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262

    Question Actuating Servos on a Schedule/Time Delay

    I need to have servos (up to say 8) move from position 0 to (X) on a time delay, but I need to set a seperate time delay between each servo also,
    so say every 10 minutes I need to cycle all servos and I need each servo to wait say 20 seconds before returning to the 0 position and letting the next servo run, so on and so forth. only 1 servo can be out of the position 0 at a one time. right now I'm just working with 2 servos, but I want to use up to 8. Ive been working with the code below, i would like the display to show which servo is not in position 0, and how long before the servos are to run (in a countdown perhaps). My code is incorrect as it would fire up all servos at the same time. also if anyone sees other problems with code let me know.

    Code:
    DEFINE LCD_DREG PORTD   ' LCD Data bits on PORTD
    DEFINE LCD_DBIT 0       ' PORTD starting address
    DEFINE LCD_RSREG PORTD  ' LCD RS bit on PORTD
    DEFINE LCD_RSBIT 5      ' LCD RS bit address
    DEFINE LCD_EREG PORTD   ' LCD E bit on PORTD
    DEFINE LCD_EBIT 4       ' LCD E bit address
    DEFINE LCD_BITS 4       ' LCD in 4-bit mode
    DEFINE LCD_LINES 4      ' LCD has 4 rows
    DEFINE ADC_BITS 10 ' A/D number of bits
    DEFINE ADC_CLOCK 1 ' Use A/D internal RC clock
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us
    
    TRISA = 1 'PORTA is all input
    TRISD = 0 ' PORTD is output 'LCD
    TRISB = 0 ' PORTB is output
     
    LCDOUT $FE, 1 ' Clear LCD
    PAUSE 500 ' Wait 0.5sec for LCD to initialize
    
    Time Var Word : time = 0' Time Between Engaging
    Servo VAR word : Servo = 200 ' Servo Position Set when Engaged
    NumServos VAR byte : numservos = 2 ' # of Servos, Max 8
    Counter VAr word : Counter = 0' Time Counter
    X var word : x = 0 ' OnTime
    Y VAR WORD : y = 0 ' Servo Select
    
    AGAIN:
    ADCIN 0, time ' Read Channel 0 data
    time = (time / 121) + 60 ' 60-600 Seconds
    for Y = 1 to NumServos
    PULSOUT PORTB.0 [Y], 100 ' Send the Home position Pulse
    Next y
    PAUSE 20 ' Wait 20 ms
    goto Display 
    Counter = counter + 1
    if counter > time then counter = 0
    GOTO AGAIN ' Repeat
    
    RunServos:
    for X = 1 to 500 ' 20ms X 500 = 10 Seconds
    For Y = 1 to NumServos ' Select Servo
    PULSOUT PORTB.0[Y], 200 ' Send the Not HOME Pulse
    Next Y
    PAUSE 20 ' Wait 20 ms
    goto display
    next X
    Return
    
    Display:
    LCDOUT $FE, 2
    LCDOUT $FE, $80
    LCDOUT "Set Minutes = ", DEC3 time 
    LCDOUT $FE, $C0
    LCDOUT "RunTime = " , DEC Counter , "      "  
    return
    Last edited by wdmagic; - 14th March 2013 at 21:59.

Similar Threads

  1. Calculating time delay between two inputs?
    By grimmjow in forum General
    Replies: 11
    Last Post: - 18th October 2010, 14:52
  2. Need advice for creating nS time delay
    By sayzer in forum mel PIC BASIC Pro
    Replies: 28
    Last Post: - 12th December 2007, 07:34
  3. change in the delay in real time
    By manu123 in forum General
    Replies: 3
    Last Post: - 6th April 2007, 19:11
  4. Control unlimited servos at the same time
    By mrx23 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 19th September 2006, 14:14
  5. Linx RF -> HSERIN time delay / time critical app...
    By batee in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 15th October 2004, 15:04

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