Thu, 06 Oct 2022 14:17:05 +0200
Version 0.3.22. Fixed adding Tetra Hop, it is now not added to the recipe because this hop is not added on brewday.
0 | 1 | /** |
2 | * @file task_driver.c | |
3 | * @brief BrewBoard relays driver. Control the hardware outputs with the | |
4 | * Solid State relays for the Mash/Boil kettle (MLT, the Hot | |
5 | * Liquer Tank (HLT) and the pump. The MLT has a PID controller | |
6 | * during mashing, and a simple bang on/off control during the | |
7 | * boil. | |
8 | * The HLT output can be off, bang on/off, or just on if the MLT | |
9 | * is off, depending on the configuration. | |
10 | * Use SSR modules that switch during zero crossing of the mains | |
11 | * power, so that when one is turned on and on the same time the | |
12 | * other is turned off, they won't be active at the same time. | |
13 | */ | |
14 | ||
15 | #include "config.h" | |
16 | ||
17 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
18 | #define SSR_MLT CONFIG_SSR_MLT_GPIO ///< GPIO SSR MLT pin |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
19 | #define SSR_HLT CONFIG_SSR_HLT_GPIO ///< GPIO SSR HLT pin |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
20 | #define SSR_PUMP CONFIG_SSR_PUMP_GPIO ///< GPIO Pump relay pin |
101
1bc6e9263ada
Fixed HendiControl interface connecter to match the board input. Tested the new circuit.
Michiel Broek <mbroek@mbse.eu>
parents:
88
diff
changeset
|
21 | #define PWM_MLT CONFIG_PWM_MLT_GPIO ///< GPIO PWM MLT pin |
0 | 22 | |
116
bafc2d6a0790
Fixed Hendi ON switch and now the switch moment is in a #define HENDI_SWITCH. Currently set at 6. Fixed the web page when going to boil, two buttons were missing. Changed the PWM log line, added information about the ON switch and current temperature.
Michiel Broek <mbroek@mbse.eu>
parents:
113
diff
changeset
|
23 | #define HENDI_SWITCH 6 ///< Hendi power on/off at % |
0 | 24 | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
25 | bool outEnable = false; ///< Enable outputs flag |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
26 | DRIVER_State * driver_state; ///< Driver state |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
27 | SemaphoreHandle_t xSemaphoreDriver = NULL; ///< Driver state lock |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
28 | int MLT_pin = 0; ///< MLT state |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
29 | int HLT_pin = 0; ///< HLT state |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
30 | int Pump_pin = 0; ///< Pump state |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
31 | double Input = 0; ///< PID input value |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
32 | double Output = 0; ///< PID output value |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
33 | double Setpoint = 0; ///< PID setpoint value |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
34 | int MLT_Mode = MLT_MODE_NONE; ///< MLT mode flag |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
35 | double HLT_Input = 0; ///< HLT input value |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
36 | double HLT_Setpoint = 0; ///< HLT setpoint values |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
37 | int HLT_Output = 0; ///< HLT output value |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
38 | int HLT_Mode = HLT_MODE_NONE; ///< HLT mode flag |
87
47253f294a9f
SDK settings to reduce bin size. Some log messages to debug level. Added KWH usage registration. Added equipment power usage for HLT and MLT. Equipment database upgraded to version 2, expandable. Fixed some screen errors during temperature mash steps.
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
39 | TickType_t MLT_time, HLT_time; |
47253f294a9f
SDK settings to reduce bin size. Some log messages to debug level. Added KWH usage registration. Added equipment power usage for HLT and MLT. Equipment database upgraded to version 2, expandable. Fixed some screen errors during temperature mash steps.
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
40 | |
47253f294a9f
SDK settings to reduce bin size. Some log messages to debug level. Added KWH usage registration. Added equipment power usage for HLT and MLT. Equipment database upgraded to version 2, expandable. Fixed some screen errors during temperature mash steps.
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
41 | static const char *MLTTypes[] = { "None", "Bang", "PID", "Off", "Ext" }; |
47253f294a9f
SDK settings to reduce bin size. Some log messages to debug level. Added KWH usage registration. Added equipment power usage for HLT and MLT. Equipment database upgraded to version 2, expandable. Fixed some screen errors during temperature mash steps.
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
42 | static const char *HLTTypes[] = { "None", "Bang", "Off", "On" }; |
0 | 43 | |
44 | static const char *TAG = "task_driver"; | |
45 | ||
87
47253f294a9f
SDK settings to reduce bin size. Some log messages to debug level. Added KWH usage registration. Added equipment power usage for HLT and MLT. Equipment database upgraded to version 2, expandable. Fixed some screen errors during temperature mash steps.
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
46 | extern SemaphoreHandle_t xSemaphoreDS18B20; |
47253f294a9f
SDK settings to reduce bin size. Some log messages to debug level. Added KWH usage registration. Added equipment power usage for HLT and MLT. Equipment database upgraded to version 2, expandable. Fixed some screen errors during temperature mash steps.
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
47 | extern DS18B20_State *ds18b20_state; |
47253f294a9f
SDK settings to reduce bin size. Some log messages to debug level. Added KWH usage registration. Added equipment power usage for HLT and MLT. Equipment database upgraded to version 2, expandable. Fixed some screen errors during temperature mash steps.
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
48 | extern unsigned long lastTime; |
0 | 49 | |
50 | ||
51 | /** | |
52 | * @brief Turn the MLT SSR on or off. | |
53 | */ | |
54 | void MLT(int onoff); | |
55 | ||
56 | /** | |
57 | * @brief Turn the HLT SSR on or off. | |
58 | */ | |
59 | void HLT(int onoff); | |
60 | ||
61 | /** | |
62 | * @brief Turn the Pump on or off. | |
63 | */ | |
64 | void Pump(int onoff); | |
65 | ||
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
66 | /** |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
67 | * @brief Calculate and set PWM value. |
103
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
68 | * @param percent The power percentage, 0..100 |
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
69 | */ |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
70 | void MLT_PWM(int percent); |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
71 | |
0 | 72 | |
73 | ||
74 | void MLT(int onoff) { | |
75 | ||
76 | if (onoff && outEnable) { | |
113
ac0c31c38959
Fixed KWh measurement for Hendi equipment.
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
77 | if (MLT_pin != 1 && ! equipment.Hendi) |
87
47253f294a9f
SDK settings to reduce bin size. Some log messages to debug level. Added KWH usage registration. Added equipment power usage for HLT and MLT. Equipment database upgraded to version 2, expandable. Fixed some screen errors during temperature mash steps.
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
78 | MLT_time = xTaskGetTickCount(); |
0 | 79 | gpio_set_level(SSR_MLT, 1); |
80 | MLT_pin = 1; | |
81 | } else { | |
113
ac0c31c38959
Fixed KWh measurement for Hendi equipment.
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
82 | if (MLT_pin && ! equipment.Hendi) |
87
47253f294a9f
SDK settings to reduce bin size. Some log messages to debug level. Added KWH usage registration. Added equipment power usage for HLT and MLT. Equipment database upgraded to version 2, expandable. Fixed some screen errors during temperature mash steps.
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
83 | runtime.MLT_usage += xTaskGetTickCount() - MLT_time; |
0 | 84 | gpio_set_level(SSR_MLT, 0); |
85 | MLT_pin = 0; | |
86 | } | |
87 | } | |
88 | ||
89 | ||
90 | ||
91 | void HLT(int onoff) { | |
92 | ||
93 | if (onoff && outEnable) { | |
87
47253f294a9f
SDK settings to reduce bin size. Some log messages to debug level. Added KWH usage registration. Added equipment power usage for HLT and MLT. Equipment database upgraded to version 2, expandable. Fixed some screen errors during temperature mash steps.
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
94 | if (HLT_pin != 1) |
47253f294a9f
SDK settings to reduce bin size. Some log messages to debug level. Added KWH usage registration. Added equipment power usage for HLT and MLT. Equipment database upgraded to version 2, expandable. Fixed some screen errors during temperature mash steps.
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
95 | HLT_time = xTaskGetTickCount(); |
0 | 96 | gpio_set_level(SSR_HLT, 1); |
97 | HLT_pin = 1; | |
98 | } else { | |
87
47253f294a9f
SDK settings to reduce bin size. Some log messages to debug level. Added KWH usage registration. Added equipment power usage for HLT and MLT. Equipment database upgraded to version 2, expandable. Fixed some screen errors during temperature mash steps.
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
99 | if (HLT_pin) |
47253f294a9f
SDK settings to reduce bin size. Some log messages to debug level. Added KWH usage registration. Added equipment power usage for HLT and MLT. Equipment database upgraded to version 2, expandable. Fixed some screen errors during temperature mash steps.
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
100 | runtime.HLT_usage += xTaskGetTickCount() - HLT_time; |
0 | 101 | gpio_set_level(SSR_HLT, 0); |
102 | HLT_pin = 0; | |
103 | } | |
104 | } | |
105 | ||
106 | ||
107 | ||
108 | void Pump(int onoff) { | |
109 | ||
110 | if (onoff && outEnable) { | |
111 | gpio_set_level(SSR_PUMP, 1); | |
112 | Pump_pin = 1; | |
113 | } else { | |
114 | gpio_set_level(SSR_PUMP, 0); | |
115 | Pump_pin = 0; | |
116 | } | |
117 | } | |
118 | ||
119 | ||
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
120 | void MLT_PWM(int percent) { |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
121 | int val; |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
122 | static int oldval = -1; |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
123 | |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
124 | if (outEnable) { |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
125 | if (percent < 0) { |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
126 | val = 0; |
113
ac0c31c38959
Fixed KWh measurement for Hendi equipment.
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
127 | MLT_time = xTaskGetTickCount(); |
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
128 | } else if (percent > 100) { |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
129 | val = 1024; |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
130 | } else { |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
131 | val = (percent * 1024) / 100; |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
132 | } |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
133 | } else { |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
134 | val = 0; |
113
ac0c31c38959
Fixed KWh measurement for Hendi equipment.
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
135 | MLT_time = xTaskGetTickCount(); |
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
136 | } |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
137 | |
103
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
138 | /* |
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
139 | * If the Hendi is on, the lowest setting is 500 Watt. So, if we need less then |
116
bafc2d6a0790
Fixed Hendi ON switch and now the switch moment is in a #define HENDI_SWITCH. Currently set at 6. Fixed the web page when going to boil, two buttons were missing. Changed the PWM log line, added information about the ON switch and current temperature.
Michiel Broek <mbroek@mbse.eu>
parents:
113
diff
changeset
|
140 | * HENDI_SWITCH power, turn it off, just like the manual knob. |
103
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
141 | */ |
116
bafc2d6a0790
Fixed Hendi ON switch and now the switch moment is in a #define HENDI_SWITCH. Currently set at 6. Fixed the web page when going to boil, two buttons were missing. Changed the PWM log line, added information about the ON switch and current temperature.
Michiel Broek <mbroek@mbse.eu>
parents:
113
diff
changeset
|
142 | MLT((percent >= HENDI_SWITCH) ? 1:0); |
103
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
143 | |
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
144 | if (val != oldval) { |
116
bafc2d6a0790
Fixed Hendi ON switch and now the switch moment is in a #define HENDI_SWITCH. Currently set at 6. Fixed the web page when going to boil, two buttons were missing. Changed the PWM log line, added information about the ON switch and current temperature.
Michiel Broek <mbroek@mbse.eu>
parents:
113
diff
changeset
|
145 | log_msg(TAG, "MLT(%d) MLT_PWM(%d) val=%d %.0f watt pv: %.3f", (percent >= HENDI_SWITCH) ? 1:0, |
bafc2d6a0790
Fixed Hendi ON switch and now the switch moment is in a #define HENDI_SWITCH. Currently set at 6. Fixed the web page when going to boil, two buttons were missing. Changed the PWM log line, added information about the ON switch and current temperature.
Michiel Broek <mbroek@mbse.eu>
parents:
113
diff
changeset
|
146 | percent, val, (percent / 100.0) * equipment.MLT_watt, driver_state->mlt_pv); |
112 | 147 | ledc_set_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0,/* 1024 - */val); |
103
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
148 | ledc_update_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0); |
116
bafc2d6a0790
Fixed Hendi ON switch and now the switch moment is in a #define HENDI_SWITCH. Currently set at 6. Fixed the web page when going to boil, two buttons were missing. Changed the PWM log line, added information about the ON switch and current temperature.
Michiel Broek <mbroek@mbse.eu>
parents:
113
diff
changeset
|
149 | if (val >= HENDI_SWITCH) { |
113
ac0c31c38959
Fixed KWh measurement for Hendi equipment.
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
150 | runtime.MLT_usage += (xTaskGetTickCount() - MLT_time) * (percent / 100.0); |
ac0c31c38959
Fixed KWh measurement for Hendi equipment.
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
151 | } |
ac0c31c38959
Fixed KWh measurement for Hendi equipment.
Michiel Broek <mbroek@mbse.eu>
parents:
112
diff
changeset
|
152 | MLT_time = xTaskGetTickCount(); |
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
153 | } |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
154 | oldval = val; |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
155 | } |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
156 | |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
157 | |
0 | 158 | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
159 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
160 | * @brief Load PID settings from equipment record. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
161 | */ |
0 | 162 | void LoadPIDsettings() { |
82 | 163 | PID_SetTunings(equipment.PID_kP, equipment.PID_kI, equipment.PID_kD); |
0 | 164 | PID_SetSampleTime(equipment.SampleTime); |
165 | ||
166 | /* | |
167 | * Initialize the PID | |
168 | */ | |
169 | Output = 0.0; // Reset internal Iterm. | |
170 | PID_SetMode(PID_MANUAL); | |
171 | PID_SetMode(PID_AUTOMATIC); | |
172 | } | |
173 | ||
174 | ||
175 | ||
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
176 | void AllowHLT(void) { |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
177 | if (equipment.SSR2 == SSR2_HLT_SHARE) { |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
178 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
179 | HLT_Output = 0; |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
180 | if (driver_state->hlt_mode == HLT_MODE_BANG) { |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
181 | HLT_Output = (HLT_Input < HLT_Setpoint) ? 1:0; |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
182 | } else if (driver_state->hlt_mode == HLT_MODE_ON) { |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
183 | HLT_Output = 1; |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
184 | } |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
185 | xSemaphoreGive(xSemaphoreDriver); |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
186 | } |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
187 | HLT(HLT_Output); |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
188 | } else if (equipment.SSR2 == SSR2_ON_IDLE) { |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
189 | HLT_Output = 1; |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
190 | HLT(1); |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
191 | } |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
192 | } |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
193 | |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
194 | |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
195 | |
0 | 196 | void task_driver(void *pvParameter) |
197 | { | |
198 | TickType_t wait_ticks, last_tick, now_tick; | |
199 | bool rc; | |
103
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
200 | int SafeCount = 0; |
0 | 201 | unsigned long now, RealTime, w_StartTime = 0; |
202 | ||
88
7f02dbee58d0
Fix missing log entries. More code space saving.
Michiel Broek <mbroek@mbse.eu>
parents:
87
diff
changeset
|
203 | ESP_LOGI(TAG, "Start drivers"); |
0 | 204 | |
205 | /* | |
206 | * Configure IOMUX register. | |
207 | */ | |
208 | gpio_pad_select_gpio(SSR_MLT); | |
209 | gpio_set_direction(SSR_MLT, GPIO_MODE_OUTPUT); | |
210 | gpio_pad_select_gpio(SSR_HLT); | |
211 | gpio_set_direction(SSR_HLT, GPIO_MODE_OUTPUT); | |
212 | gpio_pad_select_gpio(SSR_PUMP); | |
213 | gpio_set_direction(SSR_PUMP, GPIO_MODE_OUTPUT); | |
214 | ||
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
215 | // Prepare and then apply the LEDC PWM timer configuration |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
216 | ledc_timer_config_t ledc_timer = { |
103
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
217 | .speed_mode = LEDC_HIGH_SPEED_MODE, ///< Use high speed timer |
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
218 | .timer_num = LEDC_TIMER_0, ///< Timer 0 |
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
219 | .duty_resolution = LEDC_TIMER_10_BIT, ///< 10 bits resolution |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
220 | .freq_hz = 100, ///< 100 Hz |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
221 | .clk_cfg = LEDC_AUTO_CLK ///< Auto select PWM clock |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
222 | }; |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
223 | ledc_timer_config(&ledc_timer); |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
224 | |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
225 | ledc_channel_config_t pwm_channel = { |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
226 | .channel = LEDC_CHANNEL_0, |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
227 | .duty = 1024, ///< Default 0% (inverted value) |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
228 | .gpio_num = PWM_MLT, ///< MLT pin |
103
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
229 | .speed_mode = LEDC_HIGH_SPEED_MODE, |
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
230 | .hpoint = 0, |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
231 | .intr_type = LEDC_INTR_DISABLE, |
103
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
232 | .timer_sel = LEDC_TIMER_0 ///< Timer 0 |
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
233 | }; |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
234 | ledc_channel_config(&pwm_channel); |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
235 | |
0 | 236 | /* |
237 | * Initialize state | |
238 | */ | |
239 | driver_state = malloc(sizeof(DRIVER_State)); | |
240 | driver_state->enable = outEnable = false; | |
241 | driver_state->mlt_gpio = SSR_MLT; | |
242 | driver_state->mlt_mode = MLT_MODE_NONE; | |
243 | driver_state->mlt_sp = driver_state->mlt_pv = 0.0; | |
244 | driver_state->mlt_power = 0; | |
245 | driver_state->hlt_gpio = SSR_HLT; | |
246 | driver_state->hlt_mode = HLT_MODE_NONE; | |
247 | driver_state->hlt_sp = driver_state->hlt_pv = 0.0; | |
248 | driver_state->hlt_power = 0; | |
249 | driver_state->hlt_and_mlt = false; | |
250 | driver_state->pump_gpio = SSR_PUMP; | |
251 | driver_state->pump_run = 0; | |
252 | ||
86 | 253 | PID(&Input, &Output, &Setpoint, 200, 2.0, 1.5, PID_DIRECT); |
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
254 | |
0 | 255 | /* |
256 | * One loop must complete in 20 mSecs, that is one mains | |
257 | * frequency period cycle in 50 Hz countries. | |
258 | */ | |
259 | while (1) { | |
260 | ||
261 | last_tick = xTaskGetTickCount(); | |
262 | ||
263 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
264 | /* | |
265 | * Get the current temperature readings | |
266 | */ | |
267 | if (xSemaphoreTake(xSemaphoreDS18B20, 10) == pdTRUE) { | |
268 | if (ds18b20_state->mlt_valid) | |
269 | driver_state->mlt_pv = ds18b20_state->mlt_temperature; | |
270 | if (ds18b20_state->hlt_valid) | |
271 | driver_state->hlt_pv = ds18b20_state->hlt_temperature; | |
272 | xSemaphoreGive(xSemaphoreDS18B20); | |
273 | } | |
274 | ||
275 | /* | |
276 | * Other values that we need | |
277 | */ | |
278 | Input = driver_state->mlt_pv; | |
279 | Setpoint = driver_state->mlt_sp; | |
280 | if (driver_state->mlt_mode != MLT_Mode) { | |
281 | if (driver_state->mlt_mode == MLT_MODE_BANG) { | |
282 | PID_SetMode(PID_MANUAL); | |
283 | } else if (driver_state->mlt_mode == MLT_MODE_PID) { | |
284 | LoadPIDsettings(); | |
285 | } | |
286 | MLT_Mode = driver_state->mlt_mode; | |
87
47253f294a9f
SDK settings to reduce bin size. Some log messages to debug level. Added KWH usage registration. Added equipment power usage for HLT and MLT. Equipment database upgraded to version 2, expandable. Fixed some screen errors during temperature mash steps.
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
287 | ESP_LOGI(TAG, "MLT mode set to %s", MLTTypes[MLT_Mode]); |
0 | 288 | } |
289 | if (driver_state->hlt_mode != HLT_Mode) { | |
290 | HLT_Mode = driver_state->hlt_mode; | |
87
47253f294a9f
SDK settings to reduce bin size. Some log messages to debug level. Added KWH usage registration. Added equipment power usage for HLT and MLT. Equipment database upgraded to version 2, expandable. Fixed some screen errors during temperature mash steps.
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
291 | ESP_LOGI(TAG, "HLT mode set to %s", HLTTypes[HLT_Mode]); |
0 | 292 | } |
293 | outEnable = driver_state->enable; | |
294 | HLT_Input = driver_state->hlt_pv; | |
295 | HLT_Setpoint = driver_state->hlt_sp; | |
296 | xSemaphoreGive(xSemaphoreDriver); | |
297 | } | |
298 | ||
299 | rc = false; | |
300 | now = xTaskGetTickCount() * portTICK_PERIOD_MS; | |
301 | ||
302 | if ((PID_GetMode() == PID_AUTOMATIC) && (MLT_Mode == MLT_MODE_PID)) { | |
303 | rc = PID_Compute(); | |
304 | RealTime = (equipment.SampleTime * equipment.MashPower) / 100; | |
305 | } else { | |
306 | /* | |
307 | * Schedule the loop ourself. | |
308 | */ | |
309 | unsigned long timeChange = (now - lastTime); | |
310 | if (timeChange >= equipment.SampleTime) { | |
311 | lastTime = now; | |
312 | rc = true; | |
313 | } | |
314 | RealTime = equipment.SampleTime; | |
315 | if (driver_state->mlt_mode == MLT_MODE_BANG) { | |
316 | Output = (Input < Setpoint) ? 255:0; | |
317 | } | |
318 | if (driver_state->mlt_mode == MLT_MODE_NONE || driver_state->mlt_mode == MLT_MODE_OFF) { | |
319 | Output = 0; | |
320 | } | |
321 | } | |
322 | ||
323 | if (rc) { | |
324 | w_StartTime = now; | |
325 | } | |
326 | ||
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
327 | if (equipment.Hendi) { |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
328 | |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
329 | int PWMout = (int)((Output * 100) / 255.0); |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
330 | |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
331 | if ((PID_GetMode() == PID_AUTOMATIC) && (MLT_Mode == MLT_MODE_PID)) { |
103
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
332 | /* Mash power limited */ |
110
2f9e48e5b8ce
Changed PWM power calculation during PID use.
Michiel Broek <mbroek@mbse.eu>
parents:
109
diff
changeset
|
333 | PWMout = (PWMout * equipment.MashPower) / 100; |
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
334 | } |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
335 | |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
336 | /* |
116
bafc2d6a0790
Fixed Hendi ON switch and now the switch moment is in a #define HENDI_SWITCH. Currently set at 6. Fixed the web page when going to boil, two buttons were missing. Changed the PWM log line, added information about the ON switch and current temperature.
Michiel Broek <mbroek@mbse.eu>
parents:
113
diff
changeset
|
337 | * Do not send power values < HENDI_SWITCH. |
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
338 | */ |
116
bafc2d6a0790
Fixed Hendi ON switch and now the switch moment is in a #define HENDI_SWITCH. Currently set at 6. Fixed the web page when going to boil, two buttons were missing. Changed the PWM log line, added information about the ON switch and current temperature.
Michiel Broek <mbroek@mbse.eu>
parents:
113
diff
changeset
|
339 | if (PWMout >= HENDI_SWITCH) { // Hendi minimum power is 500 Watt, this is 10% |
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
340 | if ((((PWMout / 100.0) * equipment.MLT_watt) + equipment.HLT_watt) > equipment.Max_watt) { |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
341 | if (HLT_pin) { |
103
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
342 | ESP_LOGI(TAG, "Current %.0f Watt above %d limit, shutdown HLT", |
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
343 | ((PWMout / 100.0) * equipment.MLT_watt) + equipment.HLT_watt, equipment.Max_watt); |
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
344 | HLT_Output = 0; |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
345 | HLT(0); // As soon as possible before the Hendi increases power. |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
346 | } |
103
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
347 | SafeCount = (int)(15000 / equipment.SampleTime) + 1; // About 15 seconds release time |
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
348 | } else if (rc) { |
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
349 | if (SafeCount > 0) { |
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
350 | SafeCount--; |
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
351 | } else { |
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
352 | AllowHLT(); |
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
353 | } |
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
354 | } |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
355 | MLT_PWM(PWMout); |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
356 | } else { |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
357 | MLT_PWM(0); |
103
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
358 | if (rc) { |
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
359 | if (SafeCount > 0) { |
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
360 | SafeCount--; |
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
361 | } else { |
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
362 | AllowHLT(); |
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
363 | } |
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
364 | } |
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
365 | } |
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
366 | } else if ((int)((Output / 255.0) * RealTime) > (now - w_StartTime)) { |
103
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
367 | /* |
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
368 | * Use On/Off kettles using time slices. |
1885d0c75c48
Default equipment max_watt set to 2750. Added defaults for new equipment record. Switched PWM timer to high-speed. Implemented the safety timer to prevent the MLT + HLT will draw too much power in shared mode. Removed some code ideas that were not used. The fake heater now uses the faked PWM power.
Michiel Broek <mbroek@mbse.eu>
parents:
102
diff
changeset
|
369 | */ |
0 | 370 | MLT(1); |
371 | if ((equipment.SSR2 == SSR2_HLT_SHARE) || (equipment.SSR2 == SSR2_ON_IDLE)) { | |
372 | HLT(0); | |
373 | HLT_Output = 0; | |
374 | } | |
375 | } else { | |
376 | MLT(0); | |
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
377 | AllowHLT(); |
0 | 378 | } |
379 | ||
380 | /* | |
381 | * Independant HLT temperature control | |
382 | */ | |
383 | if (equipment.SSR2 == SSR2_HLT_IND) { | |
384 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
385 | HLT_Output = 0; | |
386 | if (driver_state->hlt_mode == HLT_MODE_BANG) { | |
387 | HLT_Output = (HLT_Input < HLT_Setpoint) ? 1:0; | |
388 | } else if (driver_state->hlt_mode == HLT_MODE_ON) { | |
389 | HLT_Output = 1; | |
390 | } | |
391 | xSemaphoreGive(xSemaphoreDriver); | |
392 | } | |
393 | HLT(HLT_Output); | |
394 | } | |
395 | ||
396 | /* | |
397 | * Update the driver results. | |
398 | */ | |
399 | if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) { | |
400 | driver_state->mlt_power = (int)((Output * 100) / 255.0); | |
401 | if (HLT_Output) { | |
402 | if (equipment.SSR2 == SSR2_HLT_SHARE) { | |
403 | driver_state->hlt_power = 100 - driver_state->mlt_power; | |
404 | } else if (equipment.SSR2 == SSR2_HLT_IND) { | |
405 | driver_state->hlt_power = 100; | |
406 | } | |
407 | } else { | |
408 | driver_state->hlt_power = 0; | |
409 | } | |
410 | if (driver_state->pump_run != Pump_pin) | |
411 | Pump(driver_state->pump_run); | |
412 | xSemaphoreGive(xSemaphoreDriver); | |
413 | } | |
414 | ||
415 | #if 0 | |
416 | if (rc) { | |
417 | printf("ST: %s MLT[In: %7.3f Out: %3.0f Sp: %6.2f %s RT: %lu] HLT[In: %7.3f Out: %d Sp: %5.1f]\n", outEnable ? "E":"D", | |
418 | Input, Output, Setpoint, PID_GetMode() ? "AUTOMATIC" : "MANUAL ", RealTime, | |
419 | HLT_Input, HLT_Output, HLT_Setpoint); | |
420 | } | |
421 | #endif | |
422 | ||
102
96e30a3a3980
Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.
Michiel Broek <mbroek@mbse.eu>
parents:
101
diff
changeset
|
423 | // Do not use vTaskDelayUntil(), it is not reliable here. |
0 | 424 | now_tick = xTaskGetTickCount(); |
425 | if ((now_tick - last_tick) > (1000 / 50)) { | |
426 | // This happens one or two times during a brew. | |
427 | wait_ticks = (1000 / 50); | |
428 | } else { | |
429 | wait_ticks = (1000 / 50) - (now_tick - last_tick); | |
430 | } | |
431 | if (wait_ticks == 0) { | |
432 | // This is rare, but it happens. | |
433 | wait_ticks = 1; | |
434 | } | |
435 | ||
436 | vTaskDelay(wait_ticks); | |
437 | } | |
438 | } | |
439 | ||
440 |