I have a question regarding the generation of a single pulse (one shot) using the Flex Timer Output Compare method. I wish to generate an immediate pulse (positive edge) which last a given duration and returns back low - a simple single shot or one shot operation. I want the pulse to begin immediately by forcing the output to a high state and letting an OC match reset the pulse.
Using the output compare function I realize that I can set up a OC match to set the pulse high and then another OC match to reset the pulse to low. But what I wish to do is manually set the output high and then let a single OC match set the pulse back low.
Is there a proper S/W means to force the output high manually while the FTM is configured in OC mode? I see that there are registers like OUTINIT but this appears to be an initialization register and not a runtime. And I see the register SWOCTRL which appears to be the correct method, however from the manual this appears to be used for PWM synchronization and not OC mode? And there are different SYNCONF update mechanisms for SWOCTRL, again not appearing to be relevant to the OC mode.
This should be the simplest operation to generate a one-shop pulse but the actual implementation is not clear.... without having to resort to multiple OC operations or even bit-banging GPIO during OC matches.
Thanks - Bruce
解決済! 解決策の投稿を見る。
In thinking about this some more, it may be better to simply keep the pin high through the FTM and create the pulse only with OUTMASK.
This would have the least affect on other channels and would prevent race conditions.
The only thing is that we would need to elevate the OC interrupt service routines (which are very quick) to a very high priority.
Hi Peter and Daniel,
Thank you for the extra time and support on this simple question, the solutions the both of you provided should be more than enough to get this operational. Mark this one as solved!
- Bruce
Bruce,
Please see the simple project attached. It implements a one-shot function on all 8 channels of FTM0. In addition to the output compare, this function utilizes the OUTINIT to set the initial pin state and the OUTMASK to prevent action on other channels. An inactive channel is disabled with the OUTMASK. When a one-shot is desired, the one-shot function will set the pin high with OUTINIT, set up the output compare with interrupt enabled and enable the desired pin with OUTMASK. When the OC occurs an interrupt is triggered to clear the flag, disable the interrupt and disable the pin with OUTMASK. I hope this helps but there may be some race conditions that need to be taken into account. I did test various overlapping conditions and it looks good.
-Peter
In thinking about this some more, it may be better to simply keep the pin high through the FTM and create the pulse only with OUTMASK.
This would have the least affect on other channels and would prevent race conditions.
The only thing is that we would need to elevate the OC interrupt service routines (which are very quick) to a very high priority.
Hi Daniel,
Thanks for the reply. The PWM mode may work, however is this independent of all channels? The 8 channels are all doing the same operation but they are phase-shifted so the OC operations do not overlap. Does the mask affect all 8 channels? Is there example code showing this mode of operation using PWM?
On using the MODE_INIT, it appears that this will affect all 8 channels at the same time - they will all get re-initialized and the channels are independent. Or is there a way to have this happen to just one channel?
- Bruce
Hi,
Unlike the MODE_INIT function, OUTMASK can mask all the PWM channels independently.
Any write to the OUTMASK register stores the value in its write buffer and then it needs to be synchronized.
45.5.13.7 OUTMASK register synchronization, S32K1xx RM, rev.9.
Please refer to AN5303 Features and Operation Modes of FlexTimer Module on S32K.
4.1. Masking, inverting, and software-controlling features.
4.3. Updating FTM registers
A simple example that shows PWM duty-cycle synchronization, SW trigger, can be found here:
FTM S32k144 indepentent PWM channel
Regards,
Daniel
Hi Daniel - thank you for the response and feedback. I have one question of OUTMASK - in the reference manual table 45.4.3.12,4 which is the description of bits for the OUTMASK, it says:
Hi Bruce,
Output Compare can only clear, set or toggle the output pin on match but the initial state is not defined.
Have you consider using PWM instead? It can be disabled or masked on this first match.
The OUTINIT can be used to set the initial state of the OC output though.
The output can be driven HIGH by a write to MODE_INIT just before the OC starts and the output can be cleared on the match.
Regards,
Daniel