application: fix relay control
This commit is contained in:
parent
f10b43e732
commit
97c5faf5e5
|
@ -73,7 +73,7 @@ bool tacho_display = false; /**< if the current tachometer count should be displ
|
|||
#define TACHO_PIN PB11 /**< tachometer input on SWIM pin, pulled up to 3V3 by 680R */
|
||||
#define TACHO_TARGET_DEFAULT 20 /**< the default target tachometer count (slow for safety) */
|
||||
uint32_t tacho_target = TACHO_TARGET_DEFAULT; /**< the target tachometer count (switch SSR on when below, off when above) */
|
||||
#define SSR_PIN PB14 /**< pin to control the SSR (active low, open drain to 5V) */
|
||||
#define SSR_PIN PB14 /**< pin to control the SSR (SWDIO, active low, open drain to 5V) */
|
||||
|
||||
size_t putc(char c)
|
||||
{
|
||||
|
@ -429,7 +429,7 @@ void main(void)
|
|||
|
||||
printf("setup SSR: ");
|
||||
rcc_periph_clock_enable(GPIO_RCC(SSR_PIN)); // enable clock for GPIO peripheral
|
||||
gpio_set(GPIO_PORT(SSR_PIN), GPIO_PIN(TACHO_PIN)); // set high to switch off
|
||||
gpio_set(GPIO_PORT(SSR_PIN), GPIO_PIN(SSR_PIN)); // set high to switch off
|
||||
gpio_set_mode(GPIO_PORT(SSR_PIN), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO_PIN(SSR_PIN)); // set SSR - control pin to open drain. active low, connected to 5V on the + pin
|
||||
printf("OK\n");
|
||||
|
||||
|
@ -483,13 +483,13 @@ void main(void)
|
|||
led_toggle(); // toggle LED (good to indicate if main function is stuck)
|
||||
if (!tacho_safety) {
|
||||
if (tacho < tacho_target) {
|
||||
gpio_clear(GPIO_PORT(SSR_PIN), GPIO_PIN(TACHO_PIN)); // switch SSR on to provide power
|
||||
gpio_clear(GPIO_PORT(SSR_PIN), GPIO_PIN(SSR_PIN)); // switch SSR on to provide power
|
||||
} else {
|
||||
gpio_set(GPIO_PORT(SSR_PIN), GPIO_PIN(TACHO_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
|
||||
tacho_safety = true; // turn safety on
|
||||
gpio_set(GPIO_PORT(SSR_PIN), GPIO_PIN(TACHO_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("either the tachometer is defective, or the motor is stuck\n");
|
||||
printf("switching the motor off for safety\n");
|
||||
|
|
Loading…
Reference in New Issue