#include "MyGirouette.h" #include "Driver_GPIO.h" #include "MyTimer.h" int x = 0; void EXTI0_IRQHandler(void) { x++; //EXTI->PR &= ~(1<<0) ; TIM2 -> CNT = 0 ; EXTI->PR |= (1<<0) ; } void Init_Girouette(void){ MyGPIO_Struct_TypeDef GPIOA0={ GPIOA, 0, In_Floating }; MyGPIO_Struct_TypeDef GPIOA1={ GPIOA, 1, In_Floating }; MyGPIO_Struct_TypeDef GPIOB0={ GPIOB, 0, In_Floating }; // Configuration du timer MyTimer_Struct_TypeDef TIM; TIM.Timer = TIM2; TIM.ARR = 360*2; TIM.PSC = 0; MyTimer_Base_Init(&TIM); TIM2->CCMR1 |= 0x1 << 0; //CH1 TIM2->CCMR1 |= 0x1 << 8; //CH2 TIM2->SMCR |= 0x1 << 0; // Capture Mode : 1 => seulement les fronts montants 2 => seulement les fronts descendants 3 => les 2 TIM2->CCMR1 |= 0x1 << 2; // 0 Reset NVIC->ISER[0] |= 1 << 6; NVIC->IP[6] = 1<<4; MyGPIO_Init(&GPIOB0); RCC->APB2ENR |= RCC_APB2ENR_AFIOEN ; AFIO->EXTICR[0] |= 0x0001; // PB0 AFIO EXTI->RTSR |= 1 <<0 ; // rising EXTI->IMR |= 1<<0 ; //mask MyGPIO_Init(&GPIOA0); MyGPIO_Init(&GPIOA1); MyTimer_Base_Start(TIM2); } uint16_t Get_Angle(void){return (TIM2 -> CNT)/2;}