I have written the piece of code below and it works at the endpoints of 0.25 to 25 sec for the on time and 30 to 60 sec cycle time. The problem is that it does not work for numbers in between. I think my functions are not working correctly but i dont know. The other problem i see is that if You do the math to figure out the loop times they come out about 4 seconds longer than what is being seen on the hardware. This seems impossible to me, if anything they should be longer not shorter because i was not taking into account the adc reads? Anybody know of an explanation of whats going on here?
MAIN:
GOSUB ON_RUN
pause 10
GOTO MAIN
ON_TIME:
PAUSE 250 ' low end pause time (0.25 sec)
for i = 0 to ON_counter step 1 ' high end pause loop time (25 sec)
GOSUB READ_A_D_AN2
GOSUB READ_A_D_AN3
PAUSE 27
nEXT I
RETURN
OFF_TIME_RUN:
' PAUSE 5000
for K = 0 to OFF_TIME step 1 'total pause loop time
GOSUB READ_A_D_AN3
GOSUB READ_A_D_AN2
GOSUB OFF_TIME_CALC
PAUSE 33
nEXT K
RETURN
ON_RUN:
LOAD_OUT = 1
GOSUB ON_TIME
GOTO OFF_RUN
OFF_RUN:
LOAD_OUT = 0
GOSUB OFF_TIME_CALC
GOSUB OFF_TIME_RUN
GOTO INITIALIZE
OFF_TIME_CALC:
OFF_TIME = (CYCLE_COUNTER - ON_COUNTER) '+ 100
IF OFF_TIME < 120 THEN OFF_TIME = OFF_TIME + 150
if OFF_TIME = 1024 THEN OFF_TIME = OFF_TIME + 180
' if OFF_TIME > 2000 THEN OFF_TIME = OFF_TIME - 50
RETURN
READ_A_D_AN2: 'used for ON Time Delay
PAUSEUS 50 ' wait 50 microsec
ADCIN 2, AD_AN2_VALUE ' read channel 2 to AD_AN0_VALUE
ON_COUNTER = AD_AN2_VALUE ' set counter to AD value
RETURN
READ_A_D_AN3: 'used for Cycle Time Delay
PAUSEUS 50 ' wait 50 microsec
ADCIN 3, AD_AN3_VALUE ' read channel 3 to AD_AN3_VALUE
CYCLE_COUNTER = AD_AN3_VALUE + 1024 ' set counter to AD value + 1024
RETURN
I appreciate any help that anyone may give. Thank you again.
Bookmarks