STM32L4R5ZI - Timer - OPM mode. Why the module cannot successfully generate two consecutive OPM pulse trains without any delay in between ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-21 10:10 AM
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.
- Labels:
-
STM32L4 series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-21 4:40 PM
Where do you wait until the pulse train finishes?
I don't Cube/HAL.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-21 11:29 PM
Hi Jan,
Am using delay as shown below.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-22 12:32 AM
According to the waveform you posted, 30ms is good for only the first 15 pulses, so why the surprise then?
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-22 12:59 AM
As i said, i want 20 pulses followed by 5 pulses. Due to insufficient delay, i am getting only 15 pulses instead of 20.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-22 2:05 AM
Then make the delay longer.
I still don't understand, what is your problem here.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-23 11:07 AM
My Problem is, controller should generate required pulses without any external delay. But it is not the case, why? Why the pulses get truncated when there is no delay or lesser delay ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-23 11:37 AM
> controller should generate required pulses without any external delay
If you overwrite the timer with new settings, it stops doing what it did before and works according to those new settings.
When the pulse sequence (as counted by the repetition counter) finishes, an Update is generated, and timer disables itself. So you can either observe the TIMx_CR1.CEN bit, or the TIMx_SR.UiF bit (provided it has been cleared previously). Alternatively, you can enable the Update interrupt, and then when Update happens, that interrupt is invoked, and then you can set up the timer for new pulse train there.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-23 8:56 PM
Thanks Jan. It is a good point. Let me try it and update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-22 9:28 AM
With enough delay soon after starting the One pulse mode, I am getting all the pulses at the OCx pin.
