From 55ac60e080d214127a38ee58993dc024181c61d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Thu, 11 Aug 2022 14:11:13 +0200 Subject: [PATCH] app: fix motor speed and direction --- application.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/application.c b/application.c index 452271a..eb8b730 100644 --- a/application.c +++ b/application.c @@ -79,7 +79,7 @@ static bool drv8825_reached = false; /**< set when the goal is reached */ /** maximum speed (in steps/s) before the motor stalls (found empirically) * @note found empirically 300 @ 9V/180mA, 420 @ 12V/150mA */ -#define DRV8825_SPEED_LIMIT 420U +#define DRV8825_SPEED_LIMIT 600U // dials position info #define DIAL_SWITCH_PIN PB4 /**< pin connected to reed switch, connected to ground when the hour dial is nearby */ @@ -115,10 +115,10 @@ static void drv8825_speed(int16_t speed) drv8825_direction = 0; // remember we stopped } else { if (speed > 0) { - gpio_clear(GPIO_PORT(DRV8825_DIRECTION_PIN), GPIO_PIN(DRV8825_DIRECTION_PIN)); // set clockwise + gpio_set(GPIO_PORT(DRV8825_DIRECTION_PIN), GPIO_PIN(DRV8825_DIRECTION_PIN)); // set clockwise drv8825_direction = 1; // remember we go clockwise } else { - gpio_set(GPIO_PORT(DRV8825_DIRECTION_PIN), GPIO_PIN(DRV8825_DIRECTION_PIN)); // set counter-clockwise + gpio_clear(GPIO_PORT(DRV8825_DIRECTION_PIN), GPIO_PIN(DRV8825_DIRECTION_PIN)); // set counter-clockwise drv8825_direction = -1; // remember we go counter-clockwise speed = -speed; // get positive speed } @@ -961,6 +961,7 @@ void main(void) rcc_periph_clock_enable(GPIO_RCC(DRV8825_FAULT_PIN)); // enable clock for GPIO port peripheral gpio_mode_setup(GPIO_PORT(DRV8825_FAULT_PIN), GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO_PIN(DRV8825_FAULT_PIN)); // set GPIO to input and pull up (a 10 kOhm external pull-up resistor is still required, the internal is too weak) bool drv8825_fault = false; // if driver reported fault + gpio_set(GPIO_PORT(DRV8825_RESET_PIN), GPIO_PIN(DRV8825_RESET_PIN)); // power up driver puts_debug("OK\n"); puts_debug("setup dial position: ");