Skip to main content
KVenk.1
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.

 0693W000003Q1GYQA0.bmp

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.

This topic has been closed for replies.

9 replies

waclawek.jan
Super User
August 21, 2020

Where do you wait until the pulse train finishes?

I don't Cube/HAL.

JW

KVenk.1
KVenk.1Author
Associate III
August 22, 2020

Hi Jan,

Am using delay as shown below.

0693W000003Q2DzQAK.jpg

waclawek.jan
Super User
August 22, 2020

According to the waveform you posted, 30ms is good for only the first 15 pulses, so why the surprise then?

JW

KVenk.1
KVenk.1Author
Associate III
August 22, 2020

As i said, i want 20 pulses followed by 5 pulses. Due to insufficient delay, i am getting only 15 pulses instead of 20.

waclawek.jan
Super User
August 22, 2020

Then make the delay longer.

I still don't understand, what is your problem here.

JW

KVenk.1
KVenk.1Author
Associate III
August 23, 2020

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 ?

waclawek.jan
Super User
August 23, 2020

> 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

KVenk.1
KVenk.1Author
Associate III
August 24, 2020

Thanks Jan. It is a good point. Let me try it and update.

KVenk.1
KVenk.1Author
Associate III
September 22, 2020

With enough delay soon after starting the One pulse mode, I am getting all the pulses at the OCx pin.