'Created 11/10/2011 Richard Stallard richardestallard@gmail.com 'Rev 0.1 11/10/2011 - auxiliary station run time based on DIP switch setting in minutes. 'Rev 1.0 11/10/2011 - converted to measure station run time and adjust in proportion. 'Rev 1.1 12/10/2011 - made timing more precise for auxiliary valve - caluclated to 1 sec. 'Rev 1.2 13/1-/2011 - added symbol for Relay = output 0 symbol DIP_SW = b0 symbol ELAPSED_MIN = b1 'Zeroed at Start symbol PREV_MIN = b2 'Stored in NVRAM location 0. symbol RELAY_SIM = b3 'Provides visual indication of relay status for debugging symbol INT_CALC = w4 'intermediate calculation for proportional run time symbol RUN_TIME_SEC = w5 'calulcated run time in seconds symbol RELAY = 0 'Output 0 (Pin 7) symbol MILLISEC = 1000 'CAN REDUCE ALL TIMES BY FACTOR OF 10 FOR DEBUG symbol DLY_5SEC = 5000 symbol DLY_25SEC = 25000 symbol DLY_1MIN = 60000 'Checklist for Debug => Production '1. Comment out debug statements (3 places) '2. Add "0" to time constants if shortened for debug (4 places) '3. Comment out hardcoded DIP switch setting '4. Uncomment relay output commands if commented out to avoid interaction with programming connection (3 places) main: dirs = %00000001 ; switch pin 0 only to output pause DLY_5SEC ‘ wait 5 seconds ELAPSED_MIN = 0 'clear elapsed time counter DIP_SW = pins / 2 'read DIP switch to load timer percentage ' DIP_SW = 5 'HARDCODED FOR DEBUG read 0, PREV_MIN 'previous elapsed time from NV RAM if PREV_MIN = 0 then PREV_MIN = 10 'assuming nominal value for first startup so valve runs for short time at least. endif INT_CALC = PREV_MIN * DIP_SW *60 'e.g. 10 min x 5 x 60 = 3000 RUN_TIME_SEC = INT_CALC / 16 ' debug pause DLY_25SEC 'initial delay to allow pressure to build, and synchronise "heatbeat" mid-minute if RUN_TIME_SEC >= 10 then high RELAY 'activate relay output - but only if on for more than 10 sec. RELAY_SIM = 255 'use variable as indicator of relay status when debugging endif ' debug main2:INC ELAPSED_MIN ;increment elapsed time counter if ELAPSED_MIN >= 5 and ELAPSED_MIN <= 60 then write 0, ELAPSED_MIN ;write current elapsed time into NC RAM, but ignore times under 5 min as probably sprinkler testing endif ;also ignore elasped times more than 1 hour to avoid overflow of INT-CALC next time (abs. max = 72 min). ' debug if RUN_TIME_SEC >= 60 then RUN_TIME_SEC = RUN_TIME_SEC -60 pause DLY_1MIN elseif RUN_TIME_SEC > 0 then RUN_TIME_SEC = RUN_TIME_SEC * MILLISEC pause RUN_TIME_SEC low RELAY 'deactivate relay ouput RELAY_SIM = 0 'use variable as indicator of relay status when debugging RUN_TIME_SEC = DLY_1MIN - RUN_TIME_SEC pause RUN_TIME_SEC 'pause for remainder of minute to maintain heatbeat. RUN_TIME_SEC = 0 'zero remaining run time else pause DLY_1MIN 'continue to maintain heartbeat even after local valve switched off low RELAY 'deactivate relay ouput RELAY_SIM = 0 'use variable as indicator of relay status when debugging endif goto main2