From 1fbbaacfeaac0f7f0eb9ad8c9e5d20b6c6dfac76 Mon Sep 17 00:00:00 2001 From: Oskar Date: Mon, 24 Nov 2025 00:08:49 +0100 Subject: [PATCH] Moving functions to Girouette/Servo --- Pilotes/Include/DriverGPIO.h | 5 ++- Pilotes/Include/Girouette.h | 7 ++-- Pilotes/Include/MyTimer.h | 12 ------ Pilotes/Include/Nucleo.h | 8 ---- Pilotes/Include/PWM.h | 7 +++- Pilotes/Include/Timer.h | 10 ++--- Pilotes/Include/test.h | Bin 1024 -> 0 bytes Pilotes/Source/ADC.c | Bin 1024 -> 0 bytes Pilotes/Source/DriverGPIO.c | 2 +- Pilotes/Source/Girouette.c | 21 ++++------ Pilotes/Source/MyTimer.c | 39 ------------------ Pilotes/Source/Nucleo.c | 25 ------------ Pilotes/Source/PWM.c | 6 +-- Pilotes/Source/Timer.c | 77 +---------------------------------- principal.c | 62 ++++++++++++---------------- 15 files changed, 54 insertions(+), 227 deletions(-) delete mode 100644 Pilotes/Include/MyTimer.h delete mode 100644 Pilotes/Include/Nucleo.h delete mode 100644 Pilotes/Include/test.h delete mode 100644 Pilotes/Source/ADC.c delete mode 100644 Pilotes/Source/MyTimer.c delete mode 100644 Pilotes/Source/Nucleo.c diff --git a/Pilotes/Include/DriverGPIO.h b/Pilotes/Include/DriverGPIO.h index 3748ebf..b0d7acb 100644 --- a/Pilotes/Include/DriverGPIO.h +++ b/Pilotes/Include/DriverGPIO.h @@ -1,3 +1,5 @@ +#ifndef DRIVERGPIO_H_ +#define DRIVERGPIO_H_ #include "stm32f10x.h" #define In_Floating 0x4 #define In_PullDown 0x8 @@ -11,4 +13,5 @@ extern void MyGPIO_Init(GPIO_TypeDef * GPIO, char pin, char conf ); extern int MyGPIO_Read(GPIO_TypeDef * GPIO, char GPIO_Pin); // renvoie 0 ou autre chose different de 0 extern void MyGPIO_Set(GPIO_TypeDef * GPIO, char GPIO_Pin); extern void MyGPIO_Reset(GPIO_TypeDef * GPIO, char GPIO_Pin); -extern void MyGPIO_Toggle(GPIO_TypeDef * GPIO, char GPIO_Pin); \ No newline at end of file +extern void MyGPIO_Toggle(GPIO_TypeDef * GPIO, char GPIO_Pin); +#endif diff --git a/Pilotes/Include/Girouette.h b/Pilotes/Include/Girouette.h index 10e3205..2379b09 100644 --- a/Pilotes/Include/Girouette.h +++ b/Pilotes/Include/Girouette.h @@ -1,6 +1,7 @@ +#ifndef _GIROUETTE_H +#define _GIROUETTE_H #include "stm32f10x.h" extern void configEncoder(TIM_TypeDef * Timer); -extern void configChannel(); -extern int returnAngle (TIM_TypeDef * Timer); +extern int angleVent (TIM_TypeDef * Timer); extern int vent2voile(int angle); -extern void Servo_Moteur(int angle, TIM_TypeDef * Timer, int Channel); \ No newline at end of file +#endif diff --git a/Pilotes/Include/MyTimer.h b/Pilotes/Include/MyTimer.h deleted file mode 100644 index 012aa0d..0000000 --- a/Pilotes/Include/MyTimer.h +++ /dev/null @@ -1,12 +0,0 @@ -#include "stm32f10x.h" - -//TIMERS start -#define MyTimer_Base_Start(Timer) (Timer->CR1 |= TIM_CR1_CEN) -#define MyTimer_Base_Stop(Timer) (Timer -> CR1 =(0x0)) -// IT -extern volatile int g_tick_count; // Declara que a variável existe em outro arquivo -void Test(void); -void ConfigureIT(); -// PWM -void ConfigurePWM(); -void ConfigureTimers(); \ No newline at end of file diff --git a/Pilotes/Include/Nucleo.h b/Pilotes/Include/Nucleo.h deleted file mode 100644 index 49fb743..0000000 --- a/Pilotes/Include/Nucleo.h +++ /dev/null @@ -1,8 +0,0 @@ -#include "stm32f10x.h" -// Config -extern void ConfigHorloge(void); -extern void ConfigBroche(void); -// Gestion des IO Spesifiques -extern int BoutonAppuye(void); -extern void AllumerLED(void); -extern void EteindreLED(void); diff --git a/Pilotes/Include/PWM.h b/Pilotes/Include/PWM.h index 049b49f..45d3685 100644 --- a/Pilotes/Include/PWM.h +++ b/Pilotes/Include/PWM.h @@ -1,4 +1,7 @@ +#ifndef PWM_H_ +#define PWM_H_ #include "stm32f10x.h" // Config -extern void MyTimer_PWM(TIM_TypeDef *Timer, char Channel); -extern void MyTimer_Set_DutyCycle(TIM_TypeDef *Timer, char Channel, float DutyCycle_Percent); +extern void init_PWM(TIM_TypeDef *Timer, int Channel); +extern void PWM_Set_DutyCycle(TIM_TypeDef *Timer, int Channel, float DutyCycle_Percent); +#endif diff --git a/Pilotes/Include/Timer.h b/Pilotes/Include/Timer.h index 1a8de79..48c46ec 100644 --- a/Pilotes/Include/Timer.h +++ b/Pilotes/Include/Timer.h @@ -1,12 +1,8 @@ +#ifndef TIMER_H_ +#define TIMER_H_ #include "stm32f10x.h" // Config de timer extern void MyTimer_Base_Init(TIM_TypeDef *Timer , unsigned short ValARR , unsigned short ValPSC ); -extern void MyTimer_ActiveIT(TIM_TypeDef *Timer, char Prio,void(*IT_function)(void)); -// Fonctions d'interruption -extern void TIM2_IRQHandler(void); -extern void TIM3_IRQHandler(void); -extern void TIM4_IRQHandler(void); -extern void TIM1_CC_IRQnHandler(void); -extern void TIM1_UP_IRQnHandler(void); // Enable timers void EnableTimer(TIM_TypeDef *Timer); +#endif diff --git a/Pilotes/Include/test.h b/Pilotes/Include/test.h deleted file mode 100644 index 06d7405020018ddf3cacee90fd4af10487da3d20..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1024 ScmZQz7zLvtFd70QH3R?z00031 diff --git a/Pilotes/Source/ADC.c b/Pilotes/Source/ADC.c deleted file mode 100644 index 06d7405020018ddf3cacee90fd4af10487da3d20..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1024 ScmZQz7zLvtFd70QH3R?z00031 diff --git a/Pilotes/Source/DriverGPIO.c b/Pilotes/Source/DriverGPIO.c index 37cd7dc..84c8226 100644 --- a/Pilotes/Source/DriverGPIO.c +++ b/Pilotes/Source/DriverGPIO.c @@ -1,5 +1,5 @@ #include "stm32f10x.h" - +#include "DriverGPIO.h" #define In_Floating 0x4 #define In_PullDown 0x8 #define In_PullUp 0x8 diff --git a/Pilotes/Source/Girouette.c b/Pilotes/Source/Girouette.c index 255c993..ebce7e4 100644 --- a/Pilotes/Source/Girouette.c +++ b/Pilotes/Source/Girouette.c @@ -1,6 +1,4 @@ #include "stm32f10x.h" -#include "MyTimer.h" -#include "Nucleo.h" #include "Timer.h" #include "DriverGPIO.h" #include "Girouette.h" @@ -20,19 +18,18 @@ void configEncoder(TIM_TypeDef * Timer){ Timer -> SMCR &= ~TIM_SMCR_SMS; // Reset SMS-bits Timer -> SMCR |= TIM_SMCR_SMS_0 | TIM_SMCR_SMS_1;// SMS = "011" Timer -> CR1 |= TIM_CR1_CEN; // Enable counter - Timer -> ARR = 0xFD20; // Setting ARR as 1440*45 -} -void configChannel(){ + Timer -> ARR = 0x5A0; // Setting ARR as 1440 + + // 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,2,In_Floating); + 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 } -int returnAngle (TIM_TypeDef * Timer){ - return((Timer -> CNT % POSITIONS)/POSITIONS * 360); +int angleVent (TIM_TypeDef * Timer){ // Returner l'angle du vent + return((Timer -> CNT)/POSITIONS * 360); } -// Reste à coder une fonction de reset des degrés et une fonction qui retourne correctement l'angle + int vent2voile(int angle){ // Conversion angle vent à angle voile if(abs(angle) < 90){ return 0; @@ -42,7 +39,3 @@ int vent2voile(int angle){ // Conversion angle vent } } -void Servo_Moteur(int angle, TIM_TypeDef * Timer, int Channel){ // Controle du moteur - int dutyCycle = (5* angle + 5*90)/90; - MyTimer_Set_DutyCycle(Timer, Channel, dutyCycle); -} \ No newline at end of file diff --git a/Pilotes/Source/MyTimer.c b/Pilotes/Source/MyTimer.c deleted file mode 100644 index e84a38f..0000000 --- a/Pilotes/Source/MyTimer.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "stm32f10x.h" -#include "Timer.h" -#include "MyTimer.h" -#include "PWM.h" -#include "DriverGPIO.h" -// Variables -#define ARR_TIM1 0xFFAD -#define PSC_TIM1 0xFF -#define ARR_TIM2 0xFFAD -#define PSC_TIM2 0x0225 -#define ARR_TIM3 0x2CF -#define PSC_TIM3 0x0 - -volatile int g_tick_count; -void Test(void){ - // Signal - g_tick_count++; - MyGPIO_Toggle(GPIOA, 8); -} - -void ConfigureTimers(){ -// Config ARR & PSC -//MyTimer_Base_Init(TIM2, ARR_TIM2, PSC_TIM2); -MyTimer_Base_Init(TIM1, ARR_TIM1, PSC_TIM1); -MyTimer_Base_Init(TIM3, ARR_TIM2, PSC_TIM2); -// Enable timer clock -EnableTimer(TIM1); -EnableTimer(TIM2); -EnableTimer(TIM3); -} -void ConfigureIT(){ // Activate general interuption with a function and priority -//MyTimer_ActiveIT(TIM2, 4, Test); //start interruption with priority 4 -//MyTimer_ActiveIT(TIM1, 4, Test); //start interruption with priority 4 -MyTimer_ActiveIT(TIM3, 4, Test); //start interruption with priority 4 -} -void ConfigurePWM(){ // Set dutycycle with timer -MyTimer_PWM(TIM1, 1); // Utiliser timer1 avec channel 1 -MyTimer_Set_DutyCycle(TIM1, 1, 20.0); -} diff --git a/Pilotes/Source/Nucleo.c b/Pilotes/Source/Nucleo.c deleted file mode 100644 index c719043..0000000 --- a/Pilotes/Source/Nucleo.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "stm32f10x.h" -#include "../Include/Nucleo.h" -#include "DriverGPIO.h" - -void ConfigHorloge(void) { // Peut-être redondant ?? -RCC->APB2ENR |= (0x01 << 2) | (0x01 << 3) | (0x01 << 4) | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_TIM1EN; -}; - -void ConfigBroche(void){ // - //Mettre Broche 5 GPIOA à output push-pull - MyGPIO_Init(GPIOA, 5, Out_Ppull); - //Mettre broche 8 sur GPIOA à output open drain - MyGPIO_Init(GPIOA, 8, Out_OD); -}; - -int BoutonAppuye(void){ // Peut être modifié avec ChercherEtat - return(MyGPIO_Read(GPIOA, 9)); -} -void AllumerLED(void){ - MyGPIO_Set(GPIOA, 8); -} -void EteindreLED(void){ - MyGPIO_Reset(GPIOA, 8); -} - diff --git a/Pilotes/Source/PWM.c b/Pilotes/Source/PWM.c index a66a5b2..8e2c11b 100644 --- a/Pilotes/Source/PWM.c +++ b/Pilotes/Source/PWM.c @@ -1,8 +1,8 @@ #include "stm32f10x.h" -#include "../Include/PWM.h" +#include "PWM.h" -void MyTimer_PWM(TIM_TypeDef *Timer, char Channel) { // Activer PWM sur un output +void init_PWM(TIM_TypeDef *Timer, int Channel) { // Activer PWM sur un output // preload Timer->CR1 |= TIM_CR1_ARPE; @@ -41,7 +41,7 @@ void MyTimer_PWM(TIM_TypeDef *Timer, char Channel) { // Activer PWM sur un outpu Timer->BDTR |= TIM_BDTR_MOE; } } -void MyTimer_Set_DutyCycle(TIM_TypeDef *Timer, char Channel, float DutyCycle_Percent) { +void PWM_Set_DutyCycle(TIM_TypeDef *Timer, int Channel, float DutyCycle_Percent) { unsigned short ccr_value; // Percentages between 0 and 100 diff --git a/Pilotes/Source/Timer.c b/Pilotes/Source/Timer.c index b17f122..474c220 100644 --- a/Pilotes/Source/Timer.c +++ b/Pilotes/Source/Timer.c @@ -1,10 +1,5 @@ #include "stm32f10x.h" -#include "../Include/Timer.h" - -//REMEMBER TO ENALBLE TIMERS -//EXAMPLES - //RCC -> APB1ENR |= RCC_APB1ENR_TIM2EN | RCC_APB1ENR_TIM3EN; // Enable TIM2 - //RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; // Enable TIM1 +#include "Timer.h" void MyTimer_Base_Init( TIM_TypeDef * Timer , unsigned short ValARR , unsigned short ValPSC ) { // Configuration du timer Timer -> PSC=(ValPSC); @@ -13,77 +8,7 @@ Timer->EGR |= TIM_EGR_UG; }; -static void (*p_IT_functions[4])(void); // Pour créer l'array des fonctions -void MyTimer_ActiveIT(TIM_TypeDef *Timer, char Prio,void(*IT_function)(void)) { - //Enable interruption requisition - Timer->DIER |= TIM_DIER_UIE; // Update interrupt enable - - //Id the interruption timer routine - IRQn_Type IRQn; - - int timer_index = -1; // Indice pour notre array des pointeurs - if (Timer == TIM2) { - IRQn = TIM2_IRQn; - timer_index = 0; - } else if (Timer == TIM3) { - IRQn = TIM3_IRQn; - timer_index = 1; - } else if (Timer == TIM4) { - IRQn = TIM4_IRQn; - timer_index = 2; - } - // Keep the pointer of the valid timer function - if (timer_index != -1) { - p_IT_functions[timer_index] = IT_function; // index the function - } else { - return; // Timer invalid - } - // set interruption priority - NVIC_SetPriority(IRQn, Prio); - // Enable routine - NVIC_EnableIRQ(IRQn); -}; - - -void TIM2_IRQHandler(void) { - // Clean flag - TIM2->SR &= ~TIM_SR_UIF; // Drapeau d'interuption - //Call function - if (p_IT_functions[0] != 0) { - p_IT_functions[0](); // Execute fonction - } -}; -void TIM3_IRQHandler(void) { - // Clean flag - TIM3->SR &= ~TIM_SR_UIF; - //Call function - if (p_IT_functions[1] != 0) { - p_IT_functions[1](); // Execute function - } -}; -void TIM4_IRQHandler(void) { - // Clean flag - TIM4->SR &= ~TIM_SR_UIF; - //Call function - if (p_IT_functions[2] != 0) { - p_IT_functions[2](); // Execute function - } -}; -// IT PWM -void TIM1_CC_IRQHandler(void) { - // Clean flag - TIM1 -> DIER &= ~TIM_DIER_CC1IE; - //Set bit - GPIOA -> ODR |= (0x1 << 8); -}; - -void TIM1_UP_IRQHandler(void) { - // Clean flag - TIM1-> DIER &= ~TIM_DIER_TIE; - //Reset bit - GPIOA -> ODR &= ~(0x1 << 8); -}; void EnableTimer(TIM_TypeDef *Timer){ if(Timer == TIM2){ RCC -> APB1ENR |= RCC_APB1ENR_TIM2EN; diff --git a/principal.c b/principal.c index 33733ad..29eaa9d 100755 --- a/principal.c +++ b/principal.c @@ -1,43 +1,33 @@ -#include "stm32f10x.h" +#include #include // Pour print -#include "MyTimer.h" -#include "Nucleo.h" #include "Girouette.h" +#include "Servo.h" #include "DriverGPIO.h" -int test=0; -volatile int angleVent; -volatile int angleVoile; +//Variables +volatile int angleVentVar; +volatile int angleVoileVar; + int main ( void ){ - - // ---- Setup ------ - //Nucleo.c - ConfigHorloge(); - //ConfigBroche(); - //MyTimer.c - ConfigureTimers(); - //ConfigureIT(); - //PWM. - ConfigurePWM(); - // Giroutte.c - configEncoder(TIM2); - configChannel(); - - //MyTimer_Base_Start (TIM2); - //MyTimer_Base_Start (TIM1); - //MyTimer_Base_Start (TIM3); - + // ---- Setup ------ + //Servo.c + initServo(TIM4, 3); + // Giroutte.c + configEncoder(TIM2); + + // Localisation de z + int Z_trouve = 0; + while (Z_trouve != 1){ + if(MyGPIO_Read(GPIOA,8)){ // Index + TIM2 -> CNT = 0x0; // Remet angle à zero + Z_trouve = 1; + } + } // ----- Opération ----- - while (1){ - if(MyGPIO_Read(GPIOA,8)){ // Index - TIM2 -> CNT = 0x0; // Remet angle à zero - } - angleVent = returnAngle(TIM2); // Récupérer l'angle de girouette - angleVoile = vent2voile(angleVent); // Transformer l'angle de girouette au l'angle des voiles souhaités - Servo_Moteur(angleVoile, TIM1, 1); // Faire bouger le moteur servo - - //printf("L'angle est %d ", returnAngle(TIM2)); - - - } + 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 + + } };