Associate III
August 21, 2020
Question
STM32L4R5ZI - Timer - OPM mode. Why the module cannot successfully generate two consecutive OPM pulse trains without any delay in between ?
- August 21, 2020
- 9 replies
- 3590 views
Hi All,
I am able to generate OPM pulses using Timer 1 of L4R5ZI MCU.
Problem is - I want pulse train having 20 pulses first time. Once they are generated, after ~5ms delay, I want another pulse train having 5 pulses. This is not working. OC1 pin has pulses truncated first time i.e instead of 20 pulses, i get 10 or 15 only. What is the reason for this ? But this works if i increase the delay to 20ms.
Below is the output am getting for this code. As you can see, i should have got 20 pulses having higher duty cycle but i got only 15.

For clarity am including the core part of the code here. In this code i have used 30ms delay which works ok.
void main()
{
driveStepper(2000, 500, 19);
HAL_Delay(30);
driveStepper(1000, 500, 4);
}
void driveStepper(uint16_t freq, uint16_t duty, uint16_t count)
{
htim1.Init.Period = freq;
htim1.Init.RepetitionCounter = count;
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
{
Error_Handler();
}
sConfigOC.Pulse = duty;
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
HAL_TIM_OnePulse_Start(&htim1, TIM_CHANNEL_1);
__HAL_TIM_ENABLE(&htim1);
}For complete code, pls find the attachment.
