rem Counter_Driver.bas. Driver for electro-mechanical counter driver. rem John Saunders 6/16/2009 #picaxe 08M #COM 1 'Input ports symbol Mode = INPUT3 'If 1 then contact closure input, else voltage input symbol Sense = 4 'Sense input, either contact clocure or voltage symbol LED = 2 'Indicates too high a voltage input and bleeds the clamp current 'Output ports symbol Mosfet = 1 'Mosfet gate 'Constants symbol Upper = 169 '3V Uses hysteresis symbol Lower = 85 '1.5V symbol Overrange = 254 '5V 'Variables symbol Pulse = Bit0 symbol Signal = B1 init: LOW LED main: READADC Sense, Signal IF Mode = 0 THEN 'Voltage Input IF Signal > Overrange THEN HIGH LED ELSE LOW LED ENDIF IF Signal > Upper THEN LET Pulse = 1 ENDIF ELSE 'Contact Closure input IF Signal < Lower THEN LET Pulse = 1 ENDIF ENDIF IF Pulse = 1 THEN HIGH Mosfet 'Activate Counter PAUSE 20 'Minimum Pulse length at 17V is 20 ms LOW Mosfet LET Pulse = 0 PAUSE 80 'Physical rated count rate is 10 cps, don't try to go faster IF Mode = 0 THEN 'Wait to prevent multiple counts DO READADC Sense, Signal IF Signal > Overrange THEN HIGH LED ELSE LOW LED ENDIF LOOP WHILE Signal > Lower ELSE DO READADC Sense, Signal LOOP WHILE Signal < Upper ENDIF ENDIF goto main end