Moteur_conf(), moteur_speed() et moteur_sens()
This commit is contained in:
parent
49f261078b
commit
506c519386
5 changed files with 117 additions and 12 deletions
|
@ -461,6 +461,18 @@
|
|||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>2</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\Services\Moteur.c</PathWithFileName>
|
||||
<FilenameWithoutPath>Moteur.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
|
@ -471,9 +483,9 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>2</FileNumber>
|
||||
<FileNumber>3</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\MyDrivers\MyTimer.c</PathWithFileName>
|
||||
|
@ -483,9 +495,9 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>3</FileNumber>
|
||||
<FileNumber>4</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\MyDrivers\MyPWM.c</PathWithFileName>
|
||||
|
@ -503,7 +515,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>4</FileNumber>
|
||||
<FileNumber>5</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -515,7 +527,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>5</FileNumber>
|
||||
<FileNumber>6</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -527,7 +539,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>6</FileNumber>
|
||||
<FileNumber>7</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -539,7 +551,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>7</FileNumber>
|
||||
<FileNumber>8</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -551,7 +563,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>8</FileNumber>
|
||||
<FileNumber>9</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -571,7 +583,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>9</FileNumber>
|
||||
<FileNumber>10</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -591,7 +603,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>10</FileNumber>
|
||||
<FileNumber>11</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -611,7 +623,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>7</GroupNumber>
|
||||
<FileNumber>11</FileNumber>
|
||||
<FileNumber>12</FileNumber>
|
||||
<FileType>2</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
|
|
@ -391,6 +391,13 @@
|
|||
</Group>
|
||||
<Group>
|
||||
<GroupName>User Services</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>Moteur.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Services\Moteur.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>MyDrivers</GroupName>
|
||||
|
@ -857,6 +864,13 @@
|
|||
</Group>
|
||||
<Group>
|
||||
<GroupName>User Services</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>Moteur.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Services\Moteur.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>MyDrivers</GroupName>
|
||||
|
|
72
Services/Moteur.c
Normal file
72
Services/Moteur.c
Normal file
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
6
Services/Moteur.h
Normal file
6
Services/Moteur.h
Normal file
|
@ -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
|
|
@ -22,6 +22,7 @@
|
|||
#include "stm32f1xx_ll_gpio.h"
|
||||
#include "MyTimer.h"
|
||||
#include "MyPWM.h"
|
||||
#include "Moteur.h"
|
||||
|
||||
void SystemClock_Config(void);
|
||||
|
||||
|
|
Loading…
Reference in a new issue