Browse Source

PWM input

Neluji 3 years ago
parent
commit
11a7310a43
6 changed files with 57 additions and 20 deletions
  1. 9
    2
      MDK-ARM/Project.uvoptx
  2. 23
    11
      MyDrivers/MyPWM.c
  3. 2
    2
      MyDrivers/MyPWM.h
  4. 1
    4
      MyDrivers/MyTimer.c
  5. 1
    1
      MyDrivers/MyTimer.h
  6. 21
    0
      Src/main.c

+ 9
- 2
MDK-ARM/Project.uvoptx View File

@@ -317,7 +317,7 @@
317 317
         <SetRegEntry>
318 318
           <Number>0</Number>
319 319
           <Key>DLGDARM</Key>
320
-          <Name>(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)</Name>
320
+          <Name>(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)</Name>
321 321
         </SetRegEntry>
322 322
         <SetRegEntry>
323 323
           <Number>0</Number>
@@ -378,7 +378,7 @@
378 378
         <AscS3>0</AscS3>
379 379
         <aSer3>0</aSer3>
380 380
         <eProf>0</eProf>
381
-        <aLa>0</aLa>
381
+        <aLa>1</aLa>
382 382
         <aPa1>0</aPa1>
383 383
         <AscS4>0</AscS4>
384 384
         <aSer4>0</aSer4>
@@ -400,6 +400,13 @@
400 400
       <pszMrulep></pszMrulep>
401 401
       <pSingCmdsp></pSingCmdsp>
402 402
       <pMultCmdsp></pMultCmdsp>
403
+      <LogicAnalyzers>
404
+        <Wi>
405
+          <IntNumber>0</IntNumber>
406
+          <FirstString>((porta &amp; 0x00000100) &gt;&gt; 8 &amp; 0x100) &gt;&gt; 8</FirstString>
407
+          <SecondString>FF000000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303031303029203E3E2038000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000F03F1A00000000000000000000000000000000000000040C0008</SecondString>
408
+        </Wi>
409
+      </LogicAnalyzers>
403 410
       <DebugDescription>
404 411
         <Enable>1</Enable>
405 412
         <EnableFlashSeq>0</EnableFlashSeq>

+ 23
- 11
MyDrivers/MyPWM.c View File

@@ -2,36 +2,48 @@
2 2
 #include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges
3 3
 #include "stm32f1xx_ll_tim.h"
4 4
 
5
-//Seul le channel CH1 des timers sera utilisé
6
-int channel = LL_TIM_CHANNEL_CH1;
7
-
8
-void MyPWM_Conf_Output(TIM_TypeDef * Timer)
5
+void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel)
9 6
 {
10
-	//Activation du channel (CH1) pour le timer considéré
7
+	//Activation du channel pour le timer considéré
11 8
 	LL_TIM_CC_EnableChannel(Timer, channel);
12 9
 	
13 10
 	LL_TIM_OC_InitTypeDef My_LL_Tim_OC_Init_Struct;
14 11
 	
15 12
 	//Configuration du output channel en PWM
16 13
 	LL_TIM_OC_StructInit(&My_LL_Tim_OC_Init_Struct);
14
+	//Configure le mode de la PWM : PWM1 = 1 jusqu'à la CompareValue puis 0, PWM2 = l'inverse
17 15
 	My_LL_Tim_OC_Init_Struct.OCMode = LL_TIM_OCMODE_PWM1;
18 16
 	
19 17
 	LL_TIM_OC_Init(Timer,channel,&My_LL_Tim_OC_Init_Struct);
20 18
 }
21 19
 
22 20
 
23
-
24
-void MyPWM_Conf_Input(TIM_TypeDef * Timer)
21
+//Configurer obligatoirement les channels 1 et 2 sur IC1 et IC2 ou IC3 et IC4
22
+void MyPWM_Conf_Input(TIM_TypeDef * Timer, int channel1, int channel2)
25 23
 {
26
-	//Activation du channel (CH1) pour le timer considéré
27
-	LL_TIM_CC_EnableChannel(Timer, channel);
24
+	//Activation des 2 channels pour le timer considéré
25
+	LL_TIM_CC_EnableChannel(Timer, channel1);
26
+	LL_TIM_CC_EnableChannel(Timer, channel2);
28 27
 	
29 28
 	LL_TIM_IC_InitTypeDef My_LL_Tim_IC_Init_Struct;
30 29
 	
30
+	//Configuration du channel1 (front montant, mappé sur TI1 = valeurs par défaut)
31
+	LL_TIM_IC_StructInit(&My_LL_Tim_IC_Init_Struct);	
32
+	LL_TIM_IC_Init(Timer,channel1,&My_LL_Tim_IC_Init_Struct);
33
+	
34
+	//Configuration du channel2 (front descendant, mappé sur TI1 = valeurs modifiées)
31 35
 	LL_TIM_IC_StructInit(&My_LL_Tim_IC_Init_Struct);
32
-	//Compléter ici?!...
36
+		//Détection sur front descendant
37
+	My_LL_Tim_IC_Init_Struct.ICPolarity = LL_TIM_IC_POLARITY_FALLING;
38
+		//Mappage sur TI1
39
+	My_LL_Tim_IC_Init_Struct.ICActiveInput = LL_TIM_ACTIVEINPUT_INDIRECTTI;
40
+	LL_TIM_IC_Init(Timer,channel2,&My_LL_Tim_IC_Init_Struct);
41
+	
42
+	//Definition du trigger
43
+	LL_TIM_SetTriggerInput(Timer, LL_TIM_TS_TI1FP1);
33 44
 	
34
-	LL_TIM_IC_Init(Timer,channel,&My_LL_Tim_IC_Init_Struct);
45
+	//Configure le mode esclave en mode RESET
46
+	LL_TIM_SetSlaveMode(Timer, LL_TIM_SLAVEMODE_RESET);	
35 47
 }
36 48
 
37 49
 

+ 2
- 2
MyDrivers/MyPWM.h View File

@@ -2,8 +2,8 @@
2 2
 #include "stm32f1xx_ll_tim.h"
3 3
 
4 4
 
5
-void MyPWM_Conf_Output(TIM_TypeDef * Timer);
5
+void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel);
6 6
 
7
-void MyPWM_Conf_Input(TIM_TypeDef * Timer);
7
+void MyPWM_Conf_Input(TIM_TypeDef * Timer, int channel1, int channel2);
8 8
 
9 9
 void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, int Percentage);

+ 1
- 4
MyDrivers/MyTimer.c View File

@@ -32,7 +32,7 @@ void (*Ptr_ItFct_TIM4)(void);
32 32
 	*					int Psc   : valeur à placer dans PSC
33 33
   * @retval None
34 34
   */
35
-void MyTimer_Conf(TIM_TypeDef * Timer, int Period)
35
+void MyTimer_Conf(TIM_TypeDef * Timer, int Arr, int Psc)
36 36
 {
37 37
 	LL_TIM_InitTypeDef My_LL_Tim_Init_Struct;
38 38
 	
@@ -42,9 +42,6 @@ void MyTimer_Conf(TIM_TypeDef * Timer, int Period)
42 42
 	else if (Timer==TIM3) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
43 43
 	else  LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
44 44
 	
45
-	int Psc = (Period*72*1000000)/256 + 2;
46
-	int Arr = (Period*72*1000000)/Psc + 1;
47
-	
48 45
 	// chargement structure Arr, Psc, Up Count
49 46
 	My_LL_Tim_Init_Struct.Autoreload=Arr;
50 47
 	My_LL_Tim_Init_Struct.Prescaler=Psc;

+ 1
- 1
MyDrivers/MyTimer.h View File

@@ -18,7 +18,7 @@ Driver pour Timer 1 
18 18
 	*					int Psc   : valeur à placer dans PSC
19 19
   * @retval None
20 20
   */
21
-void MyTimer_Conf(TIM_TypeDef * Timer,int Period);
21
+void MyTimer_Conf(TIM_TypeDef * Timer, int Arr, int Psc);
22 22
 
23 23
 
24 24
 /**

+ 21
- 0
Src/main.c View File

@@ -19,6 +19,8 @@
19 19
 #include "stm32f1xx_ll_rcc.h" // utile dans la fonction SystemClock_Config
20 20
 #include "stm32f1xx_ll_utils.h"   // utile dans la fonction SystemClock_Config
21 21
 #include "stm32f1xx_ll_system.h" // utile dans la fonction SystemClock_Config
22
+#include "stm32f1xx_ll_gpio.h"
23
+#include "MyTimer.h"
22 24
 #include "MyPWM.h"
23 25
 
24 26
 void  SystemClock_Config(void);
@@ -36,6 +38,25 @@ int main(void)
36 38
 {
37 39
   /* Configure the system clock to 72 MHz */
38 40
   SystemClock_Config();
41
+	
42
+	MyTimer_Conf(TIM1,999, 719);
43
+	
44
+	MyPWM_Conf_Output(TIM1, LL_TIM_CHANNEL_CH1);
45
+	
46
+	MyPWM_Set_Impulse_Duration(TIM1, 25);
47
+	
48
+//	LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
49
+//	GPIO_TypeDef * GPIO;
50
+//	LL_GPIO_InitTypeDef My_GPIO_Init_Struct;	
51
+//	GPIO = GPIOA;
52
+//	My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_8;
53
+//	My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_OUTPUT;
54
+//	My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
55
+//	My_GPIO_Init_Struct.Speed = LL_GPIO_MODE_OUTPUT_10MHz;
56
+//	My_GPIO_Init_Struct.Pull = LL_GPIO_PULL_DOWN;
57
+//	LL_GPIO_Init(GPIO, &My_GPIO_Init_Struct);
58
+	
59
+	MyTimer_Start(TIM1);
39 60
   
40 61
   /* Infinite loop */
41 62
   while (1)

Loading…
Cancel
Save