cancel
Showing results for 
Search instead for 
Did you mean: 

Tim interrupt?

orn
Associate II
Posted on November 12, 2012 at 17:22

I need that display that I put on my stm32f4 Discovery is updated every second, I thought to do so through an interrupt TIM, but I do not know how to configure to work as TIM clock! can you give me some suggestions or examples?

5 REPLIES 5
Posted on November 12, 2012 at 17:35

Just set up the time base (prescale/period), and enable the Update interrupt.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
orn
Associate II
Posted on November 14, 2012 at 16:10

I have configured in the following way TIM4

//file stm32f4xx_it.c

void TIM4_IRQHandler(void){
TIM_ClearITPendingBit(TIM4,TIM_IT_Update);
STM_EVAL_LEDToggle(LED6);
}
//file of configuration
void Tim_Clock_IT(void){
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
//Configure TIM4 
TIM_TimeBaseStructure.TIM_Period =SystemCoreClock ; 
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM4, ENABLE);
/* Enable TIM4 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}

and to understand if they actually worked well I put the code in the interrupt routin STM_EVAL_LEDToggle(LED6), but the LED 6 never turns off, and according to my calculations should flash on and off once per second! what is wrong??
Posted on November 14, 2012 at 17:09

Unless TIM4 is 32-bit you need to compute/factor your period/prescale values to fit in 16-bit ranges.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on November 14, 2012 at 17:56

// TOGGLETIM4 STM32F4 Discovery - sourcer32@gmail.com
#include ''stm32f4_discovery.h''
/**************************************************************************************/
void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* TIM4 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
}
/**************************************************************************************/
void TIM4_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = ((SystemCoreClock / 10000) / 2) - 1;
TIM_TimeBaseStructure.TIM_Prescaler = 10000 - 1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
/* TIM4 enable counter */
TIM_Cmd(TIM4, ENABLE);
TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
}
/**************************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable TIM4 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**************************************************************************************/
void TIM4_IRQHandler(void)
{
TIM_ClearITPendingBit(TIM4,TIM_IT_Update);
STM_EVAL_LEDToggle(LED6);
}
/**************************************************************************************/
int main(void)
{
RCC_Configuration();
NVIC_Configuration();
STM_EVAL_LEDInit(LED6);
STM_EVAL_LEDOn(LED6);
TIM4_Configuration();
while(1); // Don't want to exit
}
/**************************************************************************************/

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
orn
Associate II
Posted on November 14, 2012 at 18:05

thank you very much Clive! for all the help you have given me :D