From 129f33c26ddc5f2929addad31a50d0410b9c102c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 8 Aug 2015 19:08:43 +1000 Subject: [PATCH] AP_RPM: define a minimum acceptable period for PWM input this will reject very short periods as invalid. This helps somewhat with noise on the line --- libraries/AP_RPM/RPM_PX4_PWM.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/AP_RPM/RPM_PX4_PWM.cpp b/libraries/AP_RPM/RPM_PX4_PWM.cpp index 4ee145eef8..5cc42380e7 100644 --- a/libraries/AP_RPM/RPM_PX4_PWM.cpp +++ b/libraries/AP_RPM/RPM_PX4_PWM.cpp @@ -34,6 +34,12 @@ extern const AP_HAL::HAL& hal; +/* + don't accept periods below 100us as it is probably ringing of the + signal. It would represent 600k RPM + */ +#define RPM_MIN_PERIOD_US 100 + /* open the sensor in constructor */ @@ -79,7 +85,7 @@ void AP_RPM_PX4_PWM::update(void) while (::read(_fd, &pwm, sizeof(pwm)) == sizeof(pwm)) { // the px4 pwm_input driver reports the period in microseconds - if (pwm.period > 0) { + if (pwm.period > RPM_MIN_PERIOD_US) { sum += (1.0e6f * 60) / pwm.period; count++; }