cancel
Showing results for 
Search instead for 
Did you mean: 

stm32 timer config at 1us bug

amin mokhtari
Associate
Posted on August 03, 2017 at 19:00

hey all

i configed timer for 1us timer interrupt but how can i be sure my timer interrupt is 1us ?

my microcontroller is stm32f103c8t6 her RCC configed with pll on 72Mhz 

external crystal 8Mhz

my timer function 

void TIMER_Config(TIM_TypeDef* timer, uint16_t Period, uint16_t Prescaler, uint16_t ClockDivision, uint16_t CounterMode, FunctionalState status){

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

TIM_TimeBaseStructure.TIM_Period = Period;

TIM_TimeBaseStructure.TIM_Prescaler = Prescaler;

TIM_TimeBaseStructure.TIM_ClockDivision = ClockDivision;

TIM_TimeBaseStructure.TIM_CounterMode = CounterMode;

TIM_TimeBaseInit(timer, &TIM_TimeBaseStructure);

TIM_ARRPreloadConfig(timer, status);//TIM4 Config for 1ms interrupt

TIM_ClearITPendingBit(timer, TIM_IT_Update);

TIM_ITConfig(timer, TIM_IT_Update, status);

TIM_SetCounter(timer, 0);

TIM_Cmd(timer, status);

}

my nvic function

void NVIC_Config(uint8_t IRQChannel, uint8_t PreemptionPriority, uint8_t SubPriority , FunctionalState status){

NVIC_InitTypeDef NVIC_InitStructure;

NVIC_InitStructure.NVIC_IRQChannel = IRQChannel;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = PreemptionPriority;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = SubPriority;

NVIC_InitStructure.NVIC_IRQChannelCmd = status; /*TIM4 Interrupt configuration*/

NVIC_Init(&NVIC_InitStructure);

}

and my timer configuration is

// TIM3 Configuration

NVIC_Config(TIM3_IRQn, 0, 1 , ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);

TIMER_Config(TIM3,360, 1, 0, TIM_CounterMode_Up,ENABLE);

please help 

thanks 

amin 

1 REPLY 1
S.Ma
Principal
Posted on August 04, 2017 at 09:59

A quick and dirty way:

If you have an LED driven by GPIO, create a global 32bit variable which will be incremented within the 1us interrupt and overflow at 500000

pseudo code:

==> 1us interrupt ISR, add:

if((count++)%1000000)==0  ToggleLED();

Then check the LED blinking period is 1 second.