'
PSU Output control Copyright Cyrob 2018 '
CP0086 Firmware
'
Release History '
24/02/2018 V1.0
Phildem
First blood '
29/05/2018 V1.1
Phildem
Final Adjust with hardware
'
At start up, output is off, no delay '
A single push on bt switch toggle the output on off '
A long push enter progMode '
In progMode, each push increment the second counter (up to 255) '
A long push leave progMode
'
IO abstraction symbol
In_Bt =
pinC.3 'Ctl Button activ Low symbol
Out_Piezzo
= C.4
'Sound Buzzer activ High symbol
Out_Relay
= C.2
'Output relay activ High symbol
Out_LedB =
C.0
'LedBlue activ Low symbol
Out_LedG =
C.1
'LedGreen activ Low
'
States symbol
kStateInit =
0
' Startup
Blue/Green Blink with snd symbol
kStateOff
=
1 ' Output
Off
Green led On symbol
kStateOn =
2
' Output
On
relay (Red led) On symbol
kStateCountDown =
3
' Countdow to
on
Green Pulse with Snd pulse symbol
kStateProg =
4
' Mode Program
Blue Led On symbol
kStateStop =
5
' Push to stop
Green led On
'
Misc Constant symbol
kTickVal
=
50 ' Value
of tick in mS symbol
kLongPush
=
20 '
NbTick for nong Push symbol
kTickPerSec =
20 '
NbTick by second
'Variables symbol
m_State =
b0 ' State
symbol
m_Loop =
b1 ' Loop
var symbol
m_NbTickOn =
b2 '
Number of Tick bt on symbol
m_Delay
=
b3 '
Number of seconds to goes on symbol
m_SecTick
=
b4 '
Second Tick counter symbol
m_CntDown
=
b5 '
Startup count down
'Startup
sequence for
m_Loop = 1 to 5
low Out_LedB
sound Out_Piezzo,(100,3)
high Out_LedB
low Out_LedG
sound Out_Piezzo,(150,3)
high Out_LedG next
m_Loop
;
Adjust relay vs state if
m_State=kStateOn then
high Out_Relay else
low Out_Relay endif
;
Adjust led vs state SELECT
m_State
CASE kStateOn
CASE kStateCountDown
high Out_LedB
high Out_LedG
CASE kStateProg
low Out_LedB
high Out_LedG
ELSE
high Out_LedB
low Out_LedG ENDSELECT
Pause
kTickVal ;
We do something only every Tick
;
Look If bt Down if
In_Bt=0 then
if m_State=kStateOn then ; Stop asap
m_State=kStateStop
low Out_Relay
endif
inc m_NbTickOn
if m_NbTickOn=kLongPush then
if m_State=kStateProg
then ; Leave ProgMode
sound
Out_Piezzo,(120,60,60,40)
m_State=kStateOff
else
; Enter
ProgMode
sound
Out_Piezzo,(60,40,120,60)
m_Delay=0
m_State=kStateProg
endif
endif
if m_NbTickOn>kLongPush then
m_NbTickOn=kLongPush ; Wait user relase
bt
endif
elseif
m_NbTickOn<>0 then ;Bt
return up
if m_NbTickOn<kLongPush then ;It was a short push
SELECT m_State
CASE
kStateCountDown,kStateStop
m_State=kStateOff
sound Out_Piezzo,(100,10,0,10,80,40)
CASE
kStateProg
inc m_Delay
sound Out_Piezzo,(120,40)
CASE
kStateOff
m_SecTick=0
m_State=kStateCountDown
m_CntDown=m_Delay
ENDSELECT
endif
m_NbTickOn=0
elseif
m_State=kStateCountDown then ;need start
if m_CntDown=0 then
m_State=kStateOn
sound
Out_Piezzo,(100,10,0,10,100,10,0,10,120,10)
else
inc m_SecTick
if m_SecTick=kTickPerSec then
low
Out_LedG
m_SecTick=0
Dec
m_CntDown
SELECT
m_CntDown
CASE 1
sound Out_Piezzo,(110,5)
high Out_LedG
sound Out_Piezzo,(0,5)
low Out_LedG
sound Out_Piezzo,(110,5)
high Out_LedG
sound Out_Piezzo,(0,5)
low Out_LedG
sound Out_Piezzo,(110,5)
high Out_LedG
sound Out_Piezzo,(0,5)
low Out_LedG
CASE 2
sound Out_Piezzo,(90,8,0,8,90,8)
CASE 3
sound Out_Piezzo,(80,8,0,8,80,8,0,8,80,8)
CASE 4
sound
Out_Piezzo,(70,8,0,8,70,8,0,8,70,8,0,8,70,8)
ELSE
sound Out_Piezzo,(60,10)
ENDSELECT
high
Out_LedG