80 lines
1.6 KiB
C
80 lines
1.6 KiB
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 GPIO
|
|
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
|
|
|
|
//Config broche PA2 -> Sens
|
|
LL_GPIO_InitTypeDef My_GPIO_Init_Struct;
|
|
|
|
LL_GPIO_StructInit(&My_GPIO_Init_Struct);
|
|
|
|
My_GPIO_Init_Struct.Pin = PinSens;
|
|
My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_OUTPUT;
|
|
My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
|
|
LL_GPIO_Init(GPIOPins, &My_GPIO_Init_Struct);
|
|
|
|
//Config broche PA1 -> PWM
|
|
LL_GPIO_StructInit(&My_GPIO_Init_Struct);
|
|
|
|
My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_1;
|
|
My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE;
|
|
My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
|
|
LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct);
|
|
|
|
|
|
|
|
//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;
|
|
|
|
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);
|
|
}
|
|
|
|
}
|