Periph-Voilier/Services/Moteur.c
2020-11-24 19:52:32 +01:00

56 lines
968 B
C

#include "Moteur.h"
#include "MyPWM.h"
#include "MyTimer.h"
#include "stm32f1xx_ll_bus.h"
#include "stm32f1xx_ll_gpio.h"
#include "stm32f1xx_ll_tim.h"
void Moteur_Conf(void) {
//Fpwm = 10kHz = 72Mhz/(7200 = 0x1C20)
int Arr = 0x1C1F;
int Psc = 0x0;
//Activation horloge Timer
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
//Configuration initiale du Timer
MyTimer_Conf(TimerPWM, Arr, Psc);
//Configuration du Timer en PWM Output
MyPWM_Conf_Output(TimerPWM, channelPWM);
Moteur_Speed(0);
Moteur_Sens(0);
}
void Moteur_Speed(int speedPercentage) {
int Arr = 0x1C1F;
//Arrêt du Timer si pas de vitesse
if(speedPercentage == 0) {
MyTimer_Stop(TimerPWM);
}
else {
MyTimer_Start(TimerPWM);
MyPWM_Set_Impulse_Duration(TimerPWM, Arr*speedPercentage/100, channelPWM);
}
}
void Moteur_Sens(int sens) {
if(sens == 0) {
LL_GPIO_ResetOutputPin(GPIOPins, PinSens);
}
else {
LL_GPIO_SetOutputPin(GPIOPins, PinSens);
}
}