S32K144 - FTM Output Compare for Single Pulse

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32K144 - FTM Output Compare for Single Pulse

Jump to solution
3,305 Views
brucebowling
Contributor I

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

Labels (1)
Tags (1)
0 Kudos
1 Solution
2,900 Views
peter_pinewski
NXP Employee
NXP Employee

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. 

 

  • Set the pin high in the One-Shot function by clearing OUTMASK bit of desired channel
  • Drive pin low from OC interrupt by setting OUTMASK bit (making sure the inactive state is low)

 

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.

View solution in original post

0 Kudos
7 Replies
2,900 Views
brucebowling
Contributor I

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

0 Kudos
2,900 Views
peter_pinewski
NXP Employee
NXP Employee

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

0 Kudos
2,901 Views
peter_pinewski
NXP Employee
NXP Employee

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. 

 

  • Set the pin high in the One-Shot function by clearing OUTMASK bit of desired channel
  • Drive pin low from OC interrupt by setting OUTMASK bit (making sure the inactive state is low)

 

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.

0 Kudos
2,900 Views
brucebowling
Contributor I

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

0 Kudos
2,900 Views
danielmartynek
NXP TechSupport
NXP TechSupport

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

0 Kudos
2,900 Views
brucebowling
Contributor I

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:

Defines if the channel output is masked or unmasked.
0b - Channel output is not masked. It continues to operate normally.
1b - Channel output is masked. It is forced to its inactive state.
So if I read this, it implies that if I mask a channel that it "is forced to its inactive state". Does this mean that it then follows the corresponding bit value in OUTINIT? And if you do set a channel to its "inactive state" using OUTMASK, if you then issue another OUTMASK register update, this time with the bit cleared does the output stay at this state? In other words, when you issue a OUTINIT with OUTMASK masking all of the other 7 channels, does subsequent OUTMASK operations on other channels reset the first one, or is the state latched when you issue the OUTINIT/OUTMASK?
In my application I need to have all 8 channels run this one-shot mode, and they are all phased independently and have different widths so one channel may be in the middle of a pulse while another channel is just initiating a pulse. I do not the act of setting up one channel to stomp over other channels. The combination of OUTINIT and OUTMASK seem like this could be what I need, but need to verify that they work orthogonally between channels.
- Bruce
0 Kudos
2,900 Views
danielmartynek
NXP TechSupport
NXP TechSupport

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

0 Kudos