From 8096ae426b84fac311f93d984d2cf4f8f9d23fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Fri, 10 Jan 2020 11:10:58 +0100 Subject: [PATCH] application: improve motor not spinning protection --- application.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/application.c b/application.c index 81ce97b..cc97a6c 100644 --- a/application.c +++ b/application.c @@ -15,7 +15,7 @@ /** STM32F1 application example * @file application.c * @author King Kévin - * @date 2016-2019 + * @date 2016-2020 */ /* standard libraries */ @@ -458,6 +458,7 @@ void main(void) printf("default"); } bool tacho_safety = false; // if the motor is switched of for safety reasons + uint32_t tacho_activity = rtc_get_counter_val(); // when was the last time we saw the motor spinning printf("): %u\n", tacho_target); // setup terminal @@ -487,10 +488,12 @@ void main(void) } else { gpio_set(GPIO_PORT(SSR_PIN), GPIO_PIN(SSR_PIN)); // switch SSR off to cut power } - if (0 == tacho && rtc_get_counter_val() > time_start + 5 * RTC_TICKS) { // the motor does not seem to turn, after 5 s + if (tacho) { // we tachometer indicates the motor is spinning + tacho_activity = rtc_get_counter_val(); // updated the last time we saw it spinning + } else if (rtc_get_counter_val() > tacho_activity + 5 * RTC_TICKS) { // the motor does not seem to turn, after 5 s tacho_safety = true; // turn safety on gpio_set(GPIO_PORT(SSR_PIN), GPIO_PIN(SSR_PIN)); // switch SSR off to cut power - printf("tachometer does not indicate the motor is turning\n"); + printf("\ntachometer does not indicate the motor is turning\n"); printf("either the tachometer is defective, or the motor is stuck\n"); printf("switching the motor off for safety\n"); printf("reboot to retry\n");