From b24d9812b42801f0fd8f4dd484319a85baed5ba8 Mon Sep 17 00:00:00 2001 From: Oskar Date: Tue, 25 Nov 2025 19:14:46 +0100 Subject: [PATCH] =?UTF-8?q?S=C3=A9ance=2025/11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Pilotes/Include/DriverGPIO.h | 0 Pilotes/Include/Girouette.h | 0 Pilotes/Include/IT.h | 0 Pilotes/Include/PWM.h | 0 Pilotes/Include/Servo.h | 0 Pilotes/Include/Timer.h | 0 Pilotes/Source/DriverGPIO.c | 5 ++++- Pilotes/Source/Girouette.c | 21 +++++++++++++++------ Pilotes/Source/IT.c | 0 Pilotes/Source/PWM.c | 0 Pilotes/Source/Servo.c | 12 ++++++++---- Pilotes/Source/Timer.c | 0 principal.c | 2 +- 13 files changed, 28 insertions(+), 12 deletions(-) mode change 100644 => 100755 Pilotes/Include/DriverGPIO.h mode change 100644 => 100755 Pilotes/Include/Girouette.h mode change 100644 => 100755 Pilotes/Include/IT.h mode change 100644 => 100755 Pilotes/Include/PWM.h mode change 100644 => 100755 Pilotes/Include/Servo.h mode change 100644 => 100755 Pilotes/Include/Timer.h mode change 100644 => 100755 Pilotes/Source/DriverGPIO.c mode change 100644 => 100755 Pilotes/Source/Girouette.c mode change 100644 => 100755 Pilotes/Source/IT.c mode change 100644 => 100755 Pilotes/Source/PWM.c mode change 100644 => 100755 Pilotes/Source/Servo.c mode change 100644 => 100755 Pilotes/Source/Timer.c diff --git a/Pilotes/Include/DriverGPIO.h b/Pilotes/Include/DriverGPIO.h old mode 100644 new mode 100755 diff --git a/Pilotes/Include/Girouette.h b/Pilotes/Include/Girouette.h old mode 100644 new mode 100755 diff --git a/Pilotes/Include/IT.h b/Pilotes/Include/IT.h old mode 100644 new mode 100755 diff --git a/Pilotes/Include/PWM.h b/Pilotes/Include/PWM.h old mode 100644 new mode 100755 diff --git a/Pilotes/Include/Servo.h b/Pilotes/Include/Servo.h old mode 100644 new mode 100755 diff --git a/Pilotes/Include/Timer.h b/Pilotes/Include/Timer.h old mode 100644 new mode 100755 diff --git a/Pilotes/Source/DriverGPIO.c b/Pilotes/Source/DriverGPIO.c old mode 100644 new mode 100755 index 84c8226..c88fdcf --- a/Pilotes/Source/DriverGPIO.c +++ b/Pilotes/Source/DriverGPIO.c @@ -56,16 +56,19 @@ GPIO -> CRH |= ( conf << shift_pin); } } } -int MyGPIO_Read(GPIO_TypeDef * GPIO, char GPIO_Pin){ +int MyGPIO_Read(GPIO_TypeDef * GPIO, char GPIO_Pin){ return(GPIO -> IDR & (1 << GPIO_Pin)); } + void MyGPIO_Set(GPIO_TypeDef * GPIO, char GPIO_Pin){ GPIO -> BSRR = (1< BSRR = (1<<(GPIO_Pin+16));//1 on reset zone } + void MyGPIO_Toggle(GPIO_TypeDef * GPIO, char GPIO_Pin){ GPIO -> ODR = GPIO -> ODR ^ (0x1 << GPIO_Pin); } diff --git a/Pilotes/Source/Girouette.c b/Pilotes/Source/Girouette.c old mode 100644 new mode 100755 index ebce7e4..7aa4e99 --- a/Pilotes/Source/Girouette.c +++ b/Pilotes/Source/Girouette.c @@ -6,9 +6,13 @@ #include // Pour abs() -#define POSITIONS 4*360 +#define POSITIONS (360*4) //0x5A0 void configEncoder(TIM_TypeDef * Timer){ + // Timer + EnableTimer(Timer); + + // Settings Timer -> CCMR1 |= TIM_CCMR1_CC1S; // TI1FP1 mapped on TI1 Timer -> CCMR1 |= TIM_CCMR1_CC2S; // TI1FP2 mapped on TI2 Timer -> CCER &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP); // TI1FP1 output non-inverted @@ -23,19 +27,24 @@ void configEncoder(TIM_TypeDef * Timer){ // GPIO MyGPIO_Init(GPIOA,0,In_Floating ); // GPIOA pin 0 in mode floating TIM2_CH1 MyGPIO_Init(GPIOA,1,In_Floating ); // GPIOA pin 1 in mode floating TIM2_CH2 - MyGPIO_Init(GPIOA,8,In_PullDown ); // GPIOA pin 7 in mode floating Index + MyGPIO_Init(GPIOA,8,In_PullDown ); // GPIOA pin 8 in mode floating Index } + int angleVent (TIM_TypeDef * Timer){ // Returner l'angle du vent - return((Timer -> CNT)/POSITIONS * 360); + int angle =(((Timer -> CNT*360)/POSITIONS )); + if (angle > 180){ + angle = 360 - angle; // Pour que l'angle soit entre 0 et 180 + } + return(angle); } int vent2voile(int angle){ // Conversion angle vent à angle voile - if(abs(angle) < 90){ - return 0; + if(angle < 45){ + return 0; // Les voiles restent immobiles } else{ - return(abs(angle)-90); + return(2*(angle-45)/3); // Augmentation linéaire } } diff --git a/Pilotes/Source/IT.c b/Pilotes/Source/IT.c old mode 100644 new mode 100755 diff --git a/Pilotes/Source/PWM.c b/Pilotes/Source/PWM.c old mode 100644 new mode 100755 diff --git a/Pilotes/Source/Servo.c b/Pilotes/Source/Servo.c old mode 100644 new mode 100755 index d8d4b6c..ad32f57 --- a/Pilotes/Source/Servo.c +++ b/Pilotes/Source/Servo.c @@ -2,18 +2,22 @@ #include "DriverGPIO.h" #include "PWM.h" #include "Timer.h" +#include "Accelerometre.h" +#include "Horloge.h" void Servo_Moteur(int angle, TIM_TypeDef * Timer, int Channel){ // Controle du moteur - int dutyCycle = (5* angle + 5*90)/90; - PWM_Set_DutyCycle(Timer, Channel, dutyCycle); + int dutyCycle = (5* angle + 5*90)/90; + Set_DutyCycle_PWM(TIM4, 3, dutyCycle); //On met Duty cycle à 2% et il reste autour de 90 deg } void initServo(TIM_TypeDef * Timer, int Channel){ // Config du moteur servo if (Timer == TIM4) { EnableTimer(TIM4); - MyTimer_Base_Init(TIM4, 20000 - 1, 71); //Claire m'a + MyTimer_Base_Init(TIM4, 20000 - 1, 71); + if (Channel == 3){ - MyGPIO_Init(GPIOB, 8, AltOut_Ppull); + MyGPIO_Init(GPIOB, 8, AltOut_Ppull); // Outut push pull alternate + MyTimer_PWM(TIM4, 3); //TIM4 CH3 pour PB8 } else{ //printf("Cet pilôte n'existe pas"); diff --git a/Pilotes/Source/Timer.c b/Pilotes/Source/Timer.c old mode 100644 new mode 100755 diff --git a/principal.c b/principal.c index 29eaa9d..f78a1df 100755 --- a/principal.c +++ b/principal.c @@ -27,7 +27,7 @@ int main ( void ){ while (1){ angleVentVar = angleVent(TIM2); // Récupérer l'angle de girouette angleVoileVar = vent2voile(angleVentVar); // Transformer l'angle de girouette au l'angle des voiles souhaités - Servo_Moteur(angleVoileVar, TIM1, 1); // Faire bouger le moteur servo + Servo_Moteur(angleVoileVar, TIM4, 3); // Faire bouger le moteur servo } };