diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx index fc20bbe..633b71e 100644 --- a/MDK-ARM/Project.uvoptx +++ b/MDK-ARM/Project.uvoptx @@ -461,6 +461,18 @@ 0 0 0 + + 2 + 2 + 1 + 1 + 0 + 0 + ..\Services\Moteur.c + Moteur.c + 0 + 0 + @@ -471,9 +483,9 @@ 0 3 - 2 + 3 1 - 1 + 0 0 0 ..\MyDrivers\MyTimer.c @@ -483,9 +495,9 @@ 3 - 3 + 4 1 - 1 + 0 0 0 ..\MyDrivers\MyPWM.c @@ -503,7 +515,7 @@ 0 4 - 4 + 5 1 0 0 @@ -515,7 +527,7 @@ 4 - 5 + 6 1 0 0 @@ -527,7 +539,7 @@ 4 - 6 + 7 1 0 0 @@ -539,7 +551,7 @@ 4 - 7 + 8 1 0 0 @@ -551,7 +563,7 @@ 4 - 8 + 9 1 0 0 @@ -571,7 +583,7 @@ 0 5 - 9 + 10 5 0 0 @@ -591,7 +603,7 @@ 0 6 - 10 + 11 1 0 0 @@ -611,7 +623,7 @@ 0 7 - 11 + 12 2 0 0 diff --git a/MDK-ARM/Project.uvprojx b/MDK-ARM/Project.uvprojx index 8a6b949..59049c2 100644 --- a/MDK-ARM/Project.uvprojx +++ b/MDK-ARM/Project.uvprojx @@ -391,6 +391,13 @@ User Services + + + Moteur.c + 1 + ..\Services\Moteur.c + + MyDrivers @@ -857,6 +864,13 @@ User Services + + + Moteur.c + 1 + ..\Services\Moteur.c + + MyDrivers diff --git a/Services/Moteur.c b/Services/Moteur.c new file mode 100644 index 0000000..69e5ca8 --- /dev/null +++ b/Services/Moteur.c @@ -0,0 +1,72 @@ +#include "Moteur.h" +#include "MyPWM.h" +#include "MyTimer.h" + +#include "stm32f1xx_ll_bus.h" +#include "stm32f1xx_ll_gpio.h" + +//Fpwm = 10kHz +static int Arr = 0x1C1F; +static int Psc = 0x0; + +void Moteur_Conf() { + + //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 = PinPWM; + My_GPIO_Init_Struct->Mode = LL_GPIO_MODE_ALTERNATE; + My_GPIO_Init_Struct->OutputType = LL_GPIO_OUTPUT_PUSHPULL; + + LL_GPIO_Init(GPIOPins, 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); + MyPWM_Set_Impulse_Duration(TimerPWM, 0, channelPWM); + +} + + + +void Moteur_Speed(int speedPercentage) { + + 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); + } + +} \ No newline at end of file diff --git a/Services/Moteur.h b/Services/Moteur.h new file mode 100644 index 0000000..f49a42c --- /dev/null +++ b/Services/Moteur.h @@ -0,0 +1,6 @@ + +#define PinSens LL_GPIO_PIN_2 +#define PinPWM LL_GPIO_PIN_1 +#define GPIOPins GPIOA +#define TimerPWM TIM2 +#define channelPWM LL_TIM_CHANNEL_CH2 diff --git a/Src/main.c b/Src/main.c index a621f57..519f827 100644 --- a/Src/main.c +++ b/Src/main.c @@ -22,6 +22,7 @@ #include "stm32f1xx_ll_gpio.h" #include "MyTimer.h" #include "MyPWM.h" +#include "Moteur.h" void SystemClock_Config(void);