forked from TG9541/W1209
-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.fs
72 lines (61 loc) · 1.43 KB
/
control.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
\ W1209 temperature control functions
\ © 2017 TG9541, refer to https://github.com/TG9541/W1209/blob/master/LICENSE
\ For now: just a simple 2-point controller
#include STARTTEMP
0 CONSTANT OFF
-1 CONSTANT ON
TARGET
\ VARIABLE c.heat
VARIABLE c.cool
VARIABLE c.delay
: C.on ( -- n )
\ lower threshold [0.1ºC]
\ C.off EE.HYS @ -
EE.SET @
;
: C.off ( -- n )
\ upper threshold [0.1ºC]
C.on EE.HYS @ -
\ for cooling rather than heating need to reverse C.off and C.on
\ EE.SET @
;
: controller ( theta -- flag )
\ simple temperature control with hystesis & delay
\ c.heat @ IF
c.cool @ IF
\ ( theta ) C.off SWAP < IF
( theta ) C.off < IF
\ OFF c.heat !
OFF c.cool !
EE.DEL @ ( [10s] )
20 ( ticks [5ms] ) * c.delay !
THEN
ELSE
\ ( theta ) C.on < IF
( theta ) C.on SWAP < IF
c.delay @ IF
-1 c.delay +!
ELSE
\ ON c.heat !
ON c.cool !
THEN
THEN
THEN
\ c.heat @ \ return flag
c.cool @ \ return flag
;
: control ( theta -- theta )
DUP DEFAULT = NOT IF
DUP controller ( flag )
ELSE
0 ( flag ) \ sensor value undefined: control variable inactive
THEN
( flag ) OUT! \ switch relay
;
: init ( -- ) init \ chained init
\ OFF c.heat !
OFF c.cool !
\ ON c.cool !
0 c.delay !
;
ENDTEMP