-
Notifications
You must be signed in to change notification settings - Fork 12
/
control.fs
60 lines (49 loc) · 1.11 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
\ 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.delay
: C.off ( -- n )
\ upper threshold [0.1ºC]
EE.SET @
;
: C.on ( -- n )
\ lower threshold [0.1ºC]
C.off EE.HYS @ -
;
: controller ( theta -- flag )
\ simple temperature control with hystesis & delay
c.heat @ IF
( theta ) C.off SWAP < IF
OFF c.heat !
EE.DEL @ ( [10s] )
20 ( ticks [5ms] ) * c.delay !
THEN
ELSE
( theta ) C.on < IF
c.delay @ IF
-1 c.delay +!
ELSE
ON c.heat !
THEN
THEN
THEN
c.heat @ \ 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 !
0 c.delay !
;
ENDTEMP