-
Notifications
You must be signed in to change notification settings - Fork 40
/
misc.cpp
92 lines (88 loc) · 5.49 KB
/
misc.cpp
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
#include "misc.h"
#if defined setHeater
#define WAIT { while (ESP.getCycleCount()-start < wait) optimistic_yield(1); wait += F_CPU/19200; }
#endif
float EEPROM_float_read(int addr) {
byte x[4];
for (byte i = 0; i < 4; i++) x[i] = EEPROM.read(i + addr);
float *y = (float *)&x;
return y[0];
}
void EEPROM_float_write(int addr, float val) {
byte *x = (byte *)&val;
for (byte i = 0; i < 4; i++) EEPROM.write(i + addr, x[i]);
}
void stop_Err() {
csOff(PWM_CH6); // выключить дополнительный ТЭН на разгон
power.heaterStatus = 0; // выключили ТЭН
power.heaterPower = 0; // установили мощность на ТЭН 0 %
timeAllertInterval = millis() + 10000; // установим счетчик времени для зв.сигнала
processMode.timeStep = 0;
timePauseOff = 60000 * 2 + millis();
if (processMode.allow == 1) processMode.step = 4; // дистилляция
else if (processMode.allow == 2) { // ректификация
if (processMode.number == 0) processMode.step = 4;
else processMode.step = 7;
if (processMode.number == 1 || processMode.number == 2) setPWM(PWM_CH5, 0, 10); // Закрыли отбор по пару
}
}
void check_Err() {
// датчики безопасности в каналах АЦП
if ((pwmOut[3].member == 0 || processMode.allow == 1) && adcIn[0].member == 1 && adcIn[0].allert == true && alertLevelEnable == true) settingAlarm = true;
else if (adcIn[1].member == 1 && adcIn[1].allert == true) { settingAlarm = true; errA = true; numCrashStop = 1; }
else if (adcIn[2].member == 1 && adcIn[2].allert == true) { settingAlarm = true; errA = true; numCrashStop = 2; }
else if (adcIn[3].member == 1 && adcIn[3].allert == true) { settingAlarm = true; errA = true; numCrashStop = 3; }
if (!errA) timePauseErrA = millis() + 10000; // 10 секунд пауза до защиты
// датчики безопасности по температурным датчикам кроме Т куба и Т царги кроме бражной колонны
#ifdef WColumn_water
if (temperatureSensor[DS_Out].cutoff == 1 && temperatureSensor[DS_Out].member == 1 && temperatureSensor[DS_Out].allertValue > 0 && temperatureSensor[DS_Out].data >= temperatureSensor[DS_Out].allertValue && processMode.number != 5) {
settingAlarm = true; errT = true; numCrashStop = DS_Out;
}
else if (temperatureSensor[DS_Def].cutoff == 1 && temperatureSensor[DS_Def].member == 1 && temperatureSensor[DS_Def].allertValue > 0 && temperatureSensor[DS_Def].data >= temperatureSensor[DS_Def].allertValue && processMode.number != 5) {
settingAlarm = true; errT = true; numCrashStop = DS_Def;
}
#elif defined WColumn_power
if (temperatureSensor[DS_Out].cutoff == 1 && temperatureSensor[DS_Out].member == 1 && temperatureSensor[DS_Out].allertValue > 0 && temperatureSensor[DS_Out].data >= temperatureSensor[DS_Out].allertValue && processMode.number != 5) {
settingAlarm = true; errT = true; numCrashStop = DS_Out;
}
else if (temperatureSensor[DS_Def].cutoff == 1 && temperatureSensor[DS_Def].member == 1 && temperatureSensor[DS_Def].allertValue > 0 && temperatureSensor[DS_Def].data >= temperatureSensor[DS_Def].allertValue && processMode.number != 5) {
settingAlarm = true; errT = true; numCrashStop = DS_Def;
}
#else
if (temperatureSensor[DS_Out].cutoff == 1 && temperatureSensor[DS_Out].member == 1 && temperatureSensor[DS_Out].allertValue > 0 && temperatureSensor[DS_Out].data >= temperatureSensor[DS_Out].allertValue) {
settingAlarm = true; errT = true; numCrashStop = DS_Out;
}
else if (temperatureSensor[DS_Def].cutoff == 1 && temperatureSensor[DS_Def].member == 1 && temperatureSensor[DS_Def].allertValue > 0 && temperatureSensor[DS_Def].data >= temperatureSensor[DS_Def].allertValue) {
settingAlarm = true; errT = true; numCrashStop = DS_Def;
}
#endif
else if (temperatureSensor[DS_Res1].cutoff == 1 && temperatureSensor[DS_Res1].member == 1 && temperatureSensor[DS_Res1].allertValue > 0 && temperatureSensor[DS_Res1].data >= temperatureSensor[DS_Res1].allertValue) {
settingAlarm = true; errT = true; numCrashStop = DS_Res1;
}
else if (temperatureSensor[DS_Res2].cutoff == 1 && temperatureSensor[DS_Res2].member == 1 && temperatureSensor[DS_Res2].allertValue > 0 && temperatureSensor[DS_Res2].data >= temperatureSensor[DS_Res2].allertValue) {
settingAlarm = true; errT = true; numCrashStop = DS_Res2;
}
else if (temperatureSensor[DS_Res3].cutoff == 1 && temperatureSensor[DS_Res3].member == 1 && temperatureSensor[DS_Res3].allertValue > 0 && temperatureSensor[DS_Res3].data >= temperatureSensor[DS_Res3].allertValue) {
settingAlarm = true; errT = true; numCrashStop = DS_Res3;
}
else if (temperatureSensor[DS_Res4].cutoff == 1 && temperatureSensor[DS_Res4].member == 1 && temperatureSensor[DS_Res4].allertValue > 0 && temperatureSensor[DS_Res4].data >= temperatureSensor[DS_Res4].allertValue) {
settingAlarm = true; errT = true; numCrashStop = DS_Res4;
}
if (!errT) timePauseErrT = millis() + 10000; // 10 секунд пауза до защиты
}
// Выключение повышенного напряжения на клапана
void stepApLoop() {
if (CH_all == true) {
if (timeSetHighVoltage < millis()) {
if (pwmOut[8].invert == false) pwm.setPWM(PWM_CH9, 4096, 0);
else pwm.setPWM(PWM_CH9, 0, 4096);
CH_all = false;
}
}
}
void setUserPWM(uint8_t pr) {
uint16_t calc = pr * 40.95;
if (pr == 0) pwm.setPWM(PWM_CH7, 4096, 0); // off
else if (pr >= 100) pwm.setPWM(PWM_CH7, 0, 4096);
else pwm.setPWM(PWM_CH7, 0, calc);
}