cancel
Showing results for 
Search instead for 
Did you mean: 

Timer Interrupt

ag2
Associate
Posted on July 28, 2008 at 11:18

Timer Interrupt

3 REPLIES 3
ag2
Associate
Posted on May 17, 2011 at 12:40

Hi

I am a new bee to the STM32 Micro controller, I am working with the STM3210E evaluation board. Can any one hint me on how to generate A TIMER INTERRUPT every X microseconds.

disirio
Associate II
Posted on May 17, 2011 at 12:40

Hello, the Cortex-M3 has a dedicated unit for this role, it is the SysTick unit.

You have to setup the interrupt vector and priority for the systick unit and then start the timer. This is an example:

#define ENABLE_ON_BITS (1 << 0)

#define TICKINT_ENABLED_BITS (1 << 1)

#define CLKSOURCE_EXT_BITS (0 << 2)

ST_RVR = SYSCLK / (8000000 / CH_FREQUENCY) - 1;

ST_CVR = 0;

ST_CSR = ENABLE_ON_BITS | TICKINT_ENABLED_BITS | CLKSOURCE_EXT_BITS;

SYSCLK is the system clock in Hertz, CH_FREQUENCY is the interrupt frequency.

The above code is present in the project you can see in my signature inside a STM32 demo program.

---

ChibiOS/RT

http://chibios.sourceforge.net

sjo
Associate II
Posted on May 17, 2011 at 12:40

There are lots of examples with the stm32 libs, here is a simple timebase:

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

/* TIM2CLK = 36 MHz, Prescaler = 1125, TIM2 counter clock = 32000 Hz

* 36MHz / (1124+1) = 32000Hz

* 160 * (1/32000Hz) = 0.005ms overflow interrupt */

/* Time base configuration */

TIM_TimeBaseStructure.TIM_Period = 160;

TIM_TimeBaseStructure.TIM_Prescaler = 1124;

TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

/* Clear TIM2 update pending flag */

TIM_ClearFlag(TIM2, TIM_FLAG_Update);

/* TIM IT enable */

TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);

/* TIM2 enable counter */

TIM_Cmd(TIM2, ENABLE);

Cheers

sjo