diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx
index f817973..aa749d9 100644
--- a/MDK-ARM/Project.uvoptx
+++ b/MDK-ARM/Project.uvoptx
@@ -305,7 +305,7 @@
- ..\..\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=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=864,64,1285,491,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=736,17,1330,768,0)(132=599,17,1193,768,0)(133=295,17,889,768,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
+ 25
+ 1
+ 134219120
+ 0
+ 0
+ 0
+ 0
+ 0
+ 1
+ F:\Etudes\4A\µC - Périphériques\Periph-Voilier\Services\Moteur.c
+
+ \\NUCLEO_F103RB\../Services/Moteur.c\25
+
+
0
@@ -362,7 +379,7 @@
1
0
- porta
+ My_GPIO_Init_Struct
0
@@ -411,13 +428,13 @@
0
- ((portb & 0x00000040) >> 6 & 0x40) >> 6
- 00008000000000000000000000000000E0FFEF400000000000000000000000000000000028706F7274622026203078303030303030343029203E3E2036000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000E03F0D00000000000000000000000000000000000000440E0008
+ ((porta & 0x00000002) >> 1 & 0x2) >> 1
+ 00800000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030303229203E3E2031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000001000000000000000000E03F0B00000000000000000000000000000000000000320F0008
1
- ((portb & 0x00000080) >> 7 & 0x80) >> 7
- 00000000000000000000000000000000E0FFEF400000000000000000000000000000000028706F7274622026203078303030303030383029203E3E2037000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000002000000000000000000E03F0D00000000000000000000000000000000000000040E0008
+ ((porta & 0x00000004) >> 2 & 0x4) >> 2
+ 00008000000000000000000000000000E0FFEF400100000000000000000000000000000028706F7274612026203078303030303030303429203E3E2032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000002000000000000000000E03F0B00000000000000000000000000000000000000320F0008
@@ -456,6 +473,18 @@
0
0
0
+
+ 2
+ 2
+ 1
+ 0
+ 0
+ 0
+ ..\Services\Moteur.c
+ Moteur.c
+ 0
+ 0
+
@@ -466,9 +495,9 @@
0
3
- 2
+ 3
1
- 1
+ 0
0
0
..\MyDrivers\MyTimer.c
@@ -478,9 +507,9 @@
3
- 3
+ 4
1
- 1
+ 0
0
0
..\MyDrivers\MyPWM.c
@@ -498,7 +527,7 @@
0
4
- 4
+ 5
1
0
0
@@ -510,7 +539,7 @@
4
- 5
+ 6
1
0
0
@@ -522,7 +551,7 @@
4
- 6
+ 7
1
0
0
@@ -534,7 +563,7 @@
4
- 7
+ 8
1
0
0
@@ -546,7 +575,7 @@
4
- 8
+ 9
1
0
0
@@ -566,7 +595,7 @@
0
5
- 9
+ 10
5
0
0
@@ -586,7 +615,7 @@
0
6
- 10
+ 11
1
0
0
@@ -606,7 +635,7 @@
0
7
- 11
+ 12
2
0
0
diff --git a/MDK-ARM/Project.uvprojx b/MDK-ARM/Project.uvprojx
index 8a6b949..59049c2 100644
--- a/MDK-ARM/Project.uvprojx
+++ b/MDK-ARM/Project.uvprojx
@@ -391,6 +391,13 @@
User Services
+
+
+ Moteur.c
+ 1
+ ..\Services\Moteur.c
+
+
MyDrivers
@@ -857,6 +864,13 @@
User Services
+
+
+ Moteur.c
+ 1
+ ..\Services\Moteur.c
+
+
MyDrivers
diff --git a/MyDrivers/MyPWM.h b/MyDrivers/MyPWM.h
index b3237c2..1905014 100644
--- a/MyDrivers/MyPWM.h
+++ b/MyDrivers/MyPWM.h
@@ -1,8 +1,7 @@
-#ifndef MYPWM_H
-#define MYPWM_H
+#ifndef PWM_H
+#define PWM_H
-#include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges
-#include "stm32f1xx_ll_tim.h"
+#include "stm32f103xb.h"
void MyPWM_Conf_Output(TIM_TypeDef * Timer, int channel);
diff --git a/Services/Moteur.c b/Services/Moteur.c
new file mode 100644
index 0000000..19640e9
--- /dev/null
+++ b/Services/Moteur.c
@@ -0,0 +1,80 @@
+
+#include "Moteur.h"
+#include "MyPWM.h"
+#include "MyTimer.h"
+
+#include "stm32f1xx_ll_bus.h"
+#include "stm32f1xx_ll_gpio.h"
+#include "stm32f1xx_ll_tim.h"
+
+
+void Moteur_Conf(void) {
+
+ //Fpwm = 10kHz = 72Mhz/(7200 = 0x1C20)
+ int Arr = 0x1C1F;
+ int Psc = 0x0;
+
+ //Activation horloge GPIO
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
+
+ //Config broche PA2 -> Sens
+ LL_GPIO_InitTypeDef My_GPIO_Init_Struct;
+
+ LL_GPIO_StructInit(&My_GPIO_Init_Struct);
+
+ My_GPIO_Init_Struct.Pin = PinSens;
+ My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_OUTPUT;
+ My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
+
+ LL_GPIO_Init(GPIOPins, &My_GPIO_Init_Struct);
+
+ //Config broche PA1 -> PWM
+ LL_GPIO_StructInit(&My_GPIO_Init_Struct);
+
+ My_GPIO_Init_Struct.Pin = LL_GPIO_PIN_1;
+ My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE;
+ My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
+
+ LL_GPIO_Init(GPIOA, &My_GPIO_Init_Struct);
+
+
+
+ //Activation horloge Timer
+ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
+
+ //Configuration initiale du Timer
+ MyTimer_Conf(TimerPWM, Arr, Psc);
+ //Configuration du Timer en PWM Output
+ MyPWM_Conf_Output(TimerPWM, channelPWM);
+
+ Moteur_Speed(0);
+ Moteur_Sens(0);
+
+}
+
+
+
+void Moteur_Speed(int speedPercentage) {
+ int Arr = 0x1C1F;
+
+ if(speedPercentage == 0) {
+ MyTimer_Stop(TimerPWM);
+ }
+ else {
+ MyTimer_Start(TimerPWM);
+ MyPWM_Set_Impulse_Duration(TimerPWM, Arr*speedPercentage/100, channelPWM);
+ }
+
+}
+
+
+void Moteur_Sens(int sens) {
+
+ if(sens == 0) {
+ LL_GPIO_ResetOutputPin(GPIOPins, PinSens);
+ }
+ else {
+ LL_GPIO_SetOutputPin(GPIOPins, PinSens);
+ }
+
+}
diff --git a/Services/Moteur.h b/Services/Moteur.h
new file mode 100644
index 0000000..32cdb88
--- /dev/null
+++ b/Services/Moteur.h
@@ -0,0 +1,18 @@
+#ifndef MOTEUR_H
+#define MOTEUR_H
+
+#include "stm32f103xb.h"
+
+#define PinSens LL_GPIO_PIN_2
+#define PinPWM LL_GPIO_PIN_1
+#define GPIOPins GPIOA
+#define TimerPWM TIM2
+#define channelPWM LL_TIM_CHANNEL_CH2
+
+void Moteur_Conf(void);
+
+void Moteur_Speed(int speedPercentage);
+
+void Moteur_Sens(int sens);
+
+#endif
diff --git a/Services/services.txt b/Services/services.txt
deleted file mode 100644
index 1698ef7..0000000
--- a/Services/services.txt
+++ /dev/null
@@ -1 +0,0 @@
-Mettre les services ici
\ No newline at end of file
diff --git a/Src/main.c b/Src/main.c
index 16ce13c..64a2b92 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -22,6 +22,7 @@
#include "stm32f1xx_ll_gpio.h"
#include "MyTimer.h"
#include "MyPWM.h"
+#include "Moteur.h"
void SystemClock_Config(void);
@@ -39,69 +40,25 @@ int main(void)
/* Configure the system clock to 72 MHz */
SystemClock_Config();
+ /*===Test Moteur===*/
- LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB);
- LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
- LL_GPIO_InitTypeDef My_GPIO_Init_Struct;
+ //INIT GPIO MARCHE PAS->PB PIN
+ Moteur_Conf();
- /*===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_Conf(Timer,0xFFAD,0x15);
-
- MyPWM_Conf_Input(Timer, channel1, channel2);
-
- int duty_cycle = 0;
+ Moteur_Speed(30);
+ Moteur_Sens(0);
/* Infinite loop */
- while (1)
+ for (int i =0; i<0xFFFF; i++)
{
- duty_cycle = MyPWM_Duty_Cycle_Permilles(Timer, channel1, channel2);
}
+
+ Moteur_Speed(60);
+ Moteur_Sens(1);
+
+ while (1)
+ {
+ }
}