cancel
Showing results for 
Search instead for 
Did you mean: 

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

Seng Tak Goh
Associate III
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
7 REPLIES 7
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

Posted on March 17, 2018 at 06:48

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

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
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?

Posted on March 17, 2018 at 11:59

Try

TIM4->EGR = TIM_EGR_TG;

JW

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.

Posted on March 17, 2018 at 14:59

I see. I have no other ideas.

JW

[EDIT] well, I have one, at the cost of 2 pins - connect the TIM4_CH1 pin with some other pin set as GPIO output, and then you can trigger by toggling the GPIO pin...

But then you could just simply set the pin you use to output the pulse to GPIO Out (with respective ODR being set to 1 previously), then start the timer, and after the few pulses needed to engage the timer's output switch the pin back to AF...