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
Bookmarks