cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4R5ZI - Timer - OPM mode. Why the module cannot successfully generate two consecutive OPM pulse trains without any delay in between ?

KVenk.1
Associate III

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.

9 REPLIES 9

Where do you wait until the pulse train finishes?

I don't Cube/HAL.

JW

Hi Jan,

Am using delay as shown below.

0693W000003Q2DzQAK.jpg

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

JW

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

Then make the delay longer.

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

JW

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 ?

> 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

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

KVenk.1
Associate III

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