main/task_driver.c

Mon, 21 Jun 2021 19:04:10 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 21 Jun 2021 19:04:10 +0200
changeset 102
96e30a3a3980
parent 101
1bc6e9263ada
child 103
1885d0c75c48
permissions
-rw-r--r--

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.

0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * @file task_driver.c
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 * @brief BrewBoard relays driver. Control the hardware outputs with the
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Solid State relays for the Mash/Boil kettle (MLT, the Hot
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * Liquer Tank (HLT) and the pump. The MLT has a PID controller
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * during mashing, and a simple bang on/off control during the
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * boil.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * The HLT output can be off, bang on/off, or just on if the MLT
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * is off, depending on the configuration.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * Use SSR modules that switch during zero crossing of the mains
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * power, so that when one is turned on and on the same time the
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * other is turned off, they won't be active at the same time.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 #include "config.h"
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
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
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23
1
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
24 bool outEnable = false; ///< Enable outputs flag
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
25 DRIVER_State * driver_state; ///< Driver state
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
26 SemaphoreHandle_t xSemaphoreDriver = NULL; ///< Driver state lock
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
27 int MLT_pin = 0; ///< MLT state
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
28 int HLT_pin = 0; ///< HLT state
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
29 int Pump_pin = 0; ///< Pump state
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
30 double Input = 0; ///< PID input value
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
31 double Output = 0; ///< PID output value
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
32 double Setpoint = 0; ///< PID setpoint value
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
33 int MLT_Mode = MLT_MODE_NONE; ///< MLT mode flag
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
34 double HLT_Input = 0; ///< HLT input value
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
35 double HLT_Setpoint = 0; ///< HLT setpoint values
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
36 int HLT_Output = 0; ///< HLT output value
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
37 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
38 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
39
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 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
41 static const char *HLTTypes[] = { "None", "Bang", "Off", "On" };
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 static const char *TAG = "task_driver";
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44
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
45 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
46 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
47 extern unsigned long lastTime;
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 /**
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 * @brief Turn the MLT SSR on or off.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 void MLT(int onoff);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 /**
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 * @brief Turn the HLT SSR on or off.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 void HLT(int onoff);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 /**
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 * @brief Turn the Pump on or off.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 void Pump(int onoff);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64
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
65 /**
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 * @brief Calculate and set PWM 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
67 * @param percent Then power percentage, 0..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
68 */
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 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
70
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 void MLT(int onoff) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 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
76 if (MLT_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
77 MLT_time = xTaskGetTickCount();
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 gpio_set_level(SSR_MLT, 1);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 MLT_pin = 1;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 } 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
81 if (MLT_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
82 runtime.MLT_usage += xTaskGetTickCount() - MLT_time;
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 gpio_set_level(SSR_MLT, 0);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 MLT_pin = 0;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 void HLT(int onoff) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 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
93 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
94 HLT_time = xTaskGetTickCount();
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 gpio_set_level(SSR_HLT, 1);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 HLT_pin = 1;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97 } 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
98 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
99 runtime.HLT_usage += xTaskGetTickCount() - HLT_time;
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 gpio_set_level(SSR_HLT, 0);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 HLT_pin = 0;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 void Pump(int onoff) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 if (onoff && outEnable) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 gpio_set_level(SSR_PUMP, 1);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 Pump_pin = 1;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 } else {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113 gpio_set_level(SSR_PUMP, 0);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 Pump_pin = 0;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118
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
119 //int oldval = 200;
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;
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
127 } 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
128 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
129 } 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
130 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
131 }
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 } 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
133 val = 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
134 }
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
135
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 if (val != oldval) {
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 ESP_LOGI(TAG, "MLT_PWM(%d) val=%d %.0f watt", percent, val, (percent / 100.0) * equipment.MLT_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
138 ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 1024 - 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
139 ledc_update_duty(LEDC_LOW_SPEED_MODE, 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
140 }
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
141 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
142 }
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
143
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
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145
1
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
146 /**
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
147 * @brief Load PID settings from equipment record.
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
148 */
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 void LoadPIDsettings() {
82
7d17e2cb31a8 The PID workig mode is fixed
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
150 PID_SetTunings(equipment.PID_kP, equipment.PID_kI, equipment.PID_kD);
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 PID_SetSampleTime(equipment.SampleTime);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 /*
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 * Initialize the PID
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 Output = 0.0; // Reset internal Iterm.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 PID_SetMode(PID_MANUAL);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 PID_SetMode(PID_AUTOMATIC);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162
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
163 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
164 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
165 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
166 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
167 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
168 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
169 } 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
170 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
171 }
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
172 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
173 }
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
174 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
175 } 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
176 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
177 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
178 }
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 }
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
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
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
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 void task_driver(void *pvParameter)
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 TickType_t wait_ticks, last_tick, now_tick;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 bool rc;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 unsigned long now, RealTime, w_StartTime = 0;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188
88
7f02dbee58d0 Fix missing log entries. More code space saving.
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
189 ESP_LOGI(TAG, "Start drivers");
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 /*
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192 * Configure IOMUX register.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 gpio_pad_select_gpio(SSR_MLT);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 gpio_set_direction(SSR_MLT, GPIO_MODE_OUTPUT);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 gpio_pad_select_gpio(SSR_HLT);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197 gpio_set_direction(SSR_HLT, GPIO_MODE_OUTPUT);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198 gpio_pad_select_gpio(SSR_PUMP);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199 gpio_set_direction(SSR_PUMP, GPIO_MODE_OUTPUT);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200
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
201 // 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
202 ledc_timer_config_t 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
203 .speed_mode = LEDC_LOW_SPEED_MODE, ///< Use low speed
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
204 .timer_num = LEDC_TIMER_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
205 .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
206 .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
207 .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
208 };
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
209 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
210
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
211 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
212 .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
213 .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
214 .gpio_num = PWM_MLT, ///< MLT pin
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 .speed_mode = LEDC_LOW_SPEED_MODE,
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 .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
217 .intr_type = LEDC_INTR_DISABLE,
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
218 .timer_sel = LEDC_TIMER_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
219 };
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 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
221
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 /*
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223 * Initialize state
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 driver_state = malloc(sizeof(DRIVER_State));
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226 driver_state->enable = outEnable = false;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227 driver_state->mlt_gpio = SSR_MLT;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 driver_state->mlt_mode = MLT_MODE_NONE;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 driver_state->mlt_sp = driver_state->mlt_pv = 0.0;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 driver_state->mlt_power = 0;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 driver_state->hlt_gpio = SSR_HLT;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 driver_state->hlt_mode = HLT_MODE_NONE;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 driver_state->hlt_sp = driver_state->hlt_pv = 0.0;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234 driver_state->hlt_power = 0;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235 driver_state->hlt_and_mlt = false;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 driver_state->pump_gpio = SSR_PUMP;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 driver_state->pump_run = 0;
101
1bc6e9263ada Fixed HendiControl interface connecter to match the board input. Tested the new circuit.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
238 driver_state->pwm_gpio = PWM_MLT;
1bc6e9263ada Fixed HendiControl interface connecter to match the board input. Tested the new circuit.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
239 driver_state->pwm_mlt = false;
1bc6e9263ada Fixed HendiControl interface connecter to match the board input. Tested the new circuit.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
240 driver_state->pwm_nohlt = 10; /* Conservative safety value. */
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241
86
8d0287a1a9e1 Default PID init adjusted.
Michiel Broek <mbroek@mbse.eu>
parents: 82
diff changeset
242 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
243
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 /*
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
245 * One loop must complete in 20 mSecs, that is one mains
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246 * frequency period cycle in 50 Hz countries.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248 while (1) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
249
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
250 last_tick = xTaskGetTickCount();
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253 /*
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 * Get the current temperature readings
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
256 if (xSemaphoreTake(xSemaphoreDS18B20, 10) == pdTRUE) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257 if (ds18b20_state->mlt_valid)
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
258 driver_state->mlt_pv = ds18b20_state->mlt_temperature;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
259 if (ds18b20_state->hlt_valid)
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
260 driver_state->hlt_pv = ds18b20_state->hlt_temperature;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
261 xSemaphoreGive(xSemaphoreDS18B20);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
262 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
263
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
264 /*
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
265 * Other values that we need
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
266 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
267 Input = driver_state->mlt_pv;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
268 Setpoint = driver_state->mlt_sp;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
269 if (driver_state->mlt_mode != MLT_Mode) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
270 if (driver_state->mlt_mode == MLT_MODE_BANG) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271 PID_SetMode(PID_MANUAL);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
272 } else if (driver_state->mlt_mode == MLT_MODE_PID) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273 LoadPIDsettings();
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
274 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275 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
276 ESP_LOGI(TAG, "MLT mode set to %s", MLTTypes[MLT_Mode]);
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
277 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
278 if (driver_state->hlt_mode != HLT_Mode) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
279 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
280 ESP_LOGI(TAG, "HLT mode set to %s", HLTTypes[HLT_Mode]);
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
281 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
282 outEnable = driver_state->enable;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
283 HLT_Input = driver_state->hlt_pv;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
284 HLT_Setpoint = driver_state->hlt_sp;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
285 xSemaphoreGive(xSemaphoreDriver);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
286 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
287
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
288 rc = false;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
289 now = xTaskGetTickCount() * portTICK_PERIOD_MS;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
290
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
291 if ((PID_GetMode() == PID_AUTOMATIC) && (MLT_Mode == MLT_MODE_PID)) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
292 rc = PID_Compute();
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
293 RealTime = (equipment.SampleTime * equipment.MashPower) / 100;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
294 } else {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
295 /*
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
296 * Schedule the loop ourself.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
297 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
298 unsigned long timeChange = (now - lastTime);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
299 if (timeChange >= equipment.SampleTime) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
300 lastTime = now;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
301 rc = true;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
302 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
303 RealTime = equipment.SampleTime;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
304 if (driver_state->mlt_mode == MLT_MODE_BANG) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
305 Output = (Input < Setpoint) ? 255:0;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
306 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
307 if (driver_state->mlt_mode == MLT_MODE_NONE || driver_state->mlt_mode == MLT_MODE_OFF) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
308 Output = 0;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
309 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
310 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
311
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
312 if (rc) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
313 w_StartTime = now;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
314 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
315
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
316 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
317
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
318 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
319
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
320 if ((PID_GetMode() == PID_AUTOMATIC) && (MLT_Mode == MLT_MODE_PID)) {
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
321 if (PWMout > equipment.MashPower)
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
322 PWMout = equipment.MashPower;
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
323 }
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
324
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
325 /*
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
326 * Hendi minimum power is 500 Watt, this is 14%.
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 * So, we turn the cooker on around 10% 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
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 if (PWMout >= 10) { // Hendi minimum power is 500 Watt, this is 10%
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 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
331 if (HLT_pin) {
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
332 ESP_LOGI(TAG, "Power %f %d", ((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
333 ESP_LOGI(TAG, "Immediate HLT panic shutdown");
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 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
335 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
336 }
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
337 } 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
338 AllowHLT(); // TODO: delay this one loop.
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
339 }
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 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
341 MLT(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
342 } 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
343 MLT_PWM(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
344 MLT(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 AllowHLT();
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 }
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
347 } else if ((int)((Output / 255.0) * RealTime) > (now - w_StartTime)) {
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
348 MLT(1);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
349 if ((equipment.SSR2 == SSR2_HLT_SHARE) || (equipment.SSR2 == SSR2_ON_IDLE)) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
350 HLT(0);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
351 HLT_Output = 0;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
352 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
353 } else {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
354 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
355 AllowHLT();
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
356 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
357
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
358 /*
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
359 * Independant HLT temperature control
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
360 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
361 if (equipment.SSR2 == SSR2_HLT_IND) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
362 if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
363 HLT_Output = 0;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
364 if (driver_state->hlt_mode == HLT_MODE_BANG) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
365 HLT_Output = (HLT_Input < HLT_Setpoint) ? 1:0;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
366 } else if (driver_state->hlt_mode == HLT_MODE_ON) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
367 HLT_Output = 1;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
368 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
369 xSemaphoreGive(xSemaphoreDriver);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
370 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
371 HLT(HLT_Output);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
372 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
373
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
374 /*
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
375 * Update the driver results.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
376 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
377 if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
378 driver_state->mlt_power = (int)((Output * 100) / 255.0);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
379 if (HLT_Output) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
380 if (equipment.SSR2 == SSR2_HLT_SHARE) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
381 driver_state->hlt_power = 100 - driver_state->mlt_power;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
382 } else if (equipment.SSR2 == SSR2_HLT_IND) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
383 driver_state->hlt_power = 100;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
384 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
385 } else {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
386 driver_state->hlt_power = 0;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
387 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
388 if (driver_state->pump_run != Pump_pin)
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
389 Pump(driver_state->pump_run);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
390 xSemaphoreGive(xSemaphoreDriver);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
391 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
392
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
393 #if 0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
394 if (rc) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
395 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",
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
396 Input, Output, Setpoint, PID_GetMode() ? "AUTOMATIC" : "MANUAL ", RealTime,
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
397 HLT_Input, HLT_Output, HLT_Setpoint);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
398 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
399 #endif
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
400
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
401 // Do not use vTaskDelayUntil(), it is not reliable here.
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
402 now_tick = xTaskGetTickCount();
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
403 if ((now_tick - last_tick) > (1000 / 50)) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
404 // This happens one or two times during a brew.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
405 wait_ticks = (1000 / 50);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
406 } else {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
407 wait_ticks = (1000 / 50) - (now_tick - last_tick);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
408 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
409 if (wait_ticks == 0) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
410 // This is rare, but it happens.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
411 wait_ticks = 1;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
412 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
413
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
414 vTaskDelay(wait_ticks);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
415 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
416 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
417
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
418

mercurial