-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathburn_control.h
216 lines (176 loc) · 8.84 KB
/
burn_control.h
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#ifndef _BURN_CONTROL_H_INCLUDED_
#define _BURN_CONTROL_H_INCLUDED_
typedef uint8_t TSTATE;
#define STATE_P0 0 //podtrzymanie
#define STATE_P1 1 //grzanie z mocą minimalną
#define STATE_P2 2 //grzanie z mocą nominalną
#define STATE_FIRESTART 3 //rozpalanie
#define STATE_ALARM 4 // alarm - cos się stało, piec zatrzymany albo włączone zabezpieczenie
#define STATE_REDUCE1 5 //tryb przejścia na niższy stan P2 => P1 => P0. zadaniem tego trybu jest dopalenie pozostałego węgla. W tym celu musimy wiedzieć z jakiego stanu wyszlismy do reduce
#define STATE_REDUCE2 6 //tryb przejścia na niższy stan P1 => P0
#define STATE_STOP 7 //tryb ręczny - zatrzymany piec - sterowanie automatyczne powinno zaprzestać działalności
#define STATE_OFF 8 //wygaszony
#define STATE_UNDEFINED 255
#define MAX_POWER_STATES 4 //max liczba konfiguracji dla mocy. 1 - tylko podtrzymanie, 2 - podtrzymanie i praca, 3 - podtrzymanie i 2 moce pracy, 4 - z rozpalaniem
#define MAX_PROFILES 2
typedef uint8_t CWSTATE;
#define CWSTATE_OK 1
#define CWSTATE_HEAT 2
#define NEED_HEAT_NONE 0
#define NEED_HEAT_CO 1
#define NEED_HEAT_CWU 2
#define COOLOFF_NONE 0
#define COOLOFF_OVERHEAT 1 //first mode - run cooloff only when above set temp + delta
#define COOLOFF_LOWER 2 //second mode- run cooloff while above the set temp
#define FIRESTART_MODE_DISABLED 0
#define FIRESTART_MODE_JUSTSTOP 1 //will switch off when done heating, but will not auto start
#define FIRESTART_MODE_STARTSTOP 2
//for config AirControlMode
#define AIRCONTROL_NONE 0
#define AIRCONTROL_CORRECT1 1
#define AIRCONTROL_CORRECT2 2
#define AIRCONTROL_HITMISS0 3
#define AIRCONTROL_HITMISS3 6
#define EXHAUST_TEMP_DELTA_BELOW_CO 2.0 //
typedef uint8_t HEATNEED;
//konfiguracja jednego z poziomów mocy
typedef struct BurnParams {
uint16_t CycleSec; //total cycle, including the fueling time, in seconds. podtrzymanie: okres przedmuchu. podawanie wegla co 1, 2, 3 przedmuchy
//czas podawania wegla, * 10 (50 = 5 sekund)
uint16_t FuelSecT10;
//moc nadmuchu
uint8_t BlowerPower; //0 .. 255 (100%)
uint8_t BlowerCycle; //cykl dmuchawy dla zasilania grupowego. 0 gdy fazowe.
uint8_t AirFlow; //air flow value, if zero then not used. If specified then BlowerPower is the starting power, then adjusted to AirFlow
} TBurnParams;
typedef struct DeviceConfiguration {
uint16_t Magic; //should always be 0x6502
uint8_t SettingsBank;
uint8_t DallasAddress[8][8]; //dallas sensor addresses. if zero - sensor not present
uint8_t DefaultBlowerCycle;
uint8_t AirFlowCoeff; //normalization coefficient for air flow voltage. 0 .. 255, where 255=1024 - maximum input value
} TDeviceConfiguration;
//zestaw ustawień pieca (aktualna konfiguracja). Nie zawiera bieżących wartości.
typedef struct ControlConfiguration {
uint16_t Magic; //should always be 0x6502
uint8_t TCO; //co temp
uint8_t TCWU; //cwu temp
uint8_t TCWU2; //cwu2 temp
uint8_t TMinPomp; //minimum pump run temp.
uint8_t THistCwu; //histereza cwu
uint8_t THistCO; //histereza co
uint8_t TDeltaCO; //delta co - temp powyzej zadanej przy ktorej przejdzie w podtrzymanie
uint8_t TDeltaCWU; //delta cwu - temp powyżej bojlera do ktorej rozgrzewamy piec
uint8_t P0BlowerTime; //czas pracy dmuchawy w podtrzymaniu
uint8_t P0FuelFreq; //podawanie wegla co x cykli przedmuchu
bool _delHomeThermostat;
bool SummerMode; //tryb letni
TBurnParams BurnConfigs[MAX_POWER_STATES]; //first one [0] is the podtrzymanie
uint8_t FeederTempLimit;
uint8_t NoHeatAlarmCycles; //time needed to deterimine if we have the fire
uint8_t EnableThermostat; //0 disabled, 1 - NO, 2 - NC
uint8_t CooloffTimeM10; //minutes * 10
uint16_t CooloffPauseM10; //minutes * 10
uint16_t FuelGrH; //fuel grams per hour of feeder work. 10 kg=10000.
uint16_t FuelHeatValueMJ10; //fuel heat in MJ, * 10 (100 = 10MJ)
uint8_t CooloffMode; //0 - none
int8_t FuelCorrection; //0 - none, fuel feed correction %. value=20 => make feed time longer by 20%, value = -20 - make it shorter by 20%
uint8_t CircCycleMin; //60, 30, 15, 10, 6
uint8_t CircWorkTimeS; //circ pump working time per cycle, sec*10 (10 = 100 sec)
uint8_t ReductionP2ExtraTime; //in %, how much % of the P2 cycle time to add for reduction (0 = just the P2 cycle, 10 = P2 cycle + 10%)
uint8_t BlowerMax; //Blower max value that will be our 100
uint8_t FireStartMode; //0 - none, 1-auto off, 2 - auto on and off
uint8_t NumFireStartCycles; //automatic firestart timeout in minutes * 10 (250 = 25 minutes). After that time we conclude 'failed to start fire' if not detected earlier
uint8_t HeaterMaxRunTimeS; //maximum run time of the heater. If exceeded, heater will be turned off for the duration of one cycle (of STATE_FIRESTART)
uint8_t FireDetExhDt10; //rate of exhaust temp increase to confirm ignition - divide this v by 10
uint8_t FireDetExhIncrD10; //how much has exh temp to increase
uint8_t FireDetCOIncr10; //how much has CO temp to increase
uint8_t P0CyclesBeforeStandby;
uint8_t AirControlMode; //0 - just blower %, 1 - flow meter (both % and then flow for adjustment) 2 - just the flow value is used
} TControlConfiguration;
#define CFG_SLOT_SIZE 140 //size of single config settings struct (with some extra space for future) - utility.cpp
#define DEV_CFG_SLOT_SIZE 80// size of device config record in eeprom - utility.cpp
//bieżąca konfiguracja pieca
extern TControlConfiguration g_CurrentConfig;
extern TDeviceConfiguration g_DeviceConfig;
typedef struct BurnTransition {
TSTATE From;
TSTATE To;
bool (*fCondition)();
void (*fAction)(int); //action executed on transition, before state change. int param = transition index in the table
} TBurnTransition;
typedef struct BurnStateConfig {
TSTATE State;
char Code;
void (*fInitialize)(TSTATE s);
void (*fLoop)();
} TBurnStateConfig;
//initialize the burning automatic algorithm
void initializeBurningLoop();
//periodically run burn control task to handle automatic burning alg.
void burnControlTask();
///functions additional to main boiler control loop
// f.ex. circulation pump
void circulationControlTask();
//wlacz/wylacz tryb automatyczny
void setManualControlMode(bool b);
//wlacz/wylacz tryb reczny z ustawieniem stanu
void setManualControlState(TSTATE t);
//
TSTATE getManualControlState();
//check if heating is needed anywhere (for home or for cwu). 0 - no, 1 - co needed, 2 - cwu needed
HEATNEED needHeatingNow();
///sets alarm state and shows alarm message
void setAlarm(const char* txt);
void forceState(TSTATE st);
void processSensorValues();
int8_t calculateBlowerPowerAdjustment(uint8_t desiredFlow, uint8_t measuredFlow, uint8_t currentBlowerPower);
int firestartIsBurningCheck();
void setBlowerPower(uint8_t power);
///set blower power 0..255 (255 = 100%)
void setBlowerPower(uint8_t power, uint8_t powerCycle);
///get blower power 0..255 (255 = 100%)
uint8_t getCurrentBlowerPower();
extern const TBurnTransition BURN_TRANSITIONS[];
extern const TBurnStateConfig BURN_STATES[];
extern const uint8_t N_BURN_TRANSITIONS;
extern const uint8_t N_BURN_STATES;
extern TSTATE g_BurnState;
extern CWSTATE g_CWState;
extern HEATNEED g_needHeat; //status variable: we need heating now (=cwu or co).
//czas wejscia w bieżący BURN stan, ms
extern unsigned long g_CurStateStart;
extern float g_CurStateStartTempCO; //temp pieca w momencie wejscia w bież. stan.
extern unsigned long g_CurBurnCycleStart; //timestamp, w ms, w ktorym rozpoczelismy akt. cykl palenia
extern bool g_overrideBurning;
//
// Globalne zmienne reprezentujące bieżący stan pieca, temperatury, dmuchawy itp
// po to żeby np moduł UI mógł sobie je wyswietlać.
//
extern float g_TargetTemp; //aktualnie zadana temperatura pieca (która może być wyższa od temp. zadanej w konfiguracji bo np grzejemy CWU)
extern float g_TempCO;
extern float g_TempCWU;
extern float g_TempPowrot; //akt. temp. powrotu
extern float g_TempSpaliny; //akt. temp. spalin
extern float g_TempFeeder;
extern float g_TempBurner; //temp palnika
extern float g_dT60; //delta temp in 1 minute
extern float g_dTl3; //delta temp in last 3 changes
extern float g_dTExh; //delta exhaust temp
extern float g_dTExhLong;
extern float g_InitialTempCO;
extern float g_InitialTempExh;
extern float g_AirFlow;
extern volatile uint8_t g_AirFlowNormal; //normalized airflow range 0..255 (or make it 0..100?)
extern uint8_t g_ReductionsToP0; //reductions P1 -> P0 or P2 -> P0 which we dont ave
extern uint8_t g_ReductionsToP1; //reductions P2 -> P1
extern uint16_t g_burnCycleNum; //nr cyklu spalania w biez stanie
extern uint8_t g_TargetFlow;
extern TSTATE g_BurnState; //aktualny stan grzania
extern bool g_HomeThermostatOn; //true - termostat pokojowy kazał zaprzestać grzania
extern unsigned long g_P1Time; //accumulated P1 time
extern unsigned long g_P2Time; //accumulated P2 time
extern unsigned long g_P0Time; //accumulated P0 time
extern float g_TempZewn; //aktualna temp. zewn
extern char* g_Alarm;
#endif