38 lines
776 B
C
38 lines
776 B
C
#ifndef _FLOW_H_
|
|
#define _FLOW_H_
|
|
|
|
#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;
|
|
#define READINTERVAL_FLOW 1000
|
|
float flow_factor=7.5; //F=7.5*flowrate[L/min]
|
|
float flow;
|
|
|
|
uint32_t flow_counter_sum=0;
|
|
|
|
|
|
|
|
void flow_setup() {
|
|
|
|
pinMode(FLOW_PIN, INPUT_PULLUP);
|
|
attachInterrupt(FLOW_PIN, isr_flow, CHANGE);
|
|
}
|
|
|
|
void flow_loop(unsigned long loopmillis) {
|
|
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]
|
|
|
|
flow_counter=0;
|
|
last_read_flow=loopmillis;
|
|
}
|
|
}
|
|
|
|
void IRAM_ATTR isr_flow() {
|
|
flow_counter++;
|
|
flow_counter_sum++;
|
|
}
|
|
|
|
|
|
#endif |