Projet voilier 4IRA1 Arnaud Vergnet Marino Benassai Bastien Picco Yohan Simard
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DCMotor.c 1008B

123456789101112131415161718192021222324252627282930313233343536
  1. #include "DCMotor.h"
  2. #include "math.h"
  3. void DCMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin)
  4. {
  5. //On règle la vitesse en valeur absolue, ici à 0
  6. Timer_pwmo_conf(timer, channel, 50, 0);
  7. // Configuration du GPIO
  8. GPIO_conf(GPIOA, LL_GPIO_PIN_1, LL_GPIO_MODE_ALTERNATE, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_UP);
  9. //On règle le sens du moteur, ici sens direct (?)
  10. GPIO_conf(gpio, pin, LL_GPIO_MODE_OUTPUT, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_DOWN);
  11. GPIO_setPin(gpio, pin, 0);
  12. Timer_start(timer);
  13. }
  14. void DCMotor_setSpeed(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin, float speed)
  15. {
  16. const int dir = (speed > 0.) ? 1 : 0;
  17. Timer_pwmo_setDutyCycle(timer, channel, fabs(speed));
  18. GPIO_setPin(gpio, pin, dir);
  19. }
  20. float DCMotor_getSpeed(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin)
  21. {
  22. const float speedAbs = Timer_pwmo_getDutyCycle(timer, channel);
  23. const int dir = GPIO_readPin(gpio, pin);
  24. return dir ? speedAbs : -speedAbs;
  25. }