cancel
Showing results for 
Search instead for 
Did you mean: 

Generate Single pulse using timer using HAL / CubeMx

RKage.3
Associate

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.

1 ACCEPTED SOLUTION

Accepted Solutions
RKage.3
Associate

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;

View solution in original post

6 REPLIES 6
Javier1
Principal

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

we dont need to firmware by ourselves, lets talk
RKage.3
Associate

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;

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

__HAL_TIM_ENABLE(&htimX);

(just for clarity of intent of the code)

Jacob WOODRUFF
ST Employee

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

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

@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​