hydroponic-controller/include/flow.h

53 lines
966 B
C
Raw Normal View History

2023-04-17 19:32:34 +00:00
#ifndef _FLOW_H_
#define _FLOW_H_
2024-06-25 19:10:12 +00:00
mqttValueTiming timing_flow;
//#define FLOW_PIN 16 //move to platformio.ini
uint16_t flow_counter=0; //maximum counts/s measured with Eden 128 Pump was 171
void IRAM_ATTR isr_flow();
unsigned long last_read_flow=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-06-25 19:10:12 +00:00
float flow;
uint32_t flow_counter_sum=0;
2023-04-17 19:32:34 +00:00
void flow_setup() {
2024-06-25 19:10:12 +00:00
timing_flow.minchange=0.0;
timing_flow.maxchange=0.3;
timing_flow.mintime=10*1000;
timing_flow.maxtime=30*60*1000;
2024-06-25 19:10:12 +00:00
2024-05-04 11:04:05 +00:00
2024-06-25 19:10:12 +00:00
pinMode(FLOW_PIN, INPUT_PULLUP);
attachInterrupt(FLOW_PIN, isr_flow, CHANGE);
2023-04-17 19:32:34 +00:00
}
void flow_loop(unsigned long loopmillis) {
2024-06-25 19:10:12 +00:00
if (loopmillis>=last_read_flow+READINTERVAL_FLOW) {
flow=flow_counter*1000.0/(loopmillis-last_read_flow)/2.0; //Frequency [Hz]
flow/=flow_factor; //[L/min]
2024-05-04 11:04:05 +00:00
2024-06-25 19:10:12 +00:00
flow_counter=0;
last_read_flow=loopmillis;
2024-05-04 11:04:05 +00:00
}
2023-04-17 19:32:34 +00:00
}
2024-06-25 19:10:12 +00:00
void IRAM_ATTR isr_flow() {
flow_counter++;
flow_counter_sum++;
2024-05-04 11:04:05 +00:00
}
2023-04-17 19:32:34 +00:00
#endif