75 lines
1.5 KiB
C
75 lines
1.5 KiB
C
#include "Moteur.h"
|
|
#include "MyPWM.h"
|
|
#include "MyTimer.h"
|
|
|
|
#include "stm32f1xx_ll_bus.h"
|
|
#include "stm32f1xx_ll_gpio.h"
|
|
|
|
//Fpwm = 10kHz
|
|
|
|
void Moteur_Conf(void) {
|
|
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 = LL_GPIO_PIN_2;
|
|
My_GPIO_Init_Struct->Mode = LL_GPIO_MODE_OUTPUT;
|
|
My_GPIO_Init_Struct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
|
|
LL_GPIO_Init(GPIOA, 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);
|
|
}
|
|
|
|
}
|