Skip to main content
Seng Tak Goh
Associate III
Mar 16, 2018 9:20 PM UTC
Question

How to generate PWM in OPM with Fast Mode with Independent Timer?

Posted on March 16, 2018 at 22:20

Hi Community,

On a STM32F407 MCU, I wish to generate a single pulse with TIM4 PWM when triggered by ADC watchdog interrupt, with least delay possible.

Taken from the reference manual RM0090 One-pulse Mode section, 

  1. Particular case: OCx fast enable:

    In One-pulse mode, the edge detection on TIx input set the CEN bit which enables the counter. Then the comparison between the counter and the compare value makes the output toggle. But several clock cycles are needed for these operations and it limits the minimum delay t

    DELAY

    min we can get.

    If you want to output a waveform with the minimum delay, you can set the OCxFE bit in the TIMx_CCMRx register. Then OCxRef (and OCx) is forced in response to the stimulus, without taking in account the comparison. Its new level is the same as if a compare match had occurred. OCxFE acts only if the channel is configured in PWM1 or PWM2 mode.

it seems like to have the OCxFE work I need a trigger from TRGI sources. Is there a way to trigger this with software, as if possible I would want my timer to work independently without a master? Actually the best solution I am looking for is a way to directly trigger the PWM output from the ADC itself without intervention from CPU.

Thanks in advance.

#tim #stm32f407 #pwm #ocxfe #opm #stm32-adc-awd-interupt
This topic has been closed for replies.

7 replies

waclawek.jan
Super User
Mar 16, 2018 11:02 PM UTC
Posted on March 17, 2018 at 00:02

The RM says, by setting OCxFE the trigger-to-output time shortens from 5 cycles presumably for case when CCR=1) to 3 cycles (presumably prescaled timer clock cycles). This is IMO not worth the hassle at all. I'd suggest to concentrate to get to starting the timer as fast as possible, by making sure the ADC ISR may preempt any other ISR, and by making sure the compiler won't insert any unnecessary code before the timer start happens.

Actually the best solution I am looking for is a way to directly trigger the PWM output from the ADC itself without intervention from CPU.

There is no such hardware on the 'F4, but there is something like that in 'F3 and 'L4 (maybe also 'F7 I didn't look).

JW

Seng Tak Goh
Associate III
Mar 17, 2018 6:48 AM UTC
Posted on March 17, 2018 at 06:48

I see. Thanks a lot JW! Btw what does IMO mean?

waclawek.jan
Super User
Mar 17, 2018 10:31 AM UTC
Posted on March 17, 2018 at 10:31

In My Opinion. Related to  IMHO, In My Humble Opinion.

https://en.wiktionary.org/wiki/IMO ♯ English

 

http://www.catb.org/~esr/jargon/html/I/IMHO.html

 

JW

Seng Tak Goh
Associate III
Mar 17, 2018 10:42 AM UTC
Posted on March 17, 2018 at 11:42

Geez that suggests I am getting obsolete. But am wondering are there really no way to use software to trigger a slave timer thus setting the TRGI?

waclawek.jan
Super User
Mar 17, 2018 11:59 AM UTC
Posted on March 17, 2018 at 11:59

Try

TIM4->EGR = TIM_EGR_TG;

JW

Seng Tak Goh
Associate III
Mar 17, 2018 1:36 PM UTC
Posted on March 17, 2018 at 13:36

I did before posting to this forum. That is meant for DMA and TRGO but does nothing to its own TRGI.