cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F410RB Timer External clock mode PROBLEM

KOlli.1
Associate

Hello everyone, this is my first post here. I am actually working on custom pcb with a STM32F410RB, which is used to count an external signal.

To do this I use 2 timers, Timer 9 configured in internal clock and counting a 1 second period and generate an interrupt to read the Timer 5 configured in external clock mode 1.

My 1 second interrupt is working (I commute a GPIO to measure the period) but there is a WEIRD problem with the Timer 5 ! I put a waveform generator on the timer input and I can count something but there is /100 ratio on the value ! If I put 1Khz, I read 10 Hz...

My STM is working at 100MHz with an external oscillator of 25MHz and PLL settings.

I post here my Timers configuration

void init_Timer5()  // Timer 5 32 bits, external clock mode on channel TI1(TI1FP1) on pin PB12

{

    // Clock Enable on Timer 5

    __HAL_RCC_TIM5_CLK_ENABLE(); 

    TIM5->CR1 = 0x0084;

    TIM5->CR2 = 0x0000;

    TIM5->CCMR1 = 0x00000000;  // input capture config on CH1, No Filter

    TIM5->CCER = 0x0000;  // input capture enabled

    TIM5->SMCR = 0x00000057;   // external  clock mode 1; trigger on TI1FP1

    TIM5->PSC = 0;

    TIM5->CNT = 0;

    TIM5->ARR = 0xffffffff;  // 32bits

}

void init_Timer9()   // Timer 9, clock interne 100MHz, interruption enable

{

    // Clock Enable on Timer 9

    __HAL_RCC_TIM9_CLK_ENABLE();

    

     TIM9->CR1 = 0x0084;

     TIM9->SMCR = 0x0000;

     TIM9->PSC = 1999;   //  div par 2000; (100MHz / 10000 = 50kHz / 20µs) 

     TIM9->ARR = 49999;  // 50000 counts * 20µs = 1 sec

     TIM9->CNT = 0;

     TIM9->DIER |= TIM_DIER_UIE;  // Enable interrupt

     HAL_NVIC_SetPriority(TIM1_BRK_TIM9_IRQn, 0, 0);

     HAL_NVIC_EnableIRQ(TIM1_BRK_TIM9_IRQn);

     NVIC_SetVector(TIM1_BRK_TIM9_IRQn, (uint32_t)&TIM1_BRK_TIM9_IRQHandler);

}

void init_GPIO()

{

    __HAL_RCC_GPIOB_CLK_ENABLE();  // GPIO B ext clk pin

    GPIO_InitTypeDef GPIO_InitStruct = {0};

    

    /**TIM5 GPIO Configuration    

    PB12     ------> TIM5_CH1 

    */

    GPIO_InitStruct.Pin = GPIO_PIN_12;

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

    GPIO_InitStruct.Alternate = GPIO_AF2_TIM5;

    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

}

I cant find my problem, I did the same on a NUCLEO BOARD F767ZI and its working very well...

0 REPLIES 0