hydroponic-controller/include/flow.h

45 lines
926 B
C
Raw Normal View History

2023-04-17 19:32:34 +00:00
#ifndef _FLOW_H_
#define _FLOW_H_
mqttValueTiming timing_flow;
2023-04-17 19:32:34 +00:00
#define FLOW_PIN 19
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]
float flow;
uint32_t flow_counter_sum=0;
void flow_setup() {
timing_flow.minchange=0.0;
2023-05-15 16:00:51 +00:00
timing_flow.maxchange=0.3;
timing_flow.mintime=10*000;
timing_flow.maxtime=30*60*1000;
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) {
2023-05-03 00:55:12 +00:00
if (loopmillis>=last_read_flow+READINTERVAL_FLOW) {
2023-04-17 19:32:34 +00:00
flow=flow_counter*1000.0/(loopmillis-last_read_flow)/2.0; //Frequency [Hz]
flow/=flow_factor; //[L/min]
flow_counter=0;
last_read_flow=loopmillis;
}
}
void IRAM_ATTR isr_flow() {
flow_counter++;
flow_counter_sum++;
}
#endif