AussieBruce
Member
Hi, I have input from an anemometer head to a Teensy 4.0, it's a squarewave ranging in frequency from a few Hz up to about 30 Hz. Checking the switching on a scope, there is debounce apparent, but it's all inside a 15 microsecond window. Using the usual debounce tools available, with the timer set to a number of milliseconds, would certainly skew the results at higher wind speeds. What I need is a debouncer that will deal with the transients and keep time skew down to around 50 microseconds. I'm hoping that the speed of the CPU will be in my favour.
Appreciate any suggestions, thanks in advance.
My loop function will be close to this.......
void loop() {
bool currentState = digitalRead(inputPin);
if (currentState != lastState && currentState == HIGH) {
unsigned long currentTime = micros();
period = currentTime - lastTime;
Dperiod = (double) period ;
Hz = 1000000.0 / Dperiod ;
Speed = Hz * 4.0 ;
lastTime = currentTime;
Serial.print("Speed: ");
Serial.print(Speed);
}
lastState = currentState;
}
Appreciate any suggestions, thanks in advance.
My loop function will be close to this.......
void loop() {
bool currentState = digitalRead(inputPin);
if (currentState != lastState && currentState == HIGH) {
unsigned long currentTime = micros();
period = currentTime - lastTime;
Dperiod = (double) period ;
Hz = 1000000.0 / Dperiod ;
Speed = Hz * 4.0 ;
lastTime = currentTime;
Serial.print("Speed: ");
Serial.print(Speed);
}
lastState = currentState;
}