2023-04-17 19:32:34 +00:00
|
|
|
#ifndef _FLOW_H_
|
|
|
|
#define _FLOW_H_
|
|
|
|
|
2024-05-04 11:04:05 +00:00
|
|
|
mqttValueTiming timing_flow_a;
|
|
|
|
mqttValueTiming timing_flow_b;
|
2023-05-10 20:27:59 +00:00
|
|
|
|
2024-05-04 11:04:05 +00:00
|
|
|
#define FLOW_A_PIN 16
|
|
|
|
#define FLOW_B_PIN 17
|
|
|
|
uint16_t flow_a_counter=0; //maximum counts/s measured with Eden 128 Pump was 171
|
|
|
|
uint16_t flow_b_counter=0; //maximum counts/s measured with Eden 128 Pump was 171
|
|
|
|
void IRAM_ATTR isr_flow_a();
|
|
|
|
void IRAM_ATTR isr_flow_b();
|
|
|
|
unsigned long last_read_flow_a=0;
|
|
|
|
unsigned long last_read_flow_b=0;
|
2023-05-15 16:00:51 +00:00
|
|
|
#define READINTERVAL_FLOW 10000
|
2023-04-17 19:32:34 +00:00
|
|
|
float flow_factor=7.5; //F=7.5*flowrate[L/min]
|
2024-05-04 11:04:05 +00:00
|
|
|
float flow_a;
|
|
|
|
float flow_b;
|
2023-04-17 19:32:34 +00:00
|
|
|
|
2024-05-04 11:04:05 +00:00
|
|
|
uint32_t flow_a_counter_sum=0;
|
|
|
|
uint32_t flow_b_counter_sum=0;
|
2023-04-17 19:32:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void flow_setup() {
|
|
|
|
|
2024-05-04 11:04:05 +00:00
|
|
|
timing_flow_a.minchange=0.0;
|
|
|
|
timing_flow_a.maxchange=0.3;
|
|
|
|
timing_flow_a.mintime=10*000;
|
|
|
|
timing_flow_a.maxtime=30*60*1000;
|
2023-05-10 20:27:59 +00:00
|
|
|
|
2024-05-04 11:04:05 +00:00
|
|
|
timing_flow_b.minchange=0.0;
|
|
|
|
timing_flow_b.maxchange=0.3;
|
|
|
|
timing_flow_b.mintime=10*000;
|
|
|
|
timing_flow_b.maxtime=30*60*1000;
|
|
|
|
|
|
|
|
pinMode(FLOW_A_PIN, INPUT_PULLUP);
|
|
|
|
pinMode(FLOW_B_PIN, INPUT_PULLUP);
|
|
|
|
attachInterrupt(FLOW_A_PIN, isr_flow_a, CHANGE);
|
|
|
|
attachInterrupt(FLOW_B_PIN, isr_flow_b, CHANGE);
|
2023-04-17 19:32:34 +00:00
|
|
|
}
|
|
|
|
|
2023-04-20 19:51:47 +00:00
|
|
|
void flow_loop(unsigned long loopmillis) {
|
2024-05-04 11:04:05 +00:00
|
|
|
if (loopmillis>=last_read_flow_a+READINTERVAL_FLOW) {
|
|
|
|
flow_a=flow_a_counter*1000.0/(loopmillis-last_read_flow_a)/2.0; //Frequency [Hz]
|
|
|
|
flow_a/=flow_factor; //[L/min]
|
|
|
|
|
|
|
|
flow_a_counter=0;
|
|
|
|
last_read_flow_a=loopmillis;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loopmillis>=last_read_flow_b+READINTERVAL_FLOW) {
|
|
|
|
flow_b=flow_b_counter*1000.0/(loopmillis-last_read_flow_b)/2.0; //Frequency [Hz]
|
|
|
|
flow_b/=flow_factor; //[L/min]
|
2023-04-17 19:32:34 +00:00
|
|
|
|
2024-05-04 11:04:05 +00:00
|
|
|
flow_b_counter=0;
|
|
|
|
last_read_flow_b=loopmillis;
|
2023-04-17 19:32:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-04 11:04:05 +00:00
|
|
|
void IRAM_ATTR isr_flow_a() {
|
|
|
|
flow_a_counter++;
|
|
|
|
flow_a_counter_sum++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IRAM_ATTR isr_flow_b() {
|
|
|
|
flow_b_counter++;
|
|
|
|
flow_b_counter_sum++;
|
2023-04-17 19:32:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|