2022-07-07 10:18 PM
I'm trying to generate 3 pulses using the One pulse Mode on the TIM1 with the LL drivers. I'm using an STM32F401RE.
I only get one pulse regardless the value I set for the repetition counter. I have done lot of research on the internet but I couldn't find any solution.
I would appreciate some help. Thanks,
Following is the code for the timer initialization:
I have also activated the the required channel in my main code().
void TIM1_af_init(void){
// Enable clock access to APB1
LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_TIM1);
// set Prescaler
LL_TIM_SetPrescaler (TIM1, 84-1);
// set counter mode
LL_TIM_SetCounterMode (TIM1, LL_TIM_COUNTERMODE_UP);
// set Autoreload
LL_TIM_SetAutoReload (TIM1, 1000-1); // 10 000 divide per 10 000 = 1
LL_TIM_EnableUpdateEvent (TIM1);
LL_TIM_SetOnePulseMode (TIM1, LL_TIM_ONEPULSEMODE_SINGLE);
LL_TIM_SetRepetitionCounter (TIM1, 2);
// Set timer 2 to OC mode
LL_TIM_OC_SetMode (TIM1, LL_TIM_CHANNEL_CH1, LL_TIM_OCMODE_PWM1); // PWM2 to inverse the signal
// set the polarity
LL_TIM_OC_SetPolarity (TIM1, LL_TIM_CHANNEL_CH1, LL_TIM_OCPOLARITY_LOW);
//Set the Duty Cycle
LL_TIM_OC_SetCompareCH1(TIM1, 995-1);
// Set counter from 0
LL_TIM_SetCounter (TIM1, 0);
// Enable counter
LL_TIM_EnableCounter (TIM1);
//3- Enable clock access to PORTA
LL_AHB1_GRP1_EnableClock (LL_AHB1_GRP1_PERIPH_GPIOA);
//4- Set pin mode
LL_GPIO_SetPinMode (GPIOA, LL_GPIO_PIN_8, LL_GPIO_MODE_ALTERNATE);
//5- Set the alternate function
LL_GPIO_SetAFPin_8_15 (GPIOA, LL_GPIO_PIN_8, LL_GPIO_AF_1);
}
2022-07-07 11:01 PM
Set up pin in GPIO first.
Note, that both PSC and RCR are preloaded.
What does this do:
> LL_TIM_EnableUpdateEvent()
?
JW
2022-07-08 03:36 AM
Hello,
Thank you for your response.
I'm new to this so excuse me if I ask basic questions.
The LL_TIM_EnableUpdateEvent() is supposed to enable the update event. But I don't know how to set it properly.
Also, what do you mean by " Set up pin in GPIO first " ?
//3- Enable clock access to PORTA
LL_AHB1_GRP1_EnableClock (LL_AHB1_GRP1_PERIPH_GPIOA);
//4- Set pin mode
LL_GPIO_SetPinMode (GPIOA, LL_GPIO_PIN_8, LL_GPIO_MODE_ALTERNATE);
//5- Set the alternate function
LL_GPIO_SetAFPin_8_15 (GPIOA, LL_GPIO_PIN_8, LL_GPIO_AF_1);
Thank you, I appreciate your help