cancel
Showing results for 
Search instead for 
Did you mean: 

How to make PWM one shot output?

SAkhi.951
Associate III

Hello, I need to make software triggered one pulse output for 300 ms. The question is what is the best way to do this? I have found that PWM can work in one-pulse mode, but it looks like it requires external trigger to start, which is not an option for me. The other option I thought about is to use and of pulse ISR to stop PWM, but I am not sure if it is the best way to do it.

The desired behaviour is following:

When needed I use function

HAL_TIM_PWM_Start();

It does one high pulse for 300 ms and then turns off.

Thank you in advance!

4 REPLIES 4
Uwe Bonnes
Principal III

I you do not mind some jitter for a 300 ms pulse, set up you systick timer for e.g. 1 ms and count the pulses. If you need exact timing and the pulse is inactive before and starts active, set up ARR and the compare values and start the puls manualin one pulse mode. If you need the pulse inactive when started and only active after some time, again set up PWN as needed, but start with OPM unset bur add an interrupt routine at update ti stop the timer.

SAkhi.951
Associate III

Thank you @Uwe Bonnes​ , I have made using a simple timer TIM6. I have also tried using one pulse mode, but it didn't work for me. CAn you describe in details how can I manually start one pulse and what ARR values should be ?

Uwe Bonnes
Principal III

enable timer clock, care for BTDR_MOE, setup GPIO as timer

CCR = PWM_Length

ARR = Period_length

CR1 = TIM_CR1_CEN | TIM1_CR1_OPM

Which STM32 is this, and on which pin are you trying to generate the PWM?

My impression was, that TIM6 is always the "basic Timer", with no CC channel...

JW