;regulation thermique sous sol 07/07/25
;Gestion 2 moteurs et 4 FdC sur 20M2
;Tempsmax mouvement trappes 10s =>erreur FdC: reset par poussoir sur B.5
;TN=trappe Nord; TS=trappe Sud ;O=ouverte F=fermée
;Trappes en transit ;ni ouvert ni fermé => "T"
;Flag sur défaut FdC => arrêt jusqu'à reset
;Ajout hystérésis + moyenne sur 4 mesures
;Ajout temporisation entre comparaisons + affichage temps
;Ajout test FDC
#picaxe 20M2
setfreq M16
symbol LCD=B.0
symbol Potar=C.7
symbol DSext=C.1
symbol DSint=C.2
symbol FCFS = pinC.6 ;Fin course fermeture sud (0=fermé)
symbol FCOS = pinC.5 ;fin course ouverture sud (0=ouvert)
symbol FCFN = pinC.4
symbol FCON = pinC.3
symbol CTON = B.1 ;commande trappe ouverture nord
symbol CTFN = B.2 ;commande trappe fermeture nord
symbol CTOS = B.3
symbol CTFS = B.4
symbol pous=pinB.5 ;poussoir reset alarme
symbol flag=bit0
symbol Text=b1
symbol Tint=b2
symbol Cgn=b3
symbol hyster=b4
symbol Textmaj=b5
symbol Textmin=b6
symbol Tintmaj=b7
symbol Tintmin=b8
symbol cpt=b9 ;compteur
symbol TN=b10
symbol TS=b11
symbol pretime=w10
symbol Tmax=w11
symbol reste=w12
symbol cumul=w13
symbol baud=N2400_16
dirsC =%0
dirsB = %11111
pullup %111100000100000 ;pullup sur C.3 à C.6 et B.5
hyster=1 ;hystérésis +/- hyster
Tmax=180 ;0=pas de tempo
;*************************
pause 500 ;temps init LCD
serout LCD, baud,(254,1)
serout LCD, baud,(254,130,"int ext Cgn TN TS",254,192,"T")
serout LCD, baud,(254,212,"Trestant: ",#reste," " )
;scan FdC MST
gosub testFDC
TN="T" : TS="T"
if FCFS=0 then ;C.6
TS="F"
elseif FCOS=0 then ;C.5
TS="O"
endif
if FCFN=0 then ;C.4
TN="F"
elseif FCON=0 then ;C.3
TN="O"
endif
gosub lectemp ;1èrelecture pour initialisation
serout LCD, baud,(254,194,#Tint," ",254,198,#Text," ",254,203,#Cgn," ",254,207,TN,254,210,TS)
reste=Tmax-time
serout LCD, baud,(254,222,#reste," s " )
gosub compare ;pas de tempo à la MST
do ;boucle principale
time=0
do
if flag=1 then
do loop while pous=1 ;appui
do loop while pous=0 ;relachement pous
serout LCD, baud,(254,148," "); raz alarme
flag=0 ;raz flag
endif
gosub lectemp
if time<>pretime then ; 1 affichage/s
if Tmax>time then ;sinon => <0
reste=Tmax-time ;calcul reste
else reste=0
endif
serout LCD, baud,(254,194,#Tint," ",254,198,#Text," ",254,203,#Cgn," ",254,207,TN,254,210,TS)
serout LCD, baud,(254,222,#reste," s " )
pretime=time
endif
loop while reste>0
;on compare les tempés toutes les 600 s (10 mn)
gosub compare
loop
lectemp:
;gosub testFDC ; option test FDC
readadc potar, Cgn ;lecture consigne sur C.7
Cgn = 15 * Cgn /250 + 15 ; de 15 à 30 °C
cumul=0
for cpt=1 to 4 ;moyenne sur 4 mesures
readtemp Dsext,Text
pause 200
cumul= cumul+Text
next
Text=cumul/4
Textmaj=Text+hyster ;valeur majorée
if Text>hyster then
Textmin=Text-hyster ;valeur minorée
else
Textmin=0 ;on bloque à 0
endif
cumul=0
for cpt=1 to 4
readtemp DSint,Tint
pause 200
cumul= cumul+Tint
next
Tint=cumul/4
Tintmaj=Tint+hyster ;valeur majorée
if Tint>hyster then
Tintmin=Tint-hyster ;valeur minorée
else Tintmin=0
endif
return
testFDC:
if FCFS=0 and FCOS=0 then
serout LCD, baud,(254,148," DEFAUT FC SUD")
do loop while pous=1
do loop while pous=0
reset
endif
if FCFN=0 and FCON=0 then
serout LCD, baud,(254,148," DEFAUT FC NORD")
do loop while pous=1
do loop while pous=0
reset
endif
return
compare: ;avec hystérésis
if Tintmaj > Cgn and Textmin < Tint then ; ouverture trappe
gosub ouvre
elseif Tintmaj < Cgn and Textmin > Tint then
gosub ouvre
elseif Textmin > Cgn and Tintmin > Cgn then ;fermeture trappe
gosub ferme
elseif Tintmin < Cgn and Textmin <Tint then
gosub ferme
endif
return
ouvre: ;C.3
if FCON =1 then ;le fdc n'est pas en position ouverture (=0)
high CTON ;commande ouverture trappe nord (5V)
time=0
do
if FCFN=1 then ;le fdc n'est plus en position fermeture
TN="T"
serout LCD, baud,(254,207,TN) ;donc on est en transit
endif
loop while FCON=1 and time<10 ;FCON=C.3 => trappe nord ouverte
low CTON
if time>= 10 then
serout LCD, baud,(254,148," DEFAUT FCON")
flag=1 ;flag mémo erreur
else
TN="O"
serout LCD, baud,(254,207,TN)
endif
endif
if FCOS=1 then
high CTOS ;sortie ouverture à 1 (5V)
time=0
do
if FCFS=1 then
TS="T"
serout LCD, baud,(254,210,TS)
endif
loop while FCOS=1 and time<10 ;FCOS=C.5 => porte ouverte
low CTOS
if time>= 10 then
serout LCD, baud,(254,148," DEFAUT FCOS")
flag=1
else
TS="O"
serout LCD, baud,(254,210,TS)
endif
endif
return
ferme: ;C.1
if FCFN =1 then ;fermeture trappe nord
high CTFN ;commande fermeture trappe nord à 1 (5V)
time=0
do
if FCON=1 then
TN="T"
serout LCD, baud,(254,207,TN)
endif
loop while FCFN=1 and time<10 ;FCFN=C.4 => porte ouverte
low CTFN
if time>= 10 then
serout LCD, baud,(254,148," DEFAUT FCFN")
flag=1
else
TN="F"
serout LCD, baud,(254,207,TN)
endif
endif
if FCFS=1 then ;fermeture trappe sud
high CTFS ;commande fermeture trappe sud à 1 (5V)
time=0
do
if FCOS=1 then
TS="T"
serout LCD, baud,(254,210,TS)
endif
loop while FCFS=1 and time<10 ;FCFS = C.6
low CTFS
if time>= 10 then
serout LCD, baud,(254,148," DEFAUT FCFS")
flag=1
else
TS="F"
serout LCD, baud,(254,210,TS)
endif
endif
return