Question
STM32f4 Timer1 counting pulses
Hello all,
I want to count pulses with TIMER 1, because he has the fastest counting frequency.
I was able to count pulses with TIMER 2 but something in my code is missing to make it work for Timer 1: (I also checked the reference manual ...)
Maybe someone knows something that I missed.
Here is my Code:
void timer_1_pulse_counter_gpioa1_Init(void){
RCC->AHB1ENR |= 0x01; // 1: IO port A clock enabled
//RCC->AHB1ENR |= 0x10; // 1: IO port E clock enabled
// APB1 peripheral reset register
RCC->APB2ENR |= 0x01; // 1: enable TIM2
// GPIO port mode register (GPIOx_MODER)
GPIOA->MODER |= 0x00000008; // 10: Alternate function mode PA1 => AF mode
GPIOA->AFR[0] |= 0x00000010; // 1000: (alternate function for TIM1/ TIm2)
GPIOA->PUPDR |= 0x00000008; // Sets pull down resistor for PA1
// CCMR!: capture/compare mode register 1
TIM1->CCMR1 |= 0x0200; // CC2 ... , IC2 is mapped on TI1
TIM1->SMCR |= 0x0007; // Bits[2:0] 111: External Clock Mode 1 - Rising edges of the selected trigger clock the counter.
TIM1->SMCR |= 0x0050; // Bits[6:4] 110: selected Trigger: Filtered Timer Input 1 (TI1FP1)
// 0x0050
TIM1->ARR = 0xFFFF; // Set the timer reset on the highest possible value
TIM1->CR1 |= 0x0001; //0001 Enable Timer
}