Skip to main content
RKage.3
Associate
February 17, 2021
Solved

Generate Single pulse using timer using HAL / CubeMx

  • February 17, 2021
  • 4 replies
  • 6926 views

I have been reading reading anything i could find on Timers, but I'm still confused about the setup in CubeMx.

I just want to trigger a timer in software, that generates a SINGLE pulse with a set width (and if possible after a set dely) on a pin, but the CubeMx configuration is incredibly badly documented and pretty confusing, if you don't already know what you are doing.

can someone please point me in the right direction?

Also please don't post a bunch of register setups and then say "I don't use CubeMx", that's not what i am asking, and I have seen it on so many forum posts.

This topic has been closed for replies.
Best answer by RKage.3

Ok, I have found the answer myself.

Here is the setup: (every setting i don't mention is either disabled or in it's standard state)

  • Clock Source: Internal clock
  • Channelx PWM Generation Channelx (if set to Output compare, it won't reset after the timer is done counting)
  • One Pulse Mode Enabled

under PWM Generation Channelx:

  • Pulse gives the width of the pulse

Polarity and Pulse Width:

The combination of CounterMode, PWM Mode and CH Polarity gives you different output polarities delay.

in Code:

execute this onece:

HAL_TIM_OnePulse_Start(&htimX, TIM_CHANNEL_X);

To trigger the pulse just execute this, whenever you need a pulse to be generated:

TIMx->CR1 |= TIM_CR1_CEN;

4 replies

Javier1
Principal
February 17, 2021

Are you referring to the One pulse mode of stm timers?

hit me up in https://www.linkedin.com/in/javiermuñoz/
RKage.3
RKage.3AuthorBest answer
Associate
February 17, 2021

Ok, I have found the answer myself.

Here is the setup: (every setting i don't mention is either disabled or in it's standard state)

  • Clock Source: Internal clock
  • Channelx PWM Generation Channelx (if set to Output compare, it won't reset after the timer is done counting)
  • One Pulse Mode Enabled

under PWM Generation Channelx:

  • Pulse gives the width of the pulse

Polarity and Pulse Width:

The combination of CounterMode, PWM Mode and CH Polarity gives you different output polarities delay.

in Code:

execute this onece:

HAL_TIM_OnePulse_Start(&htimX, TIM_CHANNEL_X);

To trigger the pulse just execute this, whenever you need a pulse to be generated:

TIMx->CR1 |= TIM_CR1_CEN;

Associate III
May 5, 2023

Instead of TIMx->CR1 |= TIM_CR1_CEN; you can simply do this:

__HAL_TIM_ENABLE(&htimX);

(just for clarity of intent of the code)

ST Employee
May 9, 2023

Hi All,

This question has been routed to our Online Support Center for direct support and we will be taking this question directly from there. This question will be taken offline.

Regards,

Jake

ST Support

Piranha
Principal III
May 10, 2023

First, the issue was solved and there is nothing to "support" here. Second, it was 2 years ago...

waclawek.jan
Super User
May 10, 2023

@Jacob WOODRUFF​ ,

Besides, as Piranha said above, there is nothing to"support" here, are you aware of the fact that this is a public forum? Taking a question "offline" is censoring it, is it really what ST wants to do here?

JW

@Lina DABASINSKAITE​