2018-03-16 02:20 PM
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,
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.
2018-03-16 04:02 PM
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
2018-03-16 11:48 PM
I see. Thanks a lot JW! Btw what does IMO mean?
2018-03-17 03:31 AM
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
2018-03-17 03:42 AM
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?
2018-03-17 04:59 AM
Try
TIM4->EGR = TIM_EGR_TG;
JW
2018-03-17 06:36 AM
I did before posting to this forum. That is meant for DMA and TRGO but does nothing to its own TRGI.
2018-03-17 07:59 AM
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...