From 9c195f302037e1ac656a781caef8f33f667953ef Mon Sep 17 00:00:00 2001 From: Neluji <38362829+Neluji@users.noreply.github.com> Date: Wed, 4 Nov 2020 09:28:38 +0100 Subject: [PATCH 1/8] PWM init --- MyDrivers/MyPWM.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 MyDrivers/MyPWM.c diff --git a/MyDrivers/MyPWM.c b/MyDrivers/MyPWM.c new file mode 100644 index 0000000..1d8a357 --- /dev/null +++ b/MyDrivers/MyPWM.c @@ -0,0 +1,43 @@ +#include "MyPWM.h" +#include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges +#include "stm32f1xx_ll_tim.h" + +//Seul le channel CH1 des timers sera utilisé +int channel = LL_TIM_CHANNEL_CH1; + +void MyPWM_Conf_Output(TIM_TypeDef * Timer) +{ + //Activation du channel (CH1) pour le timer considéré + LL_TIM_CC_EnableChannel(Timer, channel); + + LL_TIM_OC_InitTypeDef My_LL_Tim_OC_Init_Struct; + + //Configuration du output channel en PWM + LL_TIM_OC_StructInit(&My_LL_Tim_OC_Init_Struct); + TIM_OC_InitStruct->OCMode = LL_TIM_OCMODE_PWM1; + + LL_TIM_OC_Init(Timer,channel,&My_LL_Tim_OC_Init_Struct); +} + + + +void MyPWM_Conf_Input(TIM_TypeDef * Timer) +{ + //Activation du channel (CH1) pour le timer considéré + LL_TIM_CC_EnableChannel(Timer, channel); + + LL_TIM_IC_InitTypeDef My_LL_Tim_IC_Init_Struct; + + LL_TIM_IC_StructInit(&My_LL_Tim_IC_Init_Struct); + //Compléter ici?!... + + LL_TIM_IC_Init(Timer,channel,&My_LL_Tim_IC_Init_Struct); +} + + +void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, int Percentage) +{ + uint32_t CompareValue = 0xFFFF * Percentage/100; + LL_TIM_OC_SetCompareCH1(Timer, CompareValue); +} + From 325154c16775cd58f37876baad543fc9c8f4fc09 Mon Sep 17 00:00:00 2001 From: Neluji <38362829+Neluji@users.noreply.github.com> Date: Wed, 4 Nov 2020 10:19:57 +0100 Subject: [PATCH 2/8] l.17 --- MDK-ARM/Project.uvoptx | 28 ++++++++++++++++++++-------- MDK-ARM/Project.uvprojx | 10 ++++++++++ MyDrivers/MyPWM.c | 2 +- MyDrivers/MyPWM.h | 9 +++++++++ Src/main.c | 1 + 5 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 MyDrivers/MyPWM.h diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx index dad60dc..7a44afb 100644 --- a/MDK-ARM/Project.uvoptx +++ b/MDK-ARM/Project.uvoptx @@ -456,6 +456,18 @@ 0 0 + + 3 + 3 + 1 + 1 + 0 + 0 + ..\MyDrivers\MyPWM.c + MyPWM.c + 0 + 0 + @@ -466,7 +478,7 @@ 0 4 - 3 + 4 1 0 0 @@ -478,7 +490,7 @@ 4 - 4 + 5 1 0 0 @@ -490,7 +502,7 @@ 4 - 5 + 6 1 0 0 @@ -502,7 +514,7 @@ 4 - 6 + 7 1 0 0 @@ -514,7 +526,7 @@ 4 - 7 + 8 1 0 0 @@ -534,7 +546,7 @@ 0 5 - 8 + 9 5 0 0 @@ -554,7 +566,7 @@ 0 6 - 9 + 10 1 0 0 @@ -574,7 +586,7 @@ 0 7 - 10 + 11 2 0 0 diff --git a/MDK-ARM/Project.uvprojx b/MDK-ARM/Project.uvprojx index cd43e32..a2a6b77 100644 --- a/MDK-ARM/Project.uvprojx +++ b/MDK-ARM/Project.uvprojx @@ -400,6 +400,11 @@ 1 ..\MyDrivers\MyTimer.c + + MyPWM.c + 1 + ..\MyDrivers\MyPWM.c + @@ -861,6 +866,11 @@ 1 ..\MyDrivers\MyTimer.c + + MyPWM.c + 1 + ..\MyDrivers\MyPWM.c + diff --git a/MyDrivers/MyPWM.c b/MyDrivers/MyPWM.c index 1d8a357..2765216 100644 --- a/MyDrivers/MyPWM.c +++ b/MyDrivers/MyPWM.c @@ -14,7 +14,7 @@ void MyPWM_Conf_Output(TIM_TypeDef * Timer) //Configuration du output channel en PWM LL_TIM_OC_StructInit(&My_LL_Tim_OC_Init_Struct); - TIM_OC_InitStruct->OCMode = LL_TIM_OCMODE_PWM1; + My_LL_Tim_OC_Init_Struct.OCMode = LL_TIM_OCMODE_PWM1; LL_TIM_OC_Init(Timer,channel,&My_LL_Tim_OC_Init_Struct); } diff --git a/MyDrivers/MyPWM.h b/MyDrivers/MyPWM.h new file mode 100644 index 0000000..da2ed82 --- /dev/null +++ b/MyDrivers/MyPWM.h @@ -0,0 +1,9 @@ +#include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges +#include "stm32f1xx_ll_tim.h" + + +void MyPWM_Conf_Output(TIM_TypeDef * Timer); + +void MyPWM_Conf_Input(TIM_TypeDef * Timer); + +void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, int Percentage); diff --git a/Src/main.c b/Src/main.c index 165d2e7..362e729 100644 --- a/Src/main.c +++ b/Src/main.c @@ -19,6 +19,7 @@ #include "stm32f1xx_ll_rcc.h" // utile dans la fonction SystemClock_Config #include "stm32f1xx_ll_utils.h" // utile dans la fonction SystemClock_Config #include "stm32f1xx_ll_system.h" // utile dans la fonction SystemClock_Config +#include "MyPWM.h" void SystemClock_Config(void); From 11a7310a434a9ab8441ed555ab2f6fcb6d69348d Mon Sep 17 00:00:00 2001 From: Neluji <38362829+Neluji@users.noreply.github.com> Date: Wed, 4 Nov 2020 12:06:23 +0100 Subject: [PATCH 3/8] PWM input --- MDK-ARM/Project.uvoptx | 11 +++++++++-- MyDrivers/MyPWM.c | 36 ++++++++++++++++++++++++------------ MyDrivers/MyPWM.h | 4 ++-- MyDrivers/MyTimer.c | 5 +---- MyDrivers/MyTimer.h | 2 +- Src/main.c | 21 +++++++++++++++++++++ 6 files changed, 58 insertions(+), 21 deletions(-) diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx index 7a44afb..463e23f 100644 --- a/MDK-ARM/Project.uvoptx +++ b/MDK-ARM/Project.uvoptx @@ -317,7 +317,7 @@ 0 DLGDARM - (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=98,107,519,534,0)(121=-1,-1,-1,-1,0)(122=674,103,1095,530,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=-1,-1,-1,-1,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0) + (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=98,107,519,534,0)(121=-1,-1,-1,-1,0)(122=674,103,1095,530,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=273,213,867,964,0)(131=-1,-1,-1,-1,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0) 0 @@ -378,7 +378,7 @@ 0 0 0 - 0 + 1 0 0 0 @@ -400,6 +400,13 @@ + + + 0 + ((porta & 0x00000100) >> 8 & 0x100) >> 8 + FF000000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303031303029203E3E2038000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000F03F1A00000000000000000000000000000000000000040C0008 + + 1 0 diff --git a/MyDrivers/MyPWM.c b/MyDrivers/MyPWM.c index 2765216..ae9b27d 100644 --- a/MyDrivers/MyPWM.c +++ b/MyDrivers/MyPWM.c @@ -2,36 +2,48 @@ #include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges #include "stm32f1xx_ll_tim.h" -//Seul le channel CH1 des timers sera utilisé -int channel = LL_TIM_CHANNEL_CH1; - -void MyPWM_Conf_Output(TIM_TypeDef * Timer) +void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel) { - //Activation du channel (CH1) pour le timer considéré + //Activation du channel pour le timer considéré LL_TIM_CC_EnableChannel(Timer, channel); LL_TIM_OC_InitTypeDef My_LL_Tim_OC_Init_Struct; //Configuration du output channel en PWM LL_TIM_OC_StructInit(&My_LL_Tim_OC_Init_Struct); + //Configure le mode de la PWM : PWM1 = 1 jusqu'à la CompareValue puis 0, PWM2 = l'inverse My_LL_Tim_OC_Init_Struct.OCMode = LL_TIM_OCMODE_PWM1; LL_TIM_OC_Init(Timer,channel,&My_LL_Tim_OC_Init_Struct); } - -void MyPWM_Conf_Input(TIM_TypeDef * Timer) +//Configurer obligatoirement les channels 1 et 2 sur IC1 et IC2 ou IC3 et IC4 +void MyPWM_Conf_Input(TIM_TypeDef * Timer, int channel1, int channel2) { - //Activation du channel (CH1) pour le timer considéré - LL_TIM_CC_EnableChannel(Timer, channel); + //Activation des 2 channels pour le timer considéré + LL_TIM_CC_EnableChannel(Timer, channel1); + LL_TIM_CC_EnableChannel(Timer, channel2); LL_TIM_IC_InitTypeDef My_LL_Tim_IC_Init_Struct; - LL_TIM_IC_StructInit(&My_LL_Tim_IC_Init_Struct); - //Compléter ici?!... + //Configuration du channel1 (front montant, mappé sur TI1 = valeurs par défaut) + LL_TIM_IC_StructInit(&My_LL_Tim_IC_Init_Struct); + LL_TIM_IC_Init(Timer,channel1,&My_LL_Tim_IC_Init_Struct); - LL_TIM_IC_Init(Timer,channel,&My_LL_Tim_IC_Init_Struct); + //Configuration du channel2 (front descendant, mappé sur TI1 = valeurs modifiées) + LL_TIM_IC_StructInit(&My_LL_Tim_IC_Init_Struct); + //Détection sur front descendant + My_LL_Tim_IC_Init_Struct.ICPolarity = LL_TIM_IC_POLARITY_FALLING; + //Mappage sur TI1 + My_LL_Tim_IC_Init_Struct.ICActiveInput = LL_TIM_ACTIVEINPUT_INDIRECTTI; + LL_TIM_IC_Init(Timer,channel2,&My_LL_Tim_IC_Init_Struct); + + //Definition du trigger + LL_TIM_SetTriggerInput(Timer, LL_TIM_TS_TI1FP1); + + //Configure le mode esclave en mode RESET + LL_TIM_SetSlaveMode(Timer, LL_TIM_SLAVEMODE_RESET); } diff --git a/MyDrivers/MyPWM.h b/MyDrivers/MyPWM.h index da2ed82..f96c348 100644 --- a/MyDrivers/MyPWM.h +++ b/MyDrivers/MyPWM.h @@ -2,8 +2,8 @@ #include "stm32f1xx_ll_tim.h" -void MyPWM_Conf_Output(TIM_TypeDef * Timer); +void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel); -void MyPWM_Conf_Input(TIM_TypeDef * Timer); +void MyPWM_Conf_Input(TIM_TypeDef * Timer, int channel1, int channel2); void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, int Percentage); diff --git a/MyDrivers/MyTimer.c b/MyDrivers/MyTimer.c index efd3cd5..6df39fe 100644 --- a/MyDrivers/MyTimer.c +++ b/MyDrivers/MyTimer.c @@ -32,7 +32,7 @@ void (*Ptr_ItFct_TIM4)(void); * int Psc : valeur à placer dans PSC * @retval None */ -void MyTimer_Conf(TIM_TypeDef * Timer, int Period) +void MyTimer_Conf(TIM_TypeDef * Timer, int Arr, int Psc) { LL_TIM_InitTypeDef My_LL_Tim_Init_Struct; @@ -42,9 +42,6 @@ void MyTimer_Conf(TIM_TypeDef * Timer, int Period) else if (Timer==TIM3) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3); else LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4); - int Psc = (Period*72*1000000)/256 + 2; - int Arr = (Period*72*1000000)/Psc + 1; - // chargement structure Arr, Psc, Up Count My_LL_Tim_Init_Struct.Autoreload=Arr; My_LL_Tim_Init_Struct.Prescaler=Psc; diff --git a/MyDrivers/MyTimer.h b/MyDrivers/MyTimer.h index 6daa6fc..4be9606 100644 --- a/MyDrivers/MyTimer.h +++ b/MyDrivers/MyTimer.h @@ -18,7 +18,7 @@ Driver pour Timer 1 * int Psc : valeur à placer dans PSC * @retval None */ -void MyTimer_Conf(TIM_TypeDef * Timer,int Period); +void MyTimer_Conf(TIM_TypeDef * Timer, int Arr, int Psc); /** diff --git a/Src/main.c b/Src/main.c index 362e729..7fd899f 100644 --- a/Src/main.c +++ b/Src/main.c @@ -19,6 +19,8 @@ #include "stm32f1xx_ll_rcc.h" // utile dans la fonction SystemClock_Config #include "stm32f1xx_ll_utils.h" // utile dans la fonction SystemClock_Config #include "stm32f1xx_ll_system.h" // utile dans la fonction SystemClock_Config +#include "stm32f1xx_ll_gpio.h" +#include "MyTimer.h" #include "MyPWM.h" void SystemClock_Config(void); @@ -36,6 +38,25 @@ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); + + MyTimer_Conf(TIM1,999, 719); + + MyPWM_Conf_Output(TIM1, LL_TIM_CHANNEL_CH1); + + MyPWM_Set_Impulse_Duration(TIM1, 25); + +// LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA); +// GPIO_TypeDef * GPIO; +// LL_GPIO_InitTypeDef My_GPIO_Init_Struct; +// GPIO = GPIOA; +// My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_8; +// My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_OUTPUT; +// My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; +// My_GPIO_Init_Struct.Speed = LL_GPIO_MODE_OUTPUT_10MHz; +// My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; +// LL_GPIO_Init(GPIO, &My_GPIO_Init_Struct); + + MyTimer_Start(TIM1); /* Infinite loop */ while (1) From 5c38d5e1da2f3127ffa2c5c3a7ed0a1870ddb537 Mon Sep 17 00:00:00 2001 From: Neluji <38362829+Neluji@users.noreply.github.com> Date: Wed, 4 Nov 2020 12:35:58 +0100 Subject: [PATCH 4/8] =?UTF-8?q?PWM=20fin=20s=C3=A9ance=209?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MDK-ARM/Project.uvoptx | 31 ++++++++++++++++++++++++++++--- MyDrivers/MyPWM.c | 20 ++++++++++---------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx index 463e23f..5f64448 100644 --- a/MDK-ARM/Project.uvoptx +++ b/MDK-ARM/Project.uvoptx @@ -317,7 +317,7 @@ 0 DLGDARM - (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=98,107,519,534,0)(121=-1,-1,-1,-1,0)(122=674,103,1095,530,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=273,213,867,964,0)(131=-1,-1,-1,-1,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0) + (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=752,104,972,564,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=98,107,519,534,0)(121=-1,-1,-1,-1,0)(122=674,103,1095,530,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=405,45,999,796,0)(131=-1,-1,-1,-1,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0) 0 @@ -350,7 +350,24 @@ -U-O142 -O2254 -S0 -C0 -A0 -N00("ARM CoreSight SW-DP") -D00(1BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM) - + + + 0 + 0 + 42 + 1 +
134221314
+ 0 + 0 + 0 + 0 + 0 + 1 + F:\Etudes\4A\µC - Périphériques\Periph-Voilier\Src\main.c + + \\NUCLEO_F103RB\../Src/main.c\42 +
+
0 @@ -358,6 +375,14 @@ time + + + 1 + 0 + 0x080005D3 + 0 + + 0 @@ -404,7 +429,7 @@ 0 ((porta & 0x00000100) >> 8 & 0x100) >> 8 - FF000000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303031303029203E3E2038000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000F03F1A00000000000000000000000000000000000000040C0008 + FF000000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303031303029203E3E2038000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000F03F1600000000000000000000000000000000000000040C0008 diff --git a/MyDrivers/MyPWM.c b/MyDrivers/MyPWM.c index ae9b27d..5af1892 100644 --- a/MyDrivers/MyPWM.c +++ b/MyDrivers/MyPWM.c @@ -3,10 +3,7 @@ #include "stm32f1xx_ll_tim.h" void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel) -{ - //Activation du channel pour le timer considéré - LL_TIM_CC_EnableChannel(Timer, channel); - +{ LL_TIM_OC_InitTypeDef My_LL_Tim_OC_Init_Struct; //Configuration du output channel en PWM @@ -15,16 +12,15 @@ void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel) My_LL_Tim_OC_Init_Struct.OCMode = LL_TIM_OCMODE_PWM1; LL_TIM_OC_Init(Timer,channel,&My_LL_Tim_OC_Init_Struct); + + //Activation du channel pour le timer considéré + LL_TIM_CC_EnableChannel(Timer, channel); } //Configurer obligatoirement les channels 1 et 2 sur IC1 et IC2 ou IC3 et IC4 void MyPWM_Conf_Input(TIM_TypeDef * Timer, int channel1, int channel2) -{ - //Activation des 2 channels pour le timer considéré - LL_TIM_CC_EnableChannel(Timer, channel1); - LL_TIM_CC_EnableChannel(Timer, channel2); - +{ LL_TIM_IC_InitTypeDef My_LL_Tim_IC_Init_Struct; //Configuration du channel1 (front montant, mappé sur TI1 = valeurs par défaut) @@ -43,7 +39,11 @@ void MyPWM_Conf_Input(TIM_TypeDef * Timer, int channel1, int channel2) LL_TIM_SetTriggerInput(Timer, LL_TIM_TS_TI1FP1); //Configure le mode esclave en mode RESET - LL_TIM_SetSlaveMode(Timer, LL_TIM_SLAVEMODE_RESET); + LL_TIM_SetSlaveMode(Timer, LL_TIM_SLAVEMODE_RESET); + + //Activation des 2 channels pour le timer considéré + LL_TIM_CC_EnableChannel(Timer, channel1); + LL_TIM_CC_EnableChannel(Timer, channel2); } From 6e1c2b1766d6201b5bd2477823fa0b0642298cb9 Mon Sep 17 00:00:00 2001 From: Neluji <38362829+Neluji@users.noreply.github.com> Date: Sat, 7 Nov 2020 19:09:20 +0100 Subject: [PATCH 5/8] Output ok, + choix canal pour Set_Impulse_Duration --- MDK-ARM/Project.uvoptx | 32 +++++++++------------------- MyDrivers/MyPWM.c | 7 +++++-- MyDrivers/MyPWM.h | 2 +- Src/main.c | 47 +++++++++++++++++++++++++++++------------- 4 files changed, 49 insertions(+), 39 deletions(-) diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx index 5f64448..5d99232 100644 --- a/MDK-ARM/Project.uvoptx +++ b/MDK-ARM/Project.uvoptx @@ -317,7 +317,7 @@ 0 DLGDARM - (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=752,104,972,564,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=98,107,519,534,0)(121=-1,-1,-1,-1,0)(122=674,103,1095,530,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=405,45,999,796,0)(131=-1,-1,-1,-1,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0) + (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=504,37,1150,710,0)(110=60,88,280,548,0)(111=752,104,972,564,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=273,112,694,539,0)(121=75,104,496,531,0)(122=674,103,1095,530,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=709,11,1303,762,0)(131=150,13,744,764,0)(132=599,52,1193,803,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0) 0 @@ -350,24 +350,7 @@ -U-O142 -O2254 -S0 -C0 -A0 -N00("ARM CoreSight SW-DP") -D00(1BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM) - - - 0 - 0 - 42 - 1 -
134221314
- 0 - 0 - 0 - 0 - 0 - 1 - F:\Etudes\4A\µC - Périphériques\Periph-Voilier\Src\main.c - - \\NUCLEO_F103RB\../Src/main.c\42 -
-
+ 0 @@ -379,7 +362,7 @@ 1 0 - 0x080005D3 + 0x04010001 0 @@ -428,8 +411,13 @@ 0 - ((porta & 0x00000100) >> 8 & 0x100) >> 8 - FF000000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303031303029203E3E2038000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000F03F1600000000000000000000000000000000000000040C0008 + ((porta & 0x00000080) >> 7 & 0x80) >> 7 + 00800000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030383029203E3E2037000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000E03F1800000000000000000000000000000000000000540E0008 + + + 1 + ((portb & 0x00000200) >> 9 & 0x200) >> 9 + 00000000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274622026203078303030303032303029203E3E2039000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000002000000000000000000E03F1800000000000000000000000000000000000000540E0008 diff --git a/MyDrivers/MyPWM.c b/MyDrivers/MyPWM.c index 5af1892..e456972 100644 --- a/MyDrivers/MyPWM.c +++ b/MyDrivers/MyPWM.c @@ -47,9 +47,12 @@ void MyPWM_Conf_Input(TIM_TypeDef * Timer, int channel1, int channel2) } -void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, int Percentage) +void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, int Percentage, int channel) { uint32_t CompareValue = 0xFFFF * Percentage/100; - LL_TIM_OC_SetCompareCH1(Timer, CompareValue); + if (channel==LL_TIM_CHANNEL_CH1) LL_TIM_OC_SetCompareCH1(Timer, CompareValue); + else if (channel==LL_TIM_CHANNEL_CH2) LL_TIM_OC_SetCompareCH2(Timer, CompareValue); + else if (channel==LL_TIM_CHANNEL_CH3) LL_TIM_OC_SetCompareCH3(Timer, CompareValue); + else LL_TIM_OC_SetCompareCH4(Timer, CompareValue); } diff --git a/MyDrivers/MyPWM.h b/MyDrivers/MyPWM.h index f96c348..d048d83 100644 --- a/MyDrivers/MyPWM.h +++ b/MyDrivers/MyPWM.h @@ -6,4 +6,4 @@ void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel); void MyPWM_Conf_Input(TIM_TypeDef * Timer, int channel1, int channel2); -void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, int Percentage); +void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, int Percentage, int channel); diff --git a/Src/main.c b/Src/main.c index 7fd899f..864acd0 100644 --- a/Src/main.c +++ b/Src/main.c @@ -39,24 +39,43 @@ int main(void) /* Configure the system clock to 72 MHz */ SystemClock_Config(); - MyTimer_Conf(TIM1,999, 719); + /*===Test Output===*/ - MyPWM_Conf_Output(TIM1, LL_TIM_CHANNEL_CH1); + TIM_TypeDef *Timer1 = TIM3; + int Channel1 = LL_TIM_CHANNEL_CH2; + TIM_TypeDef *Timer2 = TIM4; + int Channel2 = LL_TIM_CHANNEL_CH4; - MyPWM_Set_Impulse_Duration(TIM1, 25); + MyTimer_Conf(Timer1,0xFFFE, 0x72); + MyTimer_Conf(Timer2,0xFFFE, 0x72); -// LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA); -// GPIO_TypeDef * GPIO; -// LL_GPIO_InitTypeDef My_GPIO_Init_Struct; -// GPIO = GPIOA; -// My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_8; -// My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_OUTPUT; -// My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; -// My_GPIO_Init_Struct.Speed = LL_GPIO_MODE_OUTPUT_10MHz; -// My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; -// LL_GPIO_Init(GPIO, &My_GPIO_Init_Struct); + MyPWM_Conf_Output(Timer1, Channel1); + MyPWM_Conf_Output(Timer2, Channel2); - MyTimer_Start(TIM1); + MyPWM_Set_Impulse_Duration(Timer1, 25, Channel1); + MyPWM_Set_Impulse_Duration(Timer2, 75, Channel2); + + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA); + LL_GPIO_InitTypeDef My_GPIO_Init_Struct; + My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_7; + My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE; + My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + My_GPIO_Init_Struct.Speed = LL_GPIO_MODE_OUTPUT_2MHz; + My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; + LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct); + + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB); + My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_9; + My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE; + My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + My_GPIO_Init_Struct.Speed = LL_GPIO_MODE_OUTPUT_2MHz; + My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; + LL_GPIO_Init(GPIOB, &My_GPIO_Init_Struct); + + MyTimer_Start(Timer1); + MyTimer_Start(Timer2); + + /* Infinite loop */ while (1) From 49f261078b22c2858352c240ffc1f54bfcecb787 Mon Sep 17 00:00:00 2001 From: Neluji <38362829+Neluji@users.noreply.github.com> Date: Tue, 17 Nov 2020 08:30:41 +0100 Subject: [PATCH 6/8] changed set_imulse_duration parameters --- MDK-ARM/Project.uvoptx | 21 +++++++++++++-------- MDK-ARM/Project.uvprojx | 4 ++-- MyDrivers/MyPWM.c | 3 +-- MyDrivers/MyPWM.h | 2 +- Src/main.c | 10 ++++++++++ 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx index 5d99232..fc20bbe 100644 --- a/MDK-ARM/Project.uvoptx +++ b/MDK-ARM/Project.uvoptx @@ -300,12 +300,12 @@ 1 0 0 - 5 + 6 - + ..\..\inifiles\Simu_Pulse.ini @@ -317,7 +317,7 @@ 0 DLGDARM - (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=504,37,1150,710,0)(110=60,88,280,548,0)(111=752,104,972,564,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=273,112,694,539,0)(121=75,104,496,531,0)(122=674,103,1095,530,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=709,11,1303,762,0)(131=150,13,744,764,0)(132=599,52,1193,803,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0) + (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=504,37,1150,710,0)(110=60,88,280,548,0)(111=752,104,972,564,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=533,85,954,512,0)(121=892,96,1313,523,0)(122=674,103,1095,530,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=709,11,1303,762,0)(131=150,13,744,764,0)(132=599,17,1193,768,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0) 0 @@ -362,7 +362,7 @@ 1 0 - 0x04010001 + porta 0 @@ -412,12 +412,17 @@ 0 ((porta & 0x00000080) >> 7 & 0x80) >> 7 - 00800000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030383029203E3E2037000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000E03F1800000000000000000000000000000000000000540E0008 + 00800000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030383029203E3E2037000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000CDCCCCCCCCCCD43F1800000000000000000000000000000000000000540E0008 1 - ((portb & 0x00000200) >> 9 & 0x200) >> 9 - 00000000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274622026203078303030303032303029203E3E2039000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000002000000000000000000E03F1800000000000000000000000000000000000000540E0008 + (porta & 0x00000001) + 00000000000000000000000000000000E0FFEF400100000000000000000000000000000028706F72746120262030783030303030303031290000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000002000000000000000000D43F1800000000000000000000000000000000000000E20E0008 + + + 2 + ((portb & 0x00000040) >> 6 & 0x40) >> 6 + 00008000000000000000000000000000E0FFEF400000000000000000000000000000000028706F7274622026203078303030303030343029203E3E2036000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000003000000333333333333D73F1800000000000000000000000000000000000000440E0008 @@ -440,7 +445,7 @@ 1 1 1 - 1 + 0 0 0 ../Src/main.c diff --git a/MDK-ARM/Project.uvprojx b/MDK-ARM/Project.uvprojx index a2a6b77..8a6b949 100644 --- a/MDK-ARM/Project.uvprojx +++ b/MDK-ARM/Project.uvprojx @@ -600,11 +600,11 @@ 0 1 1 - 4107 + 4101 1 STLink\ST-LINKIII-KEIL_SWO.dll - + "" () diff --git a/MyDrivers/MyPWM.c b/MyDrivers/MyPWM.c index e456972..1b7de35 100644 --- a/MyDrivers/MyPWM.c +++ b/MyDrivers/MyPWM.c @@ -47,9 +47,8 @@ void MyPWM_Conf_Input(TIM_TypeDef * Timer, int channel1, int channel2) } -void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, int Percentage, int channel) +void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, uint32_t CompareValue, int channel) { - uint32_t CompareValue = 0xFFFF * Percentage/100; if (channel==LL_TIM_CHANNEL_CH1) LL_TIM_OC_SetCompareCH1(Timer, CompareValue); else if (channel==LL_TIM_CHANNEL_CH2) LL_TIM_OC_SetCompareCH2(Timer, CompareValue); else if (channel==LL_TIM_CHANNEL_CH3) LL_TIM_OC_SetCompareCH3(Timer, CompareValue); diff --git a/MyDrivers/MyPWM.h b/MyDrivers/MyPWM.h index d048d83..6702b92 100644 --- a/MyDrivers/MyPWM.h +++ b/MyDrivers/MyPWM.h @@ -6,4 +6,4 @@ void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel); void MyPWM_Conf_Input(TIM_TypeDef * Timer, int channel1, int channel2); -void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, int Percentage, int channel); +void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, uint32_t CompareValue, int channel); diff --git a/Src/main.c b/Src/main.c index 864acd0..a621f57 100644 --- a/Src/main.c +++ b/Src/main.c @@ -72,6 +72,16 @@ int main(void) My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; LL_GPIO_Init(GPIOB, &My_GPIO_Init_Struct); + My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_0; + My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_FLOATING; + My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; + LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct); + + My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_6; + My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_FLOATING; + My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; + LL_GPIO_Init(GPIOB, &My_GPIO_Init_Struct); + MyTimer_Start(Timer1); MyTimer_Start(Timer2); From 88050db15f7c6aec8dea10b46a81c290606c6deb Mon Sep 17 00:00:00 2001 From: Neluji <38362829+Neluji@users.noreply.github.com> Date: Sun, 22 Nov 2020 16:48:42 +0100 Subject: [PATCH 7/8] PWM input -> Duty_Cycle_Permilles --- MDK-ARM/Project.uvoptx | 13 ++----- MyDrivers/MyPWM.c | 8 ++++ MyDrivers/MyPWM.h | 7 ++++ Src/main.c | 87 ++++++++++++++++++++++++------------------ 4 files changed, 68 insertions(+), 47 deletions(-) diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx index fc20bbe..f817973 100644 --- a/MDK-ARM/Project.uvoptx +++ b/MDK-ARM/Project.uvoptx @@ -411,18 +411,13 @@ 0 - ((porta & 0x00000080) >> 7 & 0x80) >> 7 - 00800000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030383029203E3E2037000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000CDCCCCCCCCCCD43F1800000000000000000000000000000000000000540E0008 + ((portb & 0x00000040) >> 6 & 0x40) >> 6 + 00008000000000000000000000000000E0FFEF400000000000000000000000000000000028706F7274622026203078303030303030343029203E3E2036000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000E03F0D00000000000000000000000000000000000000440E0008 1 - (porta & 0x00000001) - 00000000000000000000000000000000E0FFEF400100000000000000000000000000000028706F72746120262030783030303030303031290000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000002000000000000000000D43F1800000000000000000000000000000000000000E20E0008 - - - 2 - ((portb & 0x00000040) >> 6 & 0x40) >> 6 - 00008000000000000000000000000000E0FFEF400000000000000000000000000000000028706F7274622026203078303030303030343029203E3E2036000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000003000000333333333333D73F1800000000000000000000000000000000000000440E0008 + ((portb & 0x00000080) >> 7 & 0x80) >> 7 + 00000000000000000000000000000000E0FFEF400000000000000000000000000000000028706F7274622026203078303030303030383029203E3E2037000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000002000000000000000000E03F0D00000000000000000000000000000000000000040E0008 diff --git a/MyDrivers/MyPWM.c b/MyDrivers/MyPWM.c index 1b7de35..a59d46a 100644 --- a/MyDrivers/MyPWM.c +++ b/MyDrivers/MyPWM.c @@ -55,3 +55,11 @@ void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, uint32_t CompareValue, int else LL_TIM_OC_SetCompareCH4(Timer, CompareValue); } +int MyPWM_Duty_Cycle_Permilles(TIM_TypeDef * Timer, int channel1, int channel2) { + if(channel1 == LL_TIM_CHANNEL_CH1 && channel2 == LL_TIM_CHANNEL_CH2) { + return LL_TIM_IC_GetCaptureCH2(Timer) / LL_TIM_IC_GetCaptureCH1(Timer) * 1000; + } + else { + return -1; + } +} diff --git a/MyDrivers/MyPWM.h b/MyDrivers/MyPWM.h index 6702b92..b3237c2 100644 --- a/MyDrivers/MyPWM.h +++ b/MyDrivers/MyPWM.h @@ -1,3 +1,6 @@ +#ifndef MYPWM_H +#define MYPWM_H + #include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges #include "stm32f1xx_ll_tim.h" @@ -7,3 +10,7 @@ void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel); void MyPWM_Conf_Input(TIM_TypeDef * Timer, int channel1, int channel2); void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, uint32_t CompareValue, int channel); + +int MyPWM_Duty_Cycle_Permilles(TIM_TypeDef * Timer, int channel1, int channel2); + +#endif diff --git a/Src/main.c b/Src/main.c index a621f57..16ce13c 100644 --- a/Src/main.c +++ b/Src/main.c @@ -39,57 +39,68 @@ int main(void) /* Configure the system clock to 72 MHz */ SystemClock_Config(); - /*===Test Output===*/ - - TIM_TypeDef *Timer1 = TIM3; - int Channel1 = LL_TIM_CHANNEL_CH2; - TIM_TypeDef *Timer2 = TIM4; - int Channel2 = LL_TIM_CHANNEL_CH4; - - MyTimer_Conf(Timer1,0xFFFE, 0x72); - MyTimer_Conf(Timer2,0xFFFE, 0x72); - - MyPWM_Conf_Output(Timer1, Channel1); - MyPWM_Conf_Output(Timer2, Channel2); - - MyPWM_Set_Impulse_Duration(Timer1, 25, Channel1); - MyPWM_Set_Impulse_Duration(Timer2, 75, Channel2); - - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA); - LL_GPIO_InitTypeDef My_GPIO_Init_Struct; - My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_7; - My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE; - My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - My_GPIO_Init_Struct.Speed = LL_GPIO_MODE_OUTPUT_2MHz; - My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; - LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct); LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB); - My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_9; - My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE; - My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - My_GPIO_Init_Struct.Speed = LL_GPIO_MODE_OUTPUT_2MHz; - My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; - LL_GPIO_Init(GPIOB, &My_GPIO_Init_Struct); + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA); + LL_GPIO_InitTypeDef My_GPIO_Init_Struct; - My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_0; - My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_FLOATING; - My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; - LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct); + /*===Test Output===*/ + +// TIM_TypeDef *Timer1 = TIM3; +// int Channel1 = LL_TIM_CHANNEL_CH2; +// TIM_TypeDef *Timer2 = TIM4; +// int Channel2 = LL_TIM_CHANNEL_CH4; +// +// MyTimer_Conf(Timer1,0xFFFE, 0x72); +// MyTimer_Conf(Timer2,0xFFFE, 0x72); +// +// MyPWM_Conf_Output(Timer1, Channel1); +// MyPWM_Conf_Output(Timer2, Channel2); +// +// MyPWM_Set_Impulse_Duration(Timer1, 25, Channel1); +// MyPWM_Set_Impulse_Duration(Timer2, 75, Channel2); +// +// My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_7; +// My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE; +// My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; +// My_GPIO_Init_Struct.Speed = LL_GPIO_MODE_OUTPUT_2MHz; +// My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; +// LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct); +// +// My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_9; +// My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE; +// My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; +// My_GPIO_Init_Struct.Speed = LL_GPIO_MODE_OUTPUT_2MHz; +// My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; +// LL_GPIO_Init(GPIOB, &My_GPIO_Init_Struct); +// +// MyTimer_Start(Timer1); +// MyTimer_Start(Timer2); + + /*===Test Input===*/ + + TIM_TypeDef *Timer = TIM4; + int channel1 = LL_TIM_CHANNEL_CH1; + int channel2 = LL_TIM_CHANNEL_CH2; My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_6; My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_FLOATING; My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; LL_GPIO_Init(GPIOB, &My_GPIO_Init_Struct); + + My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_7; + LL_GPIO_Init(GPIOB, &My_GPIO_Init_Struct); - MyTimer_Start(Timer1); - MyTimer_Start(Timer2); - - + MyTimer_Conf(Timer,0xFFAD,0x15); + + MyPWM_Conf_Input(Timer, channel1, channel2); + + int duty_cycle = 0; /* Infinite loop */ while (1) { + duty_cycle = MyPWM_Duty_Cycle_Permilles(Timer, channel1, channel2); } } From 04f1835265d189df24d4752b5a6284d651ccbe10 Mon Sep 17 00:00:00 2001 From: Neluji <38362829+Neluji@users.noreply.github.com> Date: Sun, 22 Nov 2020 16:48:42 +0100 Subject: [PATCH 8/8] PWM input -> Duty_Cycle_Permilles --- MDK-ARM/Project.uvoptx | 15 +++----- MyDrivers/MyPWM.c | 8 ++++ MyDrivers/MyPWM.h | 7 ++++ Src/main.c | 87 ++++++++++++++++++++++++------------------ 4 files changed, 69 insertions(+), 48 deletions(-) diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx index fc20bbe..6ad75e4 100644 --- a/MDK-ARM/Project.uvoptx +++ b/MDK-ARM/Project.uvoptx @@ -317,7 +317,7 @@ 0 DLGDARM - (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=504,37,1150,710,0)(110=60,88,280,548,0)(111=752,104,972,564,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=533,85,954,512,0)(121=892,96,1313,523,0)(122=674,103,1095,530,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=709,11,1303,762,0)(131=150,13,744,764,0)(132=599,17,1193,768,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0) + (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=504,37,1150,710,0)(110=60,88,280,548,0)(111=752,104,972,564,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=533,85,954,512,0)(121=684,17,1105,444,0)(122=674,103,1095,530,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=709,11,1303,762,0)(131=150,13,744,764,0)(132=599,17,1193,768,0)(133=112,9,706,760,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0) 0 @@ -411,18 +411,13 @@ 0 - ((porta & 0x00000080) >> 7 & 0x80) >> 7 - 00800000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030383029203E3E2037000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000CDCCCCCCCCCCD43F1800000000000000000000000000000000000000540E0008 + ((portb & 0x00000040) >> 6 & 0x40) >> 6 + 00008000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274622026203078303030303030343029203E3E2036000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000E03F0D00000000000000000000000000000000000000440E0008 1 - (porta & 0x00000001) - 00000000000000000000000000000000E0FFEF400100000000000000000000000000000028706F72746120262030783030303030303031290000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000002000000000000000000D43F1800000000000000000000000000000000000000E20E0008 - - - 2 - ((portb & 0x00000040) >> 6 & 0x40) >> 6 - 00008000000000000000000000000000E0FFEF400000000000000000000000000000000028706F7274622026203078303030303030343029203E3E2036000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000003000000333333333333D73F1800000000000000000000000000000000000000440E0008 + ((portb & 0x00000080) >> 7 & 0x80) >> 7 + 00000000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274622026203078303030303030383029203E3E2037000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000002000000000000000000E03F0D00000000000000000000000000000000000000040E0008 diff --git a/MyDrivers/MyPWM.c b/MyDrivers/MyPWM.c index 1b7de35..a59d46a 100644 --- a/MyDrivers/MyPWM.c +++ b/MyDrivers/MyPWM.c @@ -55,3 +55,11 @@ void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, uint32_t CompareValue, int else LL_TIM_OC_SetCompareCH4(Timer, CompareValue); } +int MyPWM_Duty_Cycle_Permilles(TIM_TypeDef * Timer, int channel1, int channel2) { + if(channel1 == LL_TIM_CHANNEL_CH1 && channel2 == LL_TIM_CHANNEL_CH2) { + return LL_TIM_IC_GetCaptureCH2(Timer) / LL_TIM_IC_GetCaptureCH1(Timer) * 1000; + } + else { + return -1; + } +} diff --git a/MyDrivers/MyPWM.h b/MyDrivers/MyPWM.h index 6702b92..b3237c2 100644 --- a/MyDrivers/MyPWM.h +++ b/MyDrivers/MyPWM.h @@ -1,3 +1,6 @@ +#ifndef MYPWM_H +#define MYPWM_H + #include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges #include "stm32f1xx_ll_tim.h" @@ -7,3 +10,7 @@ void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel); void MyPWM_Conf_Input(TIM_TypeDef * Timer, int channel1, int channel2); void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, uint32_t CompareValue, int channel); + +int MyPWM_Duty_Cycle_Permilles(TIM_TypeDef * Timer, int channel1, int channel2); + +#endif diff --git a/Src/main.c b/Src/main.c index a621f57..16ce13c 100644 --- a/Src/main.c +++ b/Src/main.c @@ -39,57 +39,68 @@ int main(void) /* Configure the system clock to 72 MHz */ SystemClock_Config(); - /*===Test Output===*/ - - TIM_TypeDef *Timer1 = TIM3; - int Channel1 = LL_TIM_CHANNEL_CH2; - TIM_TypeDef *Timer2 = TIM4; - int Channel2 = LL_TIM_CHANNEL_CH4; - - MyTimer_Conf(Timer1,0xFFFE, 0x72); - MyTimer_Conf(Timer2,0xFFFE, 0x72); - - MyPWM_Conf_Output(Timer1, Channel1); - MyPWM_Conf_Output(Timer2, Channel2); - - MyPWM_Set_Impulse_Duration(Timer1, 25, Channel1); - MyPWM_Set_Impulse_Duration(Timer2, 75, Channel2); - - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA); - LL_GPIO_InitTypeDef My_GPIO_Init_Struct; - My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_7; - My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE; - My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - My_GPIO_Init_Struct.Speed = LL_GPIO_MODE_OUTPUT_2MHz; - My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; - LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct); LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB); - My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_9; - My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE; - My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - My_GPIO_Init_Struct.Speed = LL_GPIO_MODE_OUTPUT_2MHz; - My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; - LL_GPIO_Init(GPIOB, &My_GPIO_Init_Struct); + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA); + LL_GPIO_InitTypeDef My_GPIO_Init_Struct; - My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_0; - My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_FLOATING; - My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; - LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct); + /*===Test Output===*/ + +// TIM_TypeDef *Timer1 = TIM3; +// int Channel1 = LL_TIM_CHANNEL_CH2; +// TIM_TypeDef *Timer2 = TIM4; +// int Channel2 = LL_TIM_CHANNEL_CH4; +// +// MyTimer_Conf(Timer1,0xFFFE, 0x72); +// MyTimer_Conf(Timer2,0xFFFE, 0x72); +// +// MyPWM_Conf_Output(Timer1, Channel1); +// MyPWM_Conf_Output(Timer2, Channel2); +// +// MyPWM_Set_Impulse_Duration(Timer1, 25, Channel1); +// MyPWM_Set_Impulse_Duration(Timer2, 75, Channel2); +// +// My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_7; +// My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE; +// My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; +// My_GPIO_Init_Struct.Speed = LL_GPIO_MODE_OUTPUT_2MHz; +// My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; +// LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct); +// +// My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_9; +// My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE; +// My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; +// My_GPIO_Init_Struct.Speed = LL_GPIO_MODE_OUTPUT_2MHz; +// My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; +// LL_GPIO_Init(GPIOB, &My_GPIO_Init_Struct); +// +// MyTimer_Start(Timer1); +// MyTimer_Start(Timer2); + + /*===Test Input===*/ + + TIM_TypeDef *Timer = TIM4; + int channel1 = LL_TIM_CHANNEL_CH1; + int channel2 = LL_TIM_CHANNEL_CH2; My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_6; My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_FLOATING; My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN; LL_GPIO_Init(GPIOB, &My_GPIO_Init_Struct); + + My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_7; + LL_GPIO_Init(GPIOB, &My_GPIO_Init_Struct); - MyTimer_Start(Timer1); - MyTimer_Start(Timer2); - - + MyTimer_Conf(Timer,0xFFAD,0x15); + + MyPWM_Conf_Input(Timer, channel1, channel2); + + int duty_cycle = 0; /* Infinite loop */ while (1) { + duty_cycle = MyPWM_Duty_Cycle_Permilles(Timer, channel1, channel2); } }