cancel
Showing results for 
Search instead for 
Did you mean: 

Timer interrupt

nanayakkaraan
Associate II
Posted on October 20, 2010 at 11:55

Timer interrupt

4 REPLIES 4
lowpowermcu
Associate II
Posted on May 17, 2011 at 14:11

Hi ANN and andy,

If you want to use TIM4 instead of TIM1, there is some differencies:

 - TIM4 is on APB1 and not on APB2

 - no repetition counter in TIM4 so no field  TIM_RepetitionCounter in timer struct

 - interrupt handler is ''TIM4_IRQHandler'' and not ''TIM1_UP_IRQHandler''

That is what I have actually in mind.

regards,

MCU Lüfter

Posted on May 17, 2011 at 14:11

Hi ANN,

I have some bits using TIM1 on a ST..103.. that may help. These use the standard libraries.

Put this somewhere in your main.

   NVIC_InitTypeDef             NVIC_InitStructure;

   TIM1_TimeBaseInitTypeDef     TIM1_TimeBaseInitStruct;

   RCC_APB2PeriphClockCmd (RCC_APB2Periph_TIM1, ENABLE);

      // Set timer1

   TIM1_TimeBaseInitStruct.TIM1_Prescaler = 8; 

   TIM1_TimeBaseInitStruct.TIM1_CounterMode = TIM1_CounterMode_Up;

   TIM1_TimeBaseInitStruct.TIM1_Period = 10000;

   TIM1_TimeBaseInitStruct.TIM1_ClockDivision = TIM1_CKD_DIV1;

   TIM1_TimeBaseInitStruct.TIM1_RepetitionCounter = 0;

   TIM1_TimeBaseInit (&TIM1_TimeBaseInitStruct);

   NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQChannel;

   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 9;

   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

   NVIC_Init (&NVIC_InitStructure);

   TIM1_ClearITPendingBit (TIM1_FLAG_Update);   // Clear Interrupt

   TIM1_ITConfig (TIM1_FLAG_Update, ENABLE);    // Enable Interrupt

   TIM1_Cmd (ENABLE);                           // Enable Timer

This next bit assumes a static variable called led_timer initialised to 0, that your LED is on port b and GPIO_LED is defined as the pin your LED is on.

Find TIM1_UP_IRQHandler() in stm32f10x_it.c and put the following code there :-

void TIM1_UP_IRQHandler(void)

{

  TIM1_ClearITPendingBit (TIM1_FLAG_Update);

    led_timer=1-led_timer;

    if (led_timer)

     GPIO_ResetBits (GPIOB, GPIO_LED);

  else

     GPIO_SetBits (GPIOB, GPIO_LED);

}

That should get you a timer interrupt ticking. Play with the Period and Prescaler to get it running at the right speed.

Sorry if it's a bit of a hack, I've taken it from bits of code I have and tied it together. Hopefully it will be enough to get you going.

Cheers,

vmtetons
Associate
Posted on May 17, 2011 at 14:11

Hi ANN

Could you please let me know where you got your STM32L152 devices or board from.  I do not seem to find any distributor here in the US for teh low power family.

Thanks

stmdesi

lowpowermcu
Associate II
Posted on May 17, 2011 at 14:11

Hi ANN,

I have looked for the site dedicated to STM32L family and I diidn't find eval board documentation neither ST library.

I have found only reference manual ,datasheet and 2 application notes.

Perhaps STM32L152-EVAL isn't from ST. could you trell us where to find it in Germany ?

Thanks ANN,

Herzlich,

MCU Lüfter