Voilier/Drivers/Voilier_fonction/Girouette.c
2023-04-11 15:31:47 +02:00

39 lines
1.1 KiB
C

#include "Girouette.h"
#include "Driver_ADC.h"
#include "Driver_Timer.h"
#include "Driver_GPIO.h"
void init_encoder_timer (void){
//Déclaration du Timer et de ses GPIO
MyGPIO_Struct_TypeDef * GPIO_PB6;
MyGPIO_Struct_TypeDef * GPIO_PB7;
MyTimer_Struct_TypeDef * Encoder_Timer;
//Parametrage des GPIO
GPIO_PB6->GPIO = GPIOB;
GPIO_PB6->GPIO_Conf = In_Floating;
GPIO_PB6->GPIO_Pin = 6;
MyGPIO_Init(GPIO_PB6);
GPIO_PB7->GPIO = GPIOB;
GPIO_PB7->GPIO_Conf = In_Floating;
GPIO_PB7->GPIO_Pin = 7;
MyGPIO_Init(GPIO_PB7);
//Parametrage du Timer
Encoder_Timer->Timer = TIM4;
Encoder_Timer->ARR = 400; //ARR doit être supérieur à 360° puisque la RAZ du Timer se fait au tour complet de la girouette
Encoder_Timer->PSC = 0; //On ne divise pas la précision de notre mesure
MyTimer_Base_Init(Encoder_Timer);
//Passage du Timer en mode Encoder
TIM4->SMCR &= ~(0x0007);
TIM4->SMCR |= TIM_SMCR_SMS_1;
TIM4->CCMR1 &= ~(0xF2F2);
TIM4->CCMR1 |= TIM_CCMR1_CC1S_0;
TIM4->CCMR1 |= TIM_CCMR1_CC2S_0;
TIM4->CCER &= TIM_CCER_CC1P;
TIM4->CCER &= TIM_CCER_CC2P;
TIM4->CR1 |= TIM_CR1_CEN;
}