From b838f0ee8d26ed12b48be43f79247620dde47aad Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 11 Apr 2023 13:35:12 +0200 Subject: [PATCH] Variation girouette --- implementation/girouette.c | 53 +++++++++++++++++++++++++++++++++ implementation/girouette.h | 10 +++++++ keilproject/Source/Principale.c | 32 ++++++-------------- keilproject/voilier.uvoptx | 20 +++++++++++++ keilproject/voilier.uvprojx | 23 +++++++++++++- 5 files changed, 114 insertions(+), 24 deletions(-) create mode 100644 implementation/girouette.c create mode 100644 implementation/girouette.h diff --git a/implementation/girouette.c b/implementation/girouette.c new file mode 100644 index 0000000..548f98e --- /dev/null +++ b/implementation/girouette.c @@ -0,0 +1,53 @@ +#include "girouette.h" + +void MyGirouette_Init(TIM_TypeDef *TIMX) +{ + + //configuration gpiob6 et gpiob7 en entrées In_Floating imposer par le timer4 + MyGPIO_Struct_TypeDef MyGPIO={GPIOB,6,In_Floating}; + MyGPIO_Init(&MyGPIO); + MyGPIO.GPIO_Pin=7; + MyGPIO_Init(&MyGPIO); + //config pa0 en entrées + MyGPIO.GPIO_Pin=0; + MyGPIO.GPIO=GPIOA; + MyGPIO_Init(&MyGPIO); + //configuration TIM4 reset a 360 + MyTimer_Struct_Typedef MyTimerGirouette ={TIMX,719,0}; + MyTimer_Base_Init(&MyTimerGirouette); + + TIMX->SMCR &=~0x07; + TIMX->SMCR |=TIM_SMCR_SMS_1; + TIMX->CCMR1 &=~(0xF2F2); + TIMX->CCMR1 |= TIM_CCMR1_CC1S_0; + TIMX->CCMR1 |= TIM_CCMR1_CC2S_0; //CC2S dans CCMR1 et pas CCMR2 + TIMX->CCER &=~TIM_CCER_CC1P; + TIMX->CCER &=~TIM_CCER_CC2P; + TIMX->CCMR1&=~(0x0F<<4); //IC1F + TIMX->CCMR1&=~(0x0F<<12);//IC2F + TIMX->CR1 |= 1; +} + + +int MyGirouette_Angle(TIM_TypeDef *TIMX) +{ + return TIMX->CNT; +} + + + +void MyGirouette_Init_IT_Z(uint8_t GPIO_Pin) +{ + + EXTI->IMR |= (0x01<RTSR|= (0x01<EXTICR[0] &= ~(0x0000000F);// L'interruption « EXTI0 » doit être provoquée par une modification PA0 + NVIC->ISER[0] |= (1 << (6 & 0x1F)); // Autorisation de l'interruption « EXTI0 » NUMERO 6, + +} + +void EXTI0_IRQHandler(void)__irq { + TIM4->CNT=0; + //rabaisse flag +} + diff --git a/implementation/girouette.h b/implementation/girouette.h new file mode 100644 index 0000000..72da37d --- /dev/null +++ b/implementation/girouette.h @@ -0,0 +1,10 @@ +#ifndef MYMOTOR_H +#define MYMOTOR_H +#include "stm32f10x.h" +#include "../driver/gpio.h" +#include "../driver/timer.h" + +int MyGirouette_Angle(TIM_TypeDef *TIMX); +void MyGirouette_Init(TIM_TypeDef *TIMX); + +#endif diff --git a/keilproject/Source/Principale.c b/keilproject/Source/Principale.c index ccbd4ab..324f7ba 100644 --- a/keilproject/Source/Principale.c +++ b/keilproject/Source/Principale.c @@ -4,34 +4,20 @@ #include "../../driver/timer.h" #include "../../driver/gpio.h" - void Girouette_Angle(void); - int Angle_Girouette=0; int main (void) { - //configuration gpiob6 et gpiob7 en entrées pull up - MyGPIO_Struct_TypeDef MyGPIO={GPIOB,6,In_PullUp}; - MyGPIO_Init(&MyGPIO); - MyGPIO.GPIO_Pin=7; - MyGPIO_Init(&MyGPIO); - //configuration TIM4 reset a 360 - MyTimer_Struct_Typedef MyTimerGirouette ={TIM4,359,1}; - MyTimer_Base_Init(&MyTimerGirouette); - TIM4->SMCR &=~0x07; - TIM4->SMCR |=~0x011; - TIM4->CCMR1 |= TIM_CCMR1_CC1S_0; - TIM4->CCMR1 |= TIM_CCMR1_CC2S_0; - TIM4->CCER &=~TIM_CCER_CC1P; - TIM4->CCER &=~TIM_CCER_CC1NP; - TIM4->CCER &=~TIM_CCER_CC2P; - TIM4->CCER &=~TIM_CCER_CC2NP; - TIM4->CCMR1&=~TIM_CCER_IC1F; - TIM1->CR1 |= 1; - Angle_Girouette=TIM4->CNT; + int Angle_Girouette=0; + + //init girouette + MyGirouette_Init(TIM4); + MyGirouette_Init_IT_Z(0); + //lecture angle + while(1){ + Angle_Girouette=MyGirouette_Angle(TIM4); + }; - - while(1){}; } diff --git a/keilproject/voilier.uvoptx b/keilproject/voilier.uvoptx index 3171a5a..1dc128d 100644 --- a/keilproject/voilier.uvoptx +++ b/keilproject/voilier.uvoptx @@ -628,6 +628,26 @@ + + implementation + 1 + 0 + 0 + 0 + + 3 + 7 + 1 + 0 + 0 + 0 + ..\implementation\girouette.c + girouette.c + 0 + 0 + + + ::CMSIS 0 diff --git a/keilproject/voilier.uvprojx b/keilproject/voilier.uvprojx index 230c61b..0eaad98 100644 --- a/keilproject/voilier.uvprojx +++ b/keilproject/voilier.uvprojx @@ -422,6 +422,16 @@ + + implementation + + + girouette.c + 1 + ..\implementation\girouette.c + + + ::CMSIS @@ -434,7 +444,8 @@ Réel 0x4 ARM-ADS - 6190000::V6.19::ARMCLANG + 5060960::V5.06 update 7 (build 960)::.\ARM_Compiler_5.06u7 + 5060960::V5.06 update 7 (build 960)::.\ARM_Compiler_5.06u7 0 @@ -845,6 +856,16 @@ + + implementation + + + girouette.c + 1 + ..\implementation\girouette.c + + + ::CMSIS