73 lines
1.7 KiB
C
73 lines
1.7 KiB
C
#ifndef _FLOW_H_
|
|
#define _FLOW_H_
|
|
|
|
mqttValueTiming timing_flow_a;
|
|
mqttValueTiming timing_flow_b;
|
|
|
|
#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;
|
|
#define READINTERVAL_FLOW 10000
|
|
float flow_factor=7.5; //F=7.5*flowrate[L/min]
|
|
float flow_a;
|
|
float flow_b;
|
|
|
|
uint32_t flow_a_counter_sum=0;
|
|
uint32_t flow_b_counter_sum=0;
|
|
|
|
|
|
|
|
void flow_setup() {
|
|
|
|
timing_flow_a.minchange=0.0;
|
|
timing_flow_a.maxchange=0.3;
|
|
timing_flow_a.mintime=10*1000;
|
|
timing_flow_a.maxtime=30*60*1000;
|
|
|
|
timing_flow_b.minchange=0.0;
|
|
timing_flow_b.maxchange=0.3;
|
|
timing_flow_b.mintime=10*1000;
|
|
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);
|
|
}
|
|
|
|
void flow_loop(unsigned long loopmillis) {
|
|
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]
|
|
|
|
flow_b_counter=0;
|
|
last_read_flow_b=loopmillis;
|
|
}
|
|
}
|
|
|
|
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++;
|
|
}
|
|
|
|
|
|
#endif |