cancel
Showing results for 
Search instead for 
Did you mean: 

Code error when passing parameters to timer function

treeset
Associate II

https://community.st.com/t5/stm32-mcus-products/can-pwm-settings-affect-other-timer-settings/m-p/748254#M267471

void TIM2_Configuration(u32 Intervalms) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_TimeBaseStructure.TIM_Prescaler = 16000-1; //do not work //TIM_TimeBaseStructure.TIM_Period = Intervalms - 1; //do work TIM_TimeBaseStructure.TIM_Period = 500 - 1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); TIM_Cmd(TIM2, ENABLE); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }

 In the last article, I said that the code worked or did not work depending on the location of TIM2_Configuration. However, when I removed the parameter from TIM2_Configuration and changed the period initialization to 500-1, the code worked properly regardless of the order. Does anyone know what causes this phenomenon to occur?

1 ACCEPTED SOLUTION

Accepted Solutions
mÆŽALLEm
ST Employee

Check the value of 

TIM_TimeBaseStructure.TIM_Period

after setting it:

TIM_TimeBaseStructure.TIM_Period = Intervalms - 1;

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

1 REPLY 1
mÆŽALLEm
ST Employee

Check the value of 

TIM_TimeBaseStructure.TIM_Period

after setting it:

TIM_TimeBaseStructure.TIM_Period = Intervalms - 1;

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.