From 0669098ea85f244ba265d37677505e1b2af7a473 Mon Sep 17 00:00:00 2001 From: William Woodward Date: Mon, 1 Dec 2025 18:33:57 +0100 Subject: [PATCH] Ajout girouette/bordage --- Services/Girouette.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ Services/Girouette.h | 15 +++++++++++++ Services/bordage.c | 30 ++++++++++++++++++++++++++ Services/bordage.h | 9 ++++++++ 4 files changed, 105 insertions(+) create mode 100644 Services/Girouette.c create mode 100644 Services/Girouette.h create mode 100644 Services/bordage.c create mode 100644 Services/bordage.h diff --git a/Services/Girouette.c b/Services/Girouette.c new file mode 100644 index 0000000..ac26b68 --- /dev/null +++ b/Services/Girouette.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include + +void (*Ptr_fct_girouette) (void); + +void Timer_Counter (TIM_TypeDef *Timer) { + Timer->CCMR1 |= TIM_CCMR1_CC1S_0; + Timer->CCMR1 |= TIM_CCMR1_CC2S_0; + + Timer->CCER &= ~(TIM_CCER_CC1P); + Timer->CCER &= ~(TIM_CCER_CC1NP); + Timer->CCMR1 &= ~(TIM_CCMR1_IC1F); + + Timer->CCER &= ~(TIM_CCER_CC2P); + Timer->CCER &= ~(TIM_CCER_CC2NP); + Timer->CCMR1 &= ~(TIM_CCMR1_IC2F); + Timer->SMCR |= 0x0003; + Timer->CR1 |= TIM_CR1_CEN; +} + +void Init_girouette (){ + MyTimer_Init(TIM4, 1440, 1); + MyTimer_Base_Start(TIM4); + MyGPIO_Init(GPIOB, 6, In_Floating); + MyGPIO_Init(GPIOB, 7, In_Floating); + MyGPIO_Init(GPIOA, 12, In_Floating); + Init_Interrupt(3, LafonctGirouette); + Timer_Counter(TIM4); +} + +//Fonctio girouette appeler pour l'interruption +void LafonctGirouette(){ + TIM4->CNT = 0; +} + +void Init_Interrupt(char Prio, void (*IT_function) (void)){ + RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; + AFIO->EXTICR[3] &= ~(0xF); + EXTI->IMR |= 1<<12; + EXTI->RTSR |= 1<<12; + NVIC->ISER[1] |= NVIC_ISER_SETENA_8; // exti 12 on s'est trompé mais normalement c'est bo mtn + Ptr_fct_girouette = IT_function; + NVIC->IPR[40] = Prio<<4; +} + +void EXTI15_10_IRQHandler (){ + EXTI->PR |= 1 << 12; + Ptr_fct_girouette(); +} diff --git a/Services/Girouette.h b/Services/Girouette.h new file mode 100644 index 0000000..2d3d297 --- /dev/null +++ b/Services/Girouette.h @@ -0,0 +1,15 @@ +#ifndef GIROUETTE_H +#define GIROUETTE_H +#include "stm32f10x.h" + + +void Init_Interrupt(char Prio, void (*IT_function) (void)); + +void EXTI0_IRQHandler(); + +void LafonctGirouette (); + +void Init_girouette (); + +void LafonctGirouette(); +#endif \ No newline at end of file diff --git a/Services/bordage.c b/Services/bordage.c new file mode 100644 index 0000000..ba7dfe8 --- /dev/null +++ b/Services/bordage.c @@ -0,0 +1,30 @@ +#include "stm32f10x.h" +#include +#include +#include + +void Init_bordage(TIM_TypeDef *Timer, char channel, unsigned short ValARR, unsigned short ValPSC){ + MyTimer_Init(Timer,ValARR,ValPSC); + Mytimer_PWM(Timer, channel); + MyTimer_Base_Start(Timer); + MyGPIO_Init(GPIOA, 0, AltOut_Ppull); +} + +void Update_bodage (TIM_TypeDef *Timer, char channel){ + float val; + val = TIM4->CNT; + if (val <4.0*45.0 || val > 4.0*(360.0-45.0)) { + Mytimer_PWM_cycle(Timer, channel, 9); + } + else + if (val <= 720.0) { + val/= -108.0; + val+= 35.0/3.0; + Mytimer_PWM_cycle(Timer, channel, (int) val); + } + else{ + val/= 108.0; + val+= -5.0/3.0; + Mytimer_PWM_cycle(Timer, channel, (int) val); + } +} \ No newline at end of file diff --git a/Services/bordage.h b/Services/bordage.h new file mode 100644 index 0000000..8231c50 --- /dev/null +++ b/Services/bordage.h @@ -0,0 +1,9 @@ +#ifndef BORDAGE_H +#define BORDAGE_H +#include "stm32f10x.h" + +void Init_bordage(TIM_TypeDef *Timer, char channel, unsigned short ValARR, unsigned short ValPSC); + +void Update_bodage (TIM_TypeDef *Timer, char channel); + +#endif \ No newline at end of file