application: improve motor not spinning protection
This commit is contained in:
parent
c9e2f9ea93
commit
8096ae426b
|
@ -15,7 +15,7 @@
|
||||||
/** STM32F1 application example
|
/** STM32F1 application example
|
||||||
* @file application.c
|
* @file application.c
|
||||||
* @author King Kévin <kingkevin@cuvoodoo.info>
|
* @author King Kévin <kingkevin@cuvoodoo.info>
|
||||||
* @date 2016-2019
|
* @date 2016-2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* standard libraries */
|
/* standard libraries */
|
||||||
|
@ -458,6 +458,7 @@ void main(void)
|
||||||
printf("default");
|
printf("default");
|
||||||
}
|
}
|
||||||
bool tacho_safety = false; // if the motor is switched of for safety reasons
|
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);
|
printf("): %u\n", tacho_target);
|
||||||
|
|
||||||
// setup terminal
|
// setup terminal
|
||||||
|
@ -487,10 +488,12 @@ void main(void)
|
||||||
} else {
|
} else {
|
||||||
gpio_set(GPIO_PORT(SSR_PIN), GPIO_PIN(SSR_PIN)); // switch SSR off to cut power
|
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
|
tacho_safety = true; // turn safety on
|
||||||
gpio_set(GPIO_PORT(SSR_PIN), GPIO_PIN(SSR_PIN)); // switch SSR off to cut power
|
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("either the tachometer is defective, or the motor is stuck\n");
|
||||||
printf("switching the motor off for safety\n");
|
printf("switching the motor off for safety\n");
|
||||||
printf("reboot to retry\n");
|
printf("reboot to retry\n");
|
||||||
|
|
Loading…
Reference in New Issue