add anemometer interrupt debounce

This commit is contained in:
interfisch 2020-11-01 12:05:32 +01:00
parent 691c77ee98
commit e2005bbf84
2 changed files with 11 additions and 5 deletions

View File

@ -39,7 +39,7 @@ build_flags =
-D SENSOR_HS1101 -D SENSOR_HS1101
-D HS1101PIN=D5 -D HS1101PIN=D5
-D dataHS1101_minchange=2 -D dataHS1101_minchange=10
-D SENSOR_ML8511 -D SENSOR_ML8511
-D ML8511PIN=A0 -D ML8511PIN=A0
@ -47,9 +47,9 @@ build_flags =
-D SENSOR_ANEMOMETER -D SENSOR_ANEMOMETER
-D ANEMOMETERPIN=D6 #Light Blue thicker cable (in distribution box) -D ANEMOMETERPIN=D6 #Light Blue thicker cable (in distribution box)
-D dataAnemometer_minchange=0.5 -D dataAnemometer_minchange=5.0
-D dataAnemometer_readdelay=1000*10 -D dataAnemometer_readdelay=1000*30
-D dataAnemometer_senddelaymax=1000*60*2 -D dataAnemometer_senddelaymax=1000*60*5
# Cable from Anemometer: Black=GND, Blue=3v3, Brown=Signal (needs pullup (internal)) # Cable from Anemometer: Black=GND, Blue=3v3, Brown=Signal (needs pullup (internal))
lib_deps = lib_deps =

View File

@ -197,6 +197,9 @@ struct sensordata
#define ANEMOMETER_PPMtoMPS 0.0208640462; #define ANEMOMETER_PPMtoMPS 0.0208640462;
#define ANEMOMETER_DEBOUNCETIME 0.015 //0.015ms between pulses is approx 85m/s windspeed
unsigned long anemometer_lastpulse_fordebounce=0;
float value_anemometer=0; // [m/s] float value_anemometer=0; // [m/s]
void ICACHE_RAM_ATTR interrupt_anemometer(); void ICACHE_RAM_ATTR interrupt_anemometer();
@ -1171,7 +1174,10 @@ float getUV_ML8511(int pin) {
#ifdef SENSOR_ANEMOMETER #ifdef SENSOR_ANEMOMETER
void ICACHE_RAM_ATTR interrupt_anemometer() void ICACHE_RAM_ATTR interrupt_anemometer()
{ {
if (millis() - anemometer_lastpulse_fordebounce >= ANEMOMETER_DEBOUNCETIME) { //ignore if pulse came too fast
anemometer_pulsecounter++; anemometer_pulsecounter++;
anemometer_lastpulse_fordebounce=millis();
}
} }
#endif #endif