; 18m2 Clock Pendulum Energiser. 25ms neg going pulse every 500ms from pendulum sensor at bottom of swing. Swing controlled by reading pulse and comparing with pot setting
; to switch coil on/off at bottom of swing as appropriate.
main:
let dirsB = 0
let dirsC = 8
serout C.3, n2400, ( 254,1)
waiting_for_pulse:
if pinB.1 = 0 then ' Looped waiting for neg going 25ms pulse.
goto energise_coil ' Pulse arrives at correct time from pendulum sensor, bottom of swing.
end if
goto waiting_for_pulse
energise_coil:
pulsin B.1, 0, w1 ' Read pulse length
w1 = w1 /10 max 999 ' 10us resolution
high B.0
pause 50 ' Coil energised pushing pendulum for 50ms
low B.0
readadc B.3,b0 ' Read adc B.3 into b0 from pot on leg 9
bintoascii b0, b22, b23 , b24
serout C.3, N2400, (254, 128,"",b22,b23,".",b24," set time ") ' Display setting on pot from B.3 and pulsin
bintoascii w1 ,b22, b23 , b24
serout C.3, N2400, (254, 192,"",b22,b23,".",b24," input pulse ")
pulse_stopped:
if w1 > b0 then 'Compare input pulse length with b0 if greater back to waiting for pulse to repeat energise coil sequence. If pulse less loop until greater.
goto waiting_for_pulse:
end if
readadc B.3, b0 ' Read adc B.3 into b0 from pot on leg 9
pulsin B.1, 0, w1 ' Read pulse length
w1 = w1 / 10 max 999 ' 10us resolution
bintoascii b0, b22, b23, b24
serout C.3, N2400, (254, 128,"",b22,b23,".",b24, " set time ") ' Display setting on pot from B.3 and pulsin
bintoascii w1, b22, b23, b24
serout C.3, N2400, (254, 192,"",b22,b23,".",b24, " input pulse ")
goto pulse_stopped ' Looping until pulse becomes greater than setting b0. Then back to waiting for pulse to repeat sequence.