cancel
Showing results for 
Search instead for 
Did you mean: 

32-bit Timer issue

albert361
Associate
Posted on August 11, 2014 at 17:10

Sorry guys,

I know it's a really simple question but I just don't get it...

I'm using STM32F427, we all know its TIM2 is a 32-bit timer.

This is the code I'm using to setup TIM2 as a periodic timer.

==================================================================

    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

    uint16_t PrescalerValue;

    NVIC_InitTypeDef NVIC_InitStructure;

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

    NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; // 84000000 * 1 = 84000000 = 84M

    TIM_TimeBaseStructure.TIM_Prescaler = 42000 - 1; // 0.5ms per count

    TIM_TimeBaseStructure.TIM_Period = (30 * 2000)-1;// 30 sec

    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

    TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

    TIM_ClearFlag(TIM2, TIM_FLAG_Update);

    TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);

    TIM_Cmd(TIM2, ENABLE);

==================================================================

My system clock is configured to 168MHz and I can get this code to generate a 30-second interrupt. (TIM_TimeBaseStructure.TIM_Period = 59999)

But if I set a value larger than 65535(16-bit) to the Period (CNT) value, the IRQ doesn't fired anymore.

Anyone knows what happend about this problem?

Thanks.

BR,

Albert
2 REPLIES 2
Posted on August 11, 2014 at 18:41

Doesn't look unreasonable, ClockDivision doesn't function how you assume it does, and there are other fields in the initialization structure that could be cleared, in case that's causing an issue.

The prescaler is limited to 16-bit, the period field should be uint32_t

What tool chain and firmware library are you using?

How are you testing this?
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
albert361
Associate
Posted on August 12, 2014 at 03:33

Hi Clive,

I'm using IAR 6.70 with Std_Peripheral_Driver 1.30.

I just download code and toggle a breakpoint in my IRQ handler.

It works when I set the period value under 65535 but failed when larger.

Thnaks.