Browse Source

Comment. + début mise en commun (GPIO)

Neluji 3 years ago
parent
commit
ebda31ee03

+ 22
- 10
MDK-ARM/Project.uvoptx View File

@@ -479,7 +479,7 @@
479 479
       <GroupNumber>2</GroupNumber>
480 480
       <FileNumber>4</FileNumber>
481 481
       <FileType>1</FileType>
482
-      <tvExp>1</tvExp>
482
+      <tvExp>0</tvExp>
483 483
       <tvExpOptDlg>0</tvExpOptDlg>
484 484
       <bDave2>0</bDave2>
485 485
       <PathWithFileName>..\Services\MySequencer.c</PathWithFileName>
@@ -523,7 +523,7 @@
523 523
       <GroupNumber>3</GroupNumber>
524 524
       <FileNumber>7</FileNumber>
525 525
       <FileType>1</FileType>
526
-      <tvExp>0</tvExp>
526
+      <tvExp>1</tvExp>
527 527
       <tvExpOptDlg>0</tvExpOptDlg>
528 528
       <bDave2>0</bDave2>
529 529
       <PathWithFileName>..\MyDrivers\MyUSART.c</PathWithFileName>
@@ -543,6 +543,18 @@
543 543
       <RteFlg>0</RteFlg>
544 544
       <bShared>0</bShared>
545 545
     </File>
546
+    <File>
547
+      <GroupNumber>3</GroupNumber>
548
+      <FileNumber>9</FileNumber>
549
+      <FileType>1</FileType>
550
+      <tvExp>0</tvExp>
551
+      <tvExpOptDlg>0</tvExpOptDlg>
552
+      <bDave2>0</bDave2>
553
+      <PathWithFileName>..\MyDrivers\GPIO.c</PathWithFileName>
554
+      <FilenameWithoutPath>GPIO.c</FilenameWithoutPath>
555
+      <RteFlg>0</RteFlg>
556
+      <bShared>0</bShared>
557
+    </File>
546 558
   </Group>
547 559
 
548 560
   <Group>
@@ -553,7 +565,7 @@
553 565
     <RteFlg>0</RteFlg>
554 566
     <File>
555 567
       <GroupNumber>4</GroupNumber>
556
-      <FileNumber>9</FileNumber>
568
+      <FileNumber>10</FileNumber>
557 569
       <FileType>1</FileType>
558 570
       <tvExp>0</tvExp>
559 571
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -565,7 +577,7 @@
565 577
     </File>
566 578
     <File>
567 579
       <GroupNumber>4</GroupNumber>
568
-      <FileNumber>10</FileNumber>
580
+      <FileNumber>11</FileNumber>
569 581
       <FileType>1</FileType>
570 582
       <tvExp>0</tvExp>
571 583
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -577,7 +589,7 @@
577 589
     </File>
578 590
     <File>
579 591
       <GroupNumber>4</GroupNumber>
580
-      <FileNumber>11</FileNumber>
592
+      <FileNumber>12</FileNumber>
581 593
       <FileType>1</FileType>
582 594
       <tvExp>0</tvExp>
583 595
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -589,7 +601,7 @@
589 601
     </File>
590 602
     <File>
591 603
       <GroupNumber>4</GroupNumber>
592
-      <FileNumber>12</FileNumber>
604
+      <FileNumber>13</FileNumber>
593 605
       <FileType>1</FileType>
594 606
       <tvExp>0</tvExp>
595 607
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -601,7 +613,7 @@
601 613
     </File>
602 614
     <File>
603 615
       <GroupNumber>4</GroupNumber>
604
-      <FileNumber>13</FileNumber>
616
+      <FileNumber>14</FileNumber>
605 617
       <FileType>1</FileType>
606 618
       <tvExp>0</tvExp>
607 619
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -621,7 +633,7 @@
621 633
     <RteFlg>0</RteFlg>
622 634
     <File>
623 635
       <GroupNumber>5</GroupNumber>
624
-      <FileNumber>14</FileNumber>
636
+      <FileNumber>15</FileNumber>
625 637
       <FileType>5</FileType>
626 638
       <tvExp>0</tvExp>
627 639
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -641,7 +653,7 @@
641 653
     <RteFlg>0</RteFlg>
642 654
     <File>
643 655
       <GroupNumber>6</GroupNumber>
644
-      <FileNumber>15</FileNumber>
656
+      <FileNumber>16</FileNumber>
645 657
       <FileType>1</FileType>
646 658
       <tvExp>0</tvExp>
647 659
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -661,7 +673,7 @@
661 673
     <RteFlg>0</RteFlg>
662 674
     <File>
663 675
       <GroupNumber>7</GroupNumber>
664
-      <FileNumber>16</FileNumber>
676
+      <FileNumber>17</FileNumber>
665 677
       <FileType>2</FileType>
666 678
       <tvExp>0</tvExp>
667 679
       <tvExpOptDlg>0</tvExpOptDlg>

+ 10
- 0
MDK-ARM/Project.uvprojx View File

@@ -432,6 +432,11 @@
432 432
               <FileType>1</FileType>
433 433
               <FilePath>..\MyDrivers\MySysTick.c</FilePath>
434 434
             </File>
435
+            <File>
436
+              <FileName>GPIO.c</FileName>
437
+              <FileType>1</FileType>
438
+              <FilePath>..\MyDrivers\GPIO.c</FilePath>
439
+            </File>
435 440
           </Files>
436 441
         </Group>
437 442
         <Group>
@@ -925,6 +930,11 @@
925 930
               <FileType>1</FileType>
926 931
               <FilePath>..\MyDrivers\MySysTick.c</FilePath>
927 932
             </File>
933
+            <File>
934
+              <FileName>GPIO.c</FileName>
935
+              <FileType>1</FileType>
936
+              <FilePath>..\MyDrivers\GPIO.c</FilePath>
937
+            </File>
928 938
           </Files>
929 939
         </Group>
930 940
         <Group>

+ 168
- 0
MyDrivers/GPIO.c View File

@@ -0,0 +1,168 @@
1
+#include "stm32f1xx_ll_gpio.h"
2
+#include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges
3
+#include "GPIO.h"
4
+
5
+
6
+void conf_GPIO_girouette(void){
7
+	
8
+	 //PA5,6,7
9
+	
10
+		//Définition
11
+
12
+    LL_GPIO_InitTypeDef My_LL_GPIO_Init_Struct;
13
+
14
+		//Initialisation
15
+	
16
+    LL_GPIO_StructInit(&My_LL_GPIO_Init_Struct);
17
+
18
+    //GPIOA - PIN 5 (INDEX)
19
+
20
+    My_LL_GPIO_Init_Struct.Mode=LL_GPIO_MODE_INPUT;
21
+    My_LL_GPIO_Init_Struct.Pin=LL_GPIO_PIN_5;
22
+    My_LL_GPIO_Init_Struct.Pull=LL_GPIO_PULL_DOWN;
23
+
24
+    LL_GPIO_Init(GPIOA,&My_LL_GPIO_Init_Struct);
25
+
26
+    //Initialisation
27
+
28
+    LL_GPIO_StructInit(&My_LL_GPIO_Init_Struct);
29
+
30
+    //GIOA - PIN 6 (CHA)
31
+
32
+    My_LL_GPIO_Init_Struct.Mode=LL_GPIO_MODE_INPUT;
33
+    My_LL_GPIO_Init_Struct.Pin=LL_GPIO_PIN_6;
34
+    My_LL_GPIO_Init_Struct.Pull=LL_GPIO_PULL_DOWN;
35
+
36
+    LL_GPIO_Init(GPIOA,&My_LL_GPIO_Init_Struct);
37
+
38
+    //Initialisation
39
+
40
+    LL_GPIO_StructInit(&My_LL_GPIO_Init_Struct);
41
+
42
+    //GPIOA - PIN 7 (CHB)
43
+
44
+    My_LL_GPIO_Init_Struct.Mode=LL_GPIO_MODE_INPUT;
45
+    My_LL_GPIO_Init_Struct.Pin=LL_GPIO_PIN_7;
46
+    My_LL_GPIO_Init_Struct.Pull=LL_GPIO_PULL_DOWN;
47
+
48
+    LL_GPIO_Init(GPIOA,&My_LL_GPIO_Init_Struct);
49
+		
50
+		//Initialisation
51
+
52
+    LL_GPIO_StructInit(&My_LL_GPIO_Init_Struct);
53
+
54
+
55
+		//GPIOA - PIN 8 (PWM)
56
+
57
+    My_LL_GPIO_Init_Struct.Mode=LL_GPIO_MODE_ALTERNATE;
58
+    My_LL_GPIO_Init_Struct.Pin=LL_GPIO_PIN_8;
59
+    My_LL_GPIO_Init_Struct.OutputType=LL_GPIO_OUTPUT_PUSHPULL;
60
+
61
+    LL_GPIO_Init(GPIOA,&My_LL_GPIO_Init_Struct);
62
+
63
+}
64
+
65
+void conf_GPIO_roulis(void){
66
+	
67
+	 //PC 0,1
68
+		
69
+		//Définition
70
+
71
+    LL_GPIO_InitTypeDef My_LL_GPIO_Init_Struct;
72
+
73
+		//Initialisation
74
+
75
+    LL_GPIO_StructInit(&My_LL_GPIO_Init_Struct);
76
+
77
+    //GPIOC - PIN 0
78
+
79
+    My_LL_GPIO_Init_Struct.Mode=LL_GPIO_MODE_ANALOG;
80
+    My_LL_GPIO_Init_Struct.Pin=LL_GPIO_PIN_0;
81
+    My_LL_GPIO_Init_Struct.Pull=LL_GPIO_PULL_DOWN;
82
+
83
+    LL_GPIO_Init(GPIOC,&My_LL_GPIO_Init_Struct);
84
+
85
+		//Initialisation
86
+
87
+    LL_GPIO_StructInit(&My_LL_GPIO_Init_Struct);
88
+
89
+    //GPIOC - PIN 1
90
+
91
+    My_LL_GPIO_Init_Struct.Mode=LL_GPIO_MODE_ANALOG;
92
+    My_LL_GPIO_Init_Struct.Pin=LL_GPIO_PIN_1;
93
+    My_LL_GPIO_Init_Struct.Pull=LL_GPIO_PULL_DOWN;
94
+
95
+    LL_GPIO_Init(GPIOC,&My_LL_GPIO_Init_Struct);
96
+		
97
+};
98
+
99
+void conf_GPIO_RF (void) {
100
+	
101
+	LL_GPIO_InitTypeDef My_GPIO_Init_Struct;
102
+	LL_GPIO_StructInit(&My_GPIO_Init_Struct);
103
+	
104
+	//RX : TIM4_CH1/2 (PWM In)
105
+	//PB.6 en floating input
106
+	My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_6;
107
+	LL_GPIO_Init(GPIOB, &My_GPIO_Init_Struct);
108
+	
109
+	//PB.7 en floating input
110
+	My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_7;
111
+	LL_GPIO_Init(GPIOB, &My_GPIO_Init_Struct);
112
+	
113
+	LL_GPIO_StructInit(&My_GPIO_Init_Struct);
114
+	
115
+	//TX : USART1 & Pin EN
116
+	//PA.9 en alternate output pp
117
+	My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_9;
118
+	My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE;
119
+	My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
120
+	LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct);
121
+	
122
+	//PA.11 en output pp
123
+	My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_11;
124
+	My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_OUTPUT;
125
+	My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
126
+	LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct);
127
+	
128
+}
129
+
130
+
131
+void conf_GPIO_Moteur (void) {
132
+	
133
+	LL_GPIO_InitTypeDef My_GPIO_Init_Struct;
134
+	LL_GPIO_StructInit(&My_GPIO_Init_Struct);
135
+	
136
+	//Pin Sens
137
+	//PA.2 en output pp
138
+	My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_2;
139
+	My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_OUTPUT;
140
+	My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
141
+	LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct);
142
+	
143
+	
144
+	LL_GPIO_StructInit(&My_GPIO_Init_Struct);
145
+	
146
+	//Vitesse : TIM2_CH2 (PWM)
147
+	//PA.1 en alternate pp
148
+	My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_1;
149
+	My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE;
150
+	My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
151
+	LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct);
152
+}
153
+
154
+
155
+
156
+void conf_GPIO(void){
157
+	
158
+	//Activation des horloges des GPIOS
159
+	LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
160
+	LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB);
161
+	LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC);
162
+	
163
+	conf_GPIO_girouette();
164
+	conf_GPIO_roulis();
165
+	conf_GPIO_Moteur();
166
+	conf_GPIO_RF();
167
+	
168
+}

+ 24
- 0
MyDrivers/GPIO.h View File

@@ -0,0 +1,24 @@
1
+#ifndef GPIO_H
2
+#define GPIO_H
3
+
4
+/*
5
+Configuration de toutes les broches utilisées par les différentes fonctions :
6
+- Moteur : PA.1 et PA.2
7
+- RF : PB.6, PB.7, PA.9 et PA.11
8
+- Accéléromètre : PC.0 et PC.1
9
+- Servo : PA.8
10
+- Girouette : PA.5, PA.6 et PA.7
11
+Manque PC.2 = adc batterie
12
+*/
13
+
14
+#include "stm32f103xb.h"
15
+
16
+/**
17
+	* @brief  Configure les broches selon leurs utilisations
18
+  * @note   Fonction à lancer en début de pgm.
19
+	* @param  None
20
+  * @retval None
21
+  */
22
+void conf_GPIO(void);
23
+
24
+#endif

+ 28
- 1
MyDrivers/MyPWM.h View File

@@ -1,15 +1,42 @@
1 1
 #ifndef MYPWM_H
2 2
 #define MYPWM_H
3 3
 
4
-#include "stm32f103xb.h"
4
+/*
5
+Driver pour la gestion de la PWM de Timers 1 à 4
6
+*/
5 7
 
8
+#include "stm32f103xb.h"
6 9
 
10
+/**
11
+	* @brief  Configure un signal PWM en mode Output
12
+	* @note   Penser à appeler Timer_Conf() de Timer.h avant !
13
+	* @param  1 timer, 1 channel
14
+	* @retval None
15
+	*/
7 16
 void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel);
8 17
 
18
+/**
19
+	* @brief  Configure un timer en mode PWM Input
20
+	* @note   Penser à appeler Timer_Conf() de Timer.h avant !
21
+	* @param  1 timer, 2 channels associés (1&2 ou 3&4)
22
+	* @retval None
23
+	*/
9 24
 void MyPWM_Conf_Input(TIM_TypeDef * Timer, int channel1, int channel2);
10 25
 
26
+/**
27
+	* @brief  Définit la durée de l'impulsion à l'état haut
28
+	* @note   Fct utilisée en émission
29
+	* @param  1 timer, la valeur de changement de la PWM, 1 channel associé au timer
30
+	* @retval None
31
+	*/
11 32
 void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, uint32_t CompareValue, int channel);
12 33
 
34
+/**
35
+	* @brief  Renvoie le duty cycle de la PWM en entrée
36
+	* @note   Fct utilisée en réception
37
+	* @param  1 timer et 2 channels associés (1&2 ou 3&4)
38
+	* @retval renvoie le duty cycle en pour mille pour améliorer la résolution
39
+	*/
13 40
 int MyPWM_Duty_Cycle_Permilles(TIM_TypeDef * Timer, int channel1, int channel2);
14 41
 
15 42
 #endif

+ 2
- 37
MyDrivers/MyUSART.c View File

@@ -3,12 +3,6 @@
3 3
 #include "stm32f1xx_ll_usart.h"
4 4
 
5 5
 
6
-/**
7
-	* @brief  Active l'horloge et règle les paramètres de transmission
8
-  * @note   Fonction à lancer avant toute autre.
9
-	* @param  USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
10
-  * @retval None
11
-  */
12 6
 void MyUSART_Conf(USART_TypeDef * USART, int TransferDir)
13 7
 {
14 8
 	LL_USART_InitTypeDef My_LL_USART_Init_Struct;
@@ -34,38 +28,9 @@ void MyUSART_Conf(USART_TypeDef * USART, int TransferDir)
34 28
 	LL_USART_Enable(USART);
35 29
 }
36 30
 
37
-/**
38
-	* @brief  Autorise les interruptions de TXE
39
-  * @note   
40
-	* @param  USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
41
-  * @retval None
42
-  */
43
-void MyUSART_IT_Enable(USART_TypeDef * USART)
44
-{
45
-	LL_USART_EnableIT_TXE(USART);
46
-}
47
-
48
-
49
-/**
50
-	* @brief  Interdit les interruptions de TXE
51
-  * @note   
52
-	* @param  USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
53
-  * @retval None
54
-  */
55
-void MyUSART_IT_Disable(USART_TypeDef * USART)
56
-{
57
-	LL_USART_DisableIT_TXE(USART);
58
-}
59
-
60 31
 
61
-/**
62
-	* @brief  Transmet 8bits de donnée
63
-  * @note   
64
-	* @param  USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
65
-  * @retval None
66
-  */
67
-void MyUSART_Transmit_Data_8b(USART_TypeDef * USART, int data)
32
+void MyUSART_Transmit_Data_8b(USART_TypeDef * USART, char data)
68 33
 {
69 34
 	LL_USART_TransmitData8(USART, data);
70
-	while (LL_USART_IsActiveFlag_TC(USART) != 1){}
35
+	while (LL_USART_IsActiveFlag_TC(USART) != 1){/*Attendre la fin de l'envoi*/}
71 36
 }

+ 5
- 21
MyDrivers/MyUSART.h View File

@@ -3,42 +3,26 @@
3 3
 
4 4
 /*
5 5
 Driver pour USART 1 à 3 du STM32F103RB
6
-
7 6
 */
8 7
 
9 8
 #include "stm32f103xb.h"
10 9
 
11 10
 /**
12 11
 	* @brief  Active l'horloge et règle les paramètres de transmission
13
-  * @note   Fonction à lancer avant toute autre.
14
-	* @param  USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
12
+  * @note   Fonction à lancer en début de pgm.
13
+	* @param  USART_TypeDef USART : indique l'usart à utiliser par le uC, USART1, USART2 ou USART3
15 14
   * @retval None
16 15
   */
17 16
 void MyUSART_Conf(USART_TypeDef * USART, int TransferDir);
18 17
 
19 18
 /**
20
-	* @brief  Autorise les interruptions de TXE
21
-  * @note   
22
-	* @param  USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
23
-  * @retval None
24
-  */
25
-void MyUSART_IT_Enable(USART_TypeDef * USART);
26
-
27
-/**
28
-	* @brief  Interdit les interruptions de TXE
29
-  * @note   
30
-	* @param  USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
31
-  * @retval None
32
-  */
33
-void MyUSART_IT_Disable(USART_TypeDef * USART);
34
-
35
-/**
36 19
 	* @brief  Transmet 8bits de donnée
37 20
   * @note   
38
-	* @param  USART_TypeDef UsDollar : indique le usart à utiliser par le uC, USART1, USART2 ou USART3
21
+	* @param  USART_TypeDef USART : indique l'usart à utiliser par le uC, USART1, USART2 ou USART3
22
+	* @param char data : la donnée sur 8bits à transmettre
39 23
   * @retval None
40 24
   */
41
-void MyUSART_Transmit_Data_8b(USART_TypeDef * USART, int data);
25
+void MyUSART_Transmit_Data_8b(USART_TypeDef * USART, char data);
42 26
 
43 27
 
44 28
 #endif

+ 101
- 0
Services/ADC_antichavirement.c View File

@@ -0,0 +1,101 @@
1
+#include "ADC_antichavirement.h"
2
+#include "Chrono.h"
3
+#include "MyTimer.h"
4
+#include "stm32f1xx_ll_bus.h"
5
+#include "stm32f1xx_ll_tim.h"
6
+#include "stm32f1xx_ll_adc.h"
7
+#include "stm32f1xx_ll_rcc.h"
8
+
9
+#define seuil_g_pos 1.0
10
+#define seuil_g_neg -1.0
11
+
12
+void conf_ADC (void) {
13
+	
14
+		//ADC_REG
15
+	
16
+		LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1);
17
+	
18
+		//Division pour etre < 14 MHz
19
+	
20
+		LL_RCC_SetADCClockSource(LL_RCC_ADC_CLKSRC_PCLK2_DIV_6);
21
+	
22
+		//Bit ADON à 1
23
+	
24
+		LL_ADC_Enable(ADC1);
25
+		
26
+		//Définition
27
+
28
+		LL_ADC_REG_InitTypeDef My_LL_ADC_REG_Init_Struct;
29
+
30
+		//Initialisation
31
+
32
+		LL_ADC_REG_StructInit(&My_LL_ADC_REG_Init_Struct);
33
+	
34
+    My_LL_ADC_REG_Init_Struct.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_1RANK  ;
35
+		
36
+		LL_ADC_StartCalibration(ADC1);
37
+
38
+		//Application a l'ADC1
39
+   
40
+		LL_ADC_REG_Init(ADC1,&My_LL_ADC_REG_Init_Struct);
41
+		
42
+		
43
+		//ADC Sampling Time
44
+
45
+		LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_10, LL_ADC_SAMPLINGTIME_239CYCLES_5);
46
+		LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_11, LL_ADC_SAMPLINGTIME_239CYCLES_5);		
47
+}
48
+
49
+
50
+uint32_t X;
51
+uint32_t Y;
52
+float rapport;
53
+
54
+float start_ADC (void) {
55
+	
56
+	//Conversion X
57
+		
58
+	LL_ADC_REG_SetSequencerRanks(ADC1,LL_ADC_REG_RANK_1,LL_ADC_CHANNEL_10);
59
+	
60
+	LL_ADC_Enable(ADC1);
61
+	
62
+	LL_ADC_REG_StartConversionSWStart(ADC1);
63
+		
64
+	while ( LL_ADC_IsActiveFlag_EOS(ADC1) == 0);
65
+	
66
+	X=LL_ADC_REG_ReadConversionData32(ADC1);
67
+	
68
+	
69
+	//Conversion Y
70
+	
71
+	LL_ADC_REG_SetSequencerRanks(ADC1,LL_ADC_REG_RANK_1,LL_ADC_CHANNEL_11);
72
+	
73
+	LL_ADC_Enable(ADC1);
74
+	
75
+	LL_ADC_REG_StartConversionSWStart(ADC1);
76
+		
77
+	while ( LL_ADC_IsActiveFlag_EOS(ADC1) == 0);
78
+	
79
+	Y=LL_ADC_REG_ReadConversionData32(ADC1);
80
+
81
+	
82
+	//Calcul rapport
83
+	
84
+	rapport = X/Y;
85
+	
86
+	return rapport;
87
+	
88
+}
89
+
90
+
91
+void antichavirement (float rapport) {
92
+	
93
+	if (rapport >= seuil_g_pos || rapport <= seuil_g_neg){
94
+		
95
+	//Voiles à 90°
96
+	MyPWM_Set_Impulse_Duration(TIM1,10000*10/100,LL_TIM_CHANNEL_CH1);
97
+		
98
+	}
99
+	
100
+	
101
+}

+ 1
- 25
Services/Moteur.c View File

@@ -14,31 +14,6 @@ void Moteur_Conf(void) {
14 14
 	int Arr = 0x1C1F;
15 15
 	int Psc = 0x0;
16 16
 	
17
-	//Activation horloge GPIO
18
-	LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
19
-	
20
-	//Config broche PA2 -> Sens
21
-	LL_GPIO_InitTypeDef My_GPIO_Init_Struct;
22
-	
23
-	LL_GPIO_StructInit(&My_GPIO_Init_Struct);
24
-	
25
-	My_GPIO_Init_Struct.Pin = PinSens;
26
-	My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_OUTPUT;
27
-	My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
28
-	
29
-	LL_GPIO_Init(GPIOPins, &My_GPIO_Init_Struct);
30
-	
31
-	//Config broche PA1 -> PWM
32
-	LL_GPIO_StructInit(&My_GPIO_Init_Struct);
33
-	
34
-	My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_1;
35
-	My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE;
36
-	My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
37
-	
38
-	LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct);
39
-	
40
-	
41
-	
42 17
 	//Activation horloge Timer
43 18
 	LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
44 19
 	
@@ -57,6 +32,7 @@ void Moteur_Conf(void) {
57 32
 void Moteur_Speed(int speedPercentage) {
58 33
 	int Arr = 0x1C1F;
59 34
 	
35
+	//Arrêt du Timer si pas de vitesse
60 36
 	if(speedPercentage == 0) {
61 37
 		MyTimer_Stop(TimerPWM);
62 38
 	}

+ 30
- 1
Services/Moteur.h View File

@@ -1,18 +1,47 @@
1 1
 #ifndef MOTEUR_H
2 2
 #define MOTEUR_H
3 3
 
4
+/*
5
+Driver permettant de contrôler le moteur CC qui fait tourner le plateau
6
+La définition des pins utilisées est faites dans un autre fichier (GPIO.c)
7
+Vitesse :
8
+	- Timer 2
9
+	- Channel 2
10
+	- Broche PA.1
11
+Sens :
12
+	- Broche PA.2
13
+*/
14
+
4 15
 #include "stm32f103xb.h" 
5 16
 
6 17
 #define PinSens LL_GPIO_PIN_2
7
-#define PinPWM LL_GPIO_PIN_1
8 18
 #define GPIOPins GPIOA
9 19
 #define TimerPWM TIM2
10 20
 #define channelPWM LL_TIM_CHANNEL_CH2
11 21
 
22
+
23
+/**
24
+	* @brief  Configure le moteur
25
+  * @note   À lancer en début de pgm
26
+	* @param  None 
27
+  * @retval None
28
+  */
12 29
 void Moteur_Conf(void);
13 30
 
31
+/**
32
+  * @brief  Définit la vitesse de rotation du plateau
33
+  * @note   
34
+  * @param  int speedPercentage : [0; 100] (%) de la vitesse max
35
+  * @retval None
36
+  */
14 37
 void Moteur_Speed(int speedPercentage);
15 38
 
39
+/**
40
+  * @brief  définit le sens de rotation du plateau
41
+  * @note   
42
+  * @param  int sens : 0 pour un sens, un int non nul pour l'autre ({0;1} attendu)
43
+  * @retval None
44
+  */
16 45
 void Moteur_Sens(int sens);
17 46
 
18 47
 #endif

+ 36
- 43
Services/MyRF.c View File

@@ -3,7 +3,6 @@
3 3
 #include "MyPWM.h"
4 4
 #include "MyUSART.h"
5 5
 
6
-#include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges
7 6
 #include "stm32f1xx_ll_tim.h"
8 7
 #include "stm32f1xx_ll_gpio.h"
9 8
 #include "stm32f1xx_ll_usart.h"
@@ -12,68 +11,58 @@
12 11
 void MyRF_Conf(void) {
13 12
 	
14 13
 	//RX
15
-	//Activation horloge du GPIO
16
-	LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB);
17
-	
18
-	LL_GPIO_InitTypeDef My_GPIO_Init_Struct;
19
-	LL_GPIO_StructInit(&My_GPIO_Init_Struct);
20
-	
21
-	//PB.6 en floating input
22
-	My_GPIO_Init_Struct.Pin = PinCH1;
23
-	LL_GPIO_Init(GPIOIn, &My_GPIO_Init_Struct);
24
-	
25
-	//PB.7 en floating input
26
-	My_GPIO_Init_Struct.Pin = PinCH2;
27
-	LL_GPIO_Init(GPIOIn, &My_GPIO_Init_Struct);
28
-	
29
-	
30
-	//Configuration et lancment du Timer PWM Input
14
+	//Configuration et lancement du Timer PWM Input
31 15
 	MyTimer_Conf(TimerCC,0xFFAD,0x15);
32 16
 	MyPWM_Conf_Input(TimerCC, channelCC1, channelCC2);
33 17
 	MyTimer_Start(TimerCC);
34 18
 	
35 19
 	//TX
36
-	//Activation horloge du GPIO
37
-	LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
38
-	
39
-	LL_GPIO_StructInit(&My_GPIO_Init_Struct);
40
-	
41
-	//PA.9 en alternate output pp
42
-	My_GPIO_Init_Struct.Pin = PinOut;
43
-	My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE;
44
-	My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
45
-	LL_GPIO_Init(GPIOOut, &My_GPIO_Init_Struct);
46
-	
47
-	//PA.11 en output pp
48
-	My_GPIO_Init_Struct.Pin = PinTXEn;
49
-	My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_OUTPUT;
50
-	My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
51
-	LL_GPIO_Init(GPIOOut, &My_GPIO_Init_Struct);
52
-
53 20
 	//Configuration de l'USART
54 21
 	MyUSART_Conf(USARTOut, TransferDirTX);
55 22
 	
56 23
 }
57 24
 
25
+
58 26
 int MyRF_Input_Duty_Cycle(void) {
59 27
 	int duty_cycle_RC = MyPWM_Duty_Cycle_Permilles(TimerCC, channelCC1, channelCC2);
28
+	//Seuil de +-10% autour de la valeur centrale
60 29
 	if (74<duty_cycle_RC && duty_cycle_RC<77) {
61 30
 		return 0;
62 31
 	}
63 32
 	else {
33
+		//Conversion : 50 à 100 => -100 à 100
64 34
 		return (duty_cycle_RC - 75) * 4;
65 35
 	}
66 36
 }
67 37
 
68
-void MyRF_Transmit_3s(void) {
38
+void MyRF_Transmit_3s(int bordage_pc, int angle_vent) {
69 39
 	
70
-	//Récupérer :
71
-	char bordage[3] = "";
72
-	char heure[2] = "xx";
73
-	char min[2] = "xx";
74
-	char sec[2] = "xx";
75
-	int allure_ref = 3;
40
+	//Conversion bordage int => chaîne de char
41
+	char bordage[3] = {bordage_pc/100+48,(bordage_pc%100-bordage_pc%10)/10+48,bordage_pc%100+48};
76 42
 	
43
+	//Conversion angle du vent int => dénomination de l'allure
44
+	int allure_ref;	
45
+	if(angle_vent <45) {
46
+		allure_ref = 0;
47
+	}
48
+	else if (angle_vent == 45) {
49
+		allure_ref = 1;
50
+	}
51
+	else if (angle_vent < 60) {
52
+		allure_ref = 2;
53
+	}
54
+	else if (angle_vent < 90) {
55
+		allure_ref = 3;
56
+	}
57
+	else if (angle_vent < 120) {
58
+		allure_ref = 4;
59
+	}
60
+	else if (angle_vent < 160) {
61
+		allure_ref = 5;
62
+	}
63
+	else {
64
+		allure_ref = 6;
65
+	}
77 66
 	char allure[7][16]= {"vent debout.",
78 67
 		"au plus près.",
79 68
 		"au près.",
@@ -82,12 +71,16 @@ void MyRF_Transmit_3s(void) {
82 71
 		"au grand largue.",
83 72
 		"au vent arrière."
84 73
 	};
74
+		
75
+	char heure[2] = "xx";
76
+	char min[2] = "xx";
77
+	char sec[2] = "xx";
78
+	
85 79
 	char data1[14] = "\" - Bordage : ";
86 80
 	char data2[24] = " === Le voilier navigue ";
87 81
 	
88 82
 	int i;
89
-	
90
-	
83
+
91 84
 	//Activation de l'émetteur RF
92 85
 	LL_GPIO_SetOutputPin(GPIOOut ,PinTXEn);
93 86
 	

+ 46
- 7
Services/MyRF.h View File

@@ -1,29 +1,68 @@
1 1
 #ifndef MYRF_H
2 2
 #define MYRF_H
3 3
 
4
+/*
5
+Driver permettant de communiquer via le module RF
6
+La définition des pins utilisées est faites dans un autre fichier (GPIO.c)
7
+RX :
8
+	- Timer 4
9
+	- Channels 1 et 2
10
+	- Broches PB.6 et PB.7
11
+TX :
12
+	- USART1
13
+	- Broche PA.9 (Données) et PA.11 (Enable)
14
+*/
15
+
4 16
 #include "stm32f103xb.h"
5 17
 
6
-#define PinCH1 LL_GPIO_PIN_6
7
-#define PinCH2 LL_GPIO_PIN_7
8
-#define PinOut LL_GPIO_PIN_9
9
-#define PinTXEn LL_GPIO_PIN_11
10
-#define GPIOIn GPIOB
11 18
 #define GPIOOut GPIOA
19
+#define PinTXEn LL_GPIO_PIN_11
12 20
 #define TimerCC TIM4
13 21
 #define channelCC1 LL_TIM_CHANNEL_CH1
14 22
 #define channelCC2 LL_TIM_CHANNEL_CH2
15 23
 #define USARTOut USART1
16 24
 #define TransferDirTX LL_USART_DIRECTION_TX
17 25
 
18
-
26
+/**
27
+	* @brief  Configure le module RF pour la RX et la TX (Timer4 en PWM In sur CH1/2 et USART1)
28
+  * @note		À lancer en début de pgm
29
+	* @note   Période TIM4 = 20ms, Transfer Dir USART = TX
30
+	* @param  None 
31
+  * @retval None
32
+  */
19 33
 void MyRF_Conf(void);
20 34
 
35
+/**
36
+	* @brief  Retourne le rapport cyclique de la PWM en provenance du récepteur RF
37
+	*	@note		Seuil de détection de +-10% autour du 0
38
+	* @param  None 
39
+  * @retval int : [-100; 100] pour correspondre à la plage du moteur
40
+  */
21 41
 int MyRF_Duty_Cycle_Moteur(void);
22 42
 
23
-void MyRF_Transmit_3s(void);
43
+/**
44
+	* @brief  Transmet un message via l'USART vers l'émetteur RF
45
+  * @note   Message : "<h>h<min>'<sec>" - Bordage : <bordage>%  === Le voilier navigue <allure>."
46
+	* @param  int bordage_pc : pourcentage du bordage des voiles [0; 100]
47
+	* @param	int angle_vent : angle du vent par rapport au bateau [0; 180]
48
+  * @retval None
49
+  */
50
+void MyRF_Transmit_3s(int bordage_pc, int angle_vent);
24 51
 
52
+/**
53
+	* @brief  Transmet un message via l'USART vers l'émetteur RF
54
+  * @note   Message : "/!\ BATTERIE FAIBLE /!\"
55
+	* @param  None 
56
+  * @retval None
57
+  */
25 58
 void MyRF_Transmit_Batterie_Faible(void);
26 59
 
60
+/**
61
+	* @brief  Transmet un message via l'USART vers l'émetteur RF
62
+  * @note   Message : "/!\ RISQUE DE CHAVIREMENT /!\"
63
+	* @param  None 
64
+  * @retval None
65
+  */
27 66
 void MyRF_Transmit_Limite_Roulis(void);
28 67
 
29 68
 #endif

+ 34
- 2
Services/MySequencer.c View File

@@ -1,7 +1,10 @@
1 1
 #include "MySequencer.h"
2 2
 #include "MySysTick.h"
3
+#include "Moteur.h"
4
+#include "MyRF.h"
5
+#include "girouette.h"
3 6
 
4
-
7
+int cnt_3sec = 0;
5 8
 
6 9
 void MySequencer_Conf(void) {
7 10
 	
@@ -11,6 +14,35 @@ void MySequencer_Conf(void) {
11 14
 	
12 15
 }
13 16
 
17
+
18
+/**
19
+	* @brief  Tâche à lancer toutes les 10ms
20
+	* @note   None
21
+	* @param  None 
22
+	* @retval None
23
+	*/
14 24
 void MySequencer_Task_10ms (void) {
15
-	__nop();
25
+	
26
+	//Incrémentation du compteur pour envoi toutes les 3 secondes
27
+	cnt_3sec++;
28
+	
29
+	//Transmission données toutes les 3 secondes
30
+	if(cnt_3sec == 300) {
31
+		MyRF_Transmit_3s((int)((Calcul_pourcentage_duree()-5.0)*20.0), (int)(Angle_Vent()));
32
+		cnt_3sec = 0;
33
+	}
34
+	
35
+	//Réglage sens et vitesse moteur
36
+	int Duty_Cycle = MyRF_Duty_Cycle_Moteur();
37
+	if (Duty_Cycle >= 0) {
38
+		Moteur_Speed(Duty_Cycle);
39
+		Moteur_Sens(1);
40
+	}
41
+	else {
42
+		Moteur_Speed(-Duty_Cycle);
43
+		Moteur_Sens(0);
44
+	}
45
+	
46
+	
47
+	
16 48
 }

+ 12
- 2
Services/MySequencer.h View File

@@ -1,10 +1,20 @@
1 1
 #ifndef MY_SEQ_H
2 2
 #define MY_SEQ_H
3 3
 
4
+/*
5
+Service qui gère le séquenceur principal du pgm
6
+Permet la mise à jour des différentes données du pgm
7
+S'appuie sur le SysTick, réglé pour interruption toutes les 10ms
8
+*/
9
+
4 10
 #include "stm32f103xb.h"
5 11
 
12
+/**
13
+	* @brief  configure un séquenceur qui s'exécute toutes les 10ms
14
+	* @note   Fct à lancer en début de programme
15
+	* @param  None 
16
+	* @retval None
17
+	*/
6 18
 void MySequencer_Conf(void);
7 19
 
8
-void MySequencer_Task_10ms (void);
9
-
10 20
 #endif

+ 248
- 0
Services/MyTimer.c View File

@@ -0,0 +1,248 @@
1
+// TOUT A FAIRE !! //
2
+
3
+/*
4
+ indispensable pour pouvoir adresser les registres des périphériques.
5
+ Rem : OBLIGATION d'utiliser les définitions utiles contenues dans ce fichier (ex : TIM_CR1_CEN, RCC_APB1ENR_TIM2EN ...)
6
+ pour une meilleure lisibilité du code.
7
+
8
+ Pour les masques, utiliser également les définitions proposée
9
+ Rappel : pour mettre à 1  , reg = reg | Mask (ou Mask est le représente le ou les bits à positionner à 1)
10
+				  pour mettre à 0  , reg = reg&~ Mask (ou Mask est le représente le ou les bits à positionner à 0)
11
+ 
12
+*/ 
13
+
14
+#include "MyTimer.h"
15
+#include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges
16
+#include "stm32f1xx_ll_tim.h" 
17
+
18
+
19
+// variable pointeur de fonction permettant de mémoriser le callback à appeler depuis
20
+// le handler d'IT
21
+void (*Ptr_ItFct_TIM1)(void); 
22
+void (*Ptr_ItFct_TIM2)(void); 
23
+void (*Ptr_ItFct_TIM3)(void); 
24
+void (*Ptr_ItFct_TIM4)(void); 
25
+
26
+
27
+
28
+
29
+/**
30
+	* @brief  Active l'horloge et règle l'ARR et le PSC du timer visé
31
+  * @note   Fonction à lancer avant toute autre. Le timer n'est pas encore lancé (voir MyTimerStart)
32
+	* @param  TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4
33
+	* 				int Arr   : valeur à placer dans ARR
34
+	*					int Psc   : valeur à placer dans PSC
35
+  * @retval None
36
+  */
37
+void MyTimer_Conf(TIM_TypeDef * Timer)
38
+{
39
+	LL_TIM_InitTypeDef My_LL_Tim_Init_Struct;
40
+	
41
+	// Validation horloge locale
42
+	if (Timer==TIM1) LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1);
43
+	else if (Timer==TIM2) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
44
+	else if (Timer==TIM3) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
45
+	else  LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
46
+	
47
+	// chargement structure Arr, Psc, Up Count
48
+	My_LL_Tim_Init_Struct.Autoreload=0xFFFF;
49
+	My_LL_Tim_Init_Struct.Prescaler=0;
50
+	My_LL_Tim_Init_Struct.ClockDivision=LL_TIM_CLOCKDIVISION_DIV1;
51
+	My_LL_Tim_Init_Struct.CounterMode=LL_TIM_COUNTERMODE_UP;
52
+	My_LL_Tim_Init_Struct.RepetitionCounter=0;
53
+	
54
+	LL_TIM_Init(Timer,&My_LL_Tim_Init_Struct);
55
+	
56
+
57
+	// Blocage IT
58
+	LL_TIM_DisableIT_UPDATE(Timer);
59
+	
60
+	
61
+	// Blocage Timer
62
+	LL_TIM_DisableCounter(Timer);
63
+		
64
+}
65
+
66
+//CONFIG Timer en compteur
67
+
68
+void MyTimer_girouette_Conf(void)
69
+{
70
+	
71
+	LL_TIM_ENCODER_InitTypeDef My_LL_Tim_Init_Struct;
72
+	
73
+	// Validation horloge locale
74
+  LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
75
+
76
+	LL_TIM_ENCODER_StructInit(&My_LL_Tim_Init_Struct);
77
+
78
+	LL_TIM_ENCODER_Init(TIM3, &My_LL_Tim_Init_Struct);
79
+	
80
+	// Réglage Timer 3
81
+	LL_TIM_SetAutoReload(TIM3,0xFFFF);
82
+	LL_TIM_SetPrescaler(TIM3,0);
83
+		
84
+}
85
+
86
+//CONFIG Timer en PWM
87
+
88
+void MyPWM_Conf_Output(TIM_TypeDef *TIMx, uint32_t Channel)
89
+{
90
+
91
+    LL_TIM_OC_InitTypeDef My_LL_Tim_OC_Init_Struct;
92
+
93
+    //Configuration du output channel en PWM
94
+    LL_TIM_OC_StructInit(&My_LL_Tim_OC_Init_Struct);
95
+    My_LL_Tim_OC_Init_Struct.OCMode = LL_TIM_OCMODE_PWM1;
96
+
97
+    LL_TIM_OC_Init(TIMx,Channel,&My_LL_Tim_OC_Init_Struct);
98
+
99
+		// Réglage Timer 
100
+		LL_TIM_SetAutoReload(TIMx,0x707F);
101
+		LL_TIM_SetPrescaler(TIMx,0x31);
102
+	
103
+		//Activation du channel (CH3) pour le timer considéré
104
+    LL_TIM_CC_EnableChannel(TIMx, Channel);
105
+}
106
+
107
+
108
+void MyPWM_Set_Impulse_Duration(TIM_TypeDef * Timer, int Percentage, int channel)
109
+{
110
+	static uint32_t Val_ARR;
111
+	static uint32_t CompareValue;
112
+	
113
+	Val_ARR = LL_TIM_GetAutoReload(Timer);
114
+	CompareValue = (Val_ARR * Percentage)/10000;
115
+	
116
+	if (channel==LL_TIM_CHANNEL_CH1) LL_TIM_OC_SetCompareCH1(Timer, CompareValue);
117
+	else if (channel==LL_TIM_CHANNEL_CH2) LL_TIM_OC_SetCompareCH2(Timer, CompareValue);
118
+	else if (channel==LL_TIM_CHANNEL_CH3) LL_TIM_OC_SetCompareCH3(Timer, CompareValue);
119
+	else  LL_TIM_OC_SetCompareCH4(Timer, CompareValue);
120
+}
121
+
122
+
123
+/**
124
+	* @brief  PWM servo moteur
125
+  * @note   
126
+	* @param  TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4
127
+  * @retval None
128
+  */
129
+
130
+void MyTimer_PWMservo_Conf(void)
131
+{
132
+	MyPWM_Conf_Output(TIM4, LL_TIM_CHANNEL_CH3);
133
+}
134
+
135
+/**
136
+	* @brief  Démarre le timer considéré
137
+  * @note   
138
+	* @param  TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4
139
+  * @retval None
140
+  */
141
+void MyTimer_Start(TIM_TypeDef * Timer)
142
+{
143
+		LL_TIM_EnableCounter(Timer);
144
+}
145
+
146
+/**
147
+	* @brief  Arrêt le timer considéré
148
+  * @note   
149
+	* @param  TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4
150
+  * @retval None
151
+  */
152
+void MyTimer_Stop(TIM_TypeDef * Timer)
153
+{
154
+	LL_TIM_DisableCounter(Timer);
155
+}
156
+
157
+
158
+/**
159
+	* @brief  Configure le Timer considéré en interruption sur débordement.
160
+  * @note   A ce stade, les interruptions ne sont pas validés (voir  MyTimer_IT_Enable )
161
+	* @param  TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4
162
+	* 				void (*IT_function) (void) : nom (adresse) de la fonction à lancer sur interruption
163
+	*         int Prio : priorité associée à l'interruption
164
+  * @retval None
165
+  */
166
+void MyTimer_IT_Conf(TIM_TypeDef * Timer, void (*IT_function) (void),int Prio)
167
+{
168
+	// affectation de la fonction
169
+	if (Timer==TIM1) Ptr_ItFct_TIM1=IT_function;
170
+	else if (Timer==TIM2)	Ptr_ItFct_TIM2=IT_function;
171
+	else if (Timer==TIM3)	Ptr_ItFct_TIM3=IT_function;
172
+	else  Ptr_ItFct_TIM4=IT_function;
173
+
174
+	
175
+	// Blocage IT (il faudra la débloquer voir fct suivante)
176
+	LL_TIM_DisableIT_UPDATE(Timer);
177
+	
178
+	// validation du canal NVIC
179
+	IRQn_Type TIM_irq;
180
+	
181
+	if (Timer==TIM1) TIM_irq=TIM1_UP_IRQn;
182
+	else if (Timer==TIM2)	TIM_irq=TIM2_IRQn;
183
+	else if (Timer==TIM3)	TIM_irq=TIM3_IRQn;
184
+	else 	TIM_irq=TIM4_IRQn;
185
+	
186
+	NVIC_SetPriority(TIM_irq, Prio);
187
+	NVIC_EnableIRQ(TIM_irq);
188
+
189
+	
190
+}
191
+
192
+
193
+/**
194
+	* @brief  Autorise les interruptions
195
+  * @note   
196
+	* @param  TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4
197
+  * @retval None
198
+  */
199
+void MyTimer_IT_Enable(TIM_TypeDef * Timer)
200
+{
201
+		LL_TIM_EnableIT_UPDATE(Timer);
202
+}
203
+
204
+
205
+/**
206
+	* @brief  Interdit les interruptions
207
+  * @note   
208
+	* @param  TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4
209
+  * @retval None
210
+  */
211
+void MyTimer_IT_Disable(TIM_TypeDef * Timer)
212
+{
213
+			LL_TIM_DisableIT_UPDATE(Timer); 
214
+}	
215
+
216
+
217
+/*
218
+============ LES INTERRUPTIONS =================================
219
+
220
+*/
221
+
222
+void TIM1_UP_IRQHandler(void)
223
+{
224
+	// rabaisser le flag d'IT
225
+	LL_TIM_ClearFlag_UPDATE(TIM1);
226
+	(*Ptr_ItFct_TIM1)();
227
+}	
228
+
229
+void TIM2_IRQHandler(void)
230
+{
231
+	// rabaisser le flag d'IT
232
+	LL_TIM_ClearFlag_UPDATE(TIM2);
233
+	(*Ptr_ItFct_TIM2)();
234
+}	
235
+
236
+void TIM3_IRQHandler(void)
237
+{
238
+	// rabaisser le flag d'IT
239
+	LL_TIM_ClearFlag_UPDATE(TIM3);
240
+	(*Ptr_ItFct_TIM3)();
241
+}	
242
+
243
+void TIM4_IRQHandler(void)
244
+{
245
+	// rabaisser le flag d'IT
246
+	LL_TIM_ClearFlag_UPDATE(TIM4);
247
+	(*Ptr_ItFct_TIM4)();
248
+}	

+ 113
- 0
Services/girouette.c View File

@@ -0,0 +1,113 @@
1
+#include "stm32f1xx_ll_gpio.h"
2
+#include "girouette.h"
3
+#include "MyTimer.h"
4
+#include "stm32f1xx_ll_bus.h"
5
+#include "stm32f1xx_ll_tim.h"
6
+#include "stm32f1xx_ll_adc.h"
7
+#include "stm32f1xx_ll_rcc.h"
8
+
9
+//Configuration de l'interruption exterieure
10
+void exti_ref(void){
11
+
12
+    LL_GPIO_AF_SetEXTISource(LL_GPIO_AF_EXTI_PORTA, LL_GPIO_AF_EXTI_LINE5);
13
+
14
+    AFIO->EXTICR[2] |= AFIO_EXTICR2_EXTI5_PA; 
15
+
16
+    EXTI->IMR |= EXTI_IMR_MR5_Msk;
17
+    EXTI->RTSR |= EXTI_RTSR_TR5_Msk;
18
+}
19
+
20
+//Configuration de l'interruption du NVIC
21
+void nvic_exti_conf(void){
22
+    NVIC->IP[23]=2<<4;
23
+    NVIC->ISER[0]=1<<23;
24
+}
25
+
26
+//redirection de l'interruption
27
+void EXTI9_5_IRQHandler(void){
28
+    //CNT A ZERO
29
+    LL_TIM_SetCounter(TIM3, 0);
30
+    //enlever le pin de pending en le mettant a 1
31
+    EXTI->PR |= EXTI_PR_PR5_Msk;
32
+}
33
+
34
+
35
+
36
+//configuration interruption + timer 3 en mode encodeur et 4 en mode PWM
37
+void conf_girouette(void){
38
+	
39
+		//interruption
40
+		exti_ref();
41
+		nvic_exti_conf();
42
+
43
+		
44
+		//Timer en mode encodeur
45
+    MyTimer_girouette_Conf();
46
+		
47
+		//Timer en mode PWM
48
+		MyPWM_Conf_Output(TIM1,LL_TIM_CHANNEL_CH1);
49
+		
50
+		//Activation Timer 1
51
+		LL_TIM_EnableAllOutputs(TIM1);
52
+
53
+}
54
+
55
+
56
+//Calcul position-angle
57
+
58
+float pos_Min=0;
59
+float pos_Max=135;
60
+float pos_actuelle;
61
+
62
+float duree_Min=1;
63
+float duree_Max=2;
64
+float duree_calc;
65
+
66
+float Periode=20;
67
+float Pourcentage_Min;
68
+float Pourcentage_Max;
69
+
70
+float Pourcentage_calc;
71
+
72
+float Calcul_pourcentage_duree (void){
73
+	
74
+	pos_actuelle=LL_TIM_GetCounter(TIM3);
75
+	
76
+	//Calcul pourcentage min et max
77
+	Pourcentage_Min=duree_Min/Periode;
78
+	Pourcentage_Max=duree_Max/Periode;
79
+	
80
+	//Calcul fctn affine
81
+	if (pos_actuelle <= 360){
82
+		if (pos_actuelle > 90 && pos_actuelle < 270) {
83
+			duree_calc=((duree_Max-duree_Min)/(pos_Max-pos_Min))*pos_actuelle+duree_Min;
84
+		}
85
+		else if (pos_actuelle > 270){
86
+			duree_calc=duree_Max;
87
+		}
88
+		else {
89
+			duree_calc=duree_Min;
90
+		}
91
+	}
92
+	
93
+	/*if (pos_actuelle > 360 && pos_actuelle < 720){
94
+		if (pos_actuelle > 450 && pos_actuelle < 630) {
95
+			duree_calc=((duree_Max-duree_Min)/(pos_Max-pos_Min))*(720-pos_actuelle)+duree_Min;
96
+		}
97
+		else if (pos_actuelle < 450){
98
+			duree_calc=duree_Max;
99
+		}
100
+		else {
101
+			duree_calc=duree_Min;
102
+		}
103
+	}*/
104
+	
105
+	//Calcul pourcentage
106
+	Pourcentage_calc=((Pourcentage_Max-Pourcentage_Min)/(duree_Max-duree_Min))*duree_calc;
107
+	
108
+ return Pourcentage_calc;
109
+}
110
+
111
+float Angle_Vent(void) {
112
+	return pos_actuelle/2.0;
113
+}

+ 4
- 4
Src/main.c View File

@@ -19,13 +19,12 @@
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"
24
-#include "MyPWM.h"
22
+
25 23
 #include "MyRF.h"
26 24
 #include "Moteur.h"
27
-#include "MySysTick.h"
28 25
 #include "MySequencer.h"
26
+#include "girouette.h"
27
+
29 28
 
30 29
 void  SystemClock_Config(void);
31 30
 
@@ -44,6 +43,7 @@ int main(void)
44 43
   SystemClock_Config();
45 44
 	
46 45
 	MyRF_Conf();
46
+	Moteur_Conf();
47 47
 	MySequencer_Conf();
48 48
   
49 49
   /* Infinite loop */

Loading…
Cancel
Save