Best way to turn PWM Output off using S08PA16 FTM

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

Best way to turn PWM Output off using S08PA16 FTM

1,380 Views
datamstr
Contributor II

Hello,

 

What is the best way to turn off a PWM Ouput from the FTM?

I am using two PWM Outputs and need to alternate between them with only one PWM Output running at a time.

 

I tried the method below on the FTM, but it does not work when I set FTMEN to 1. (required to get correct clock divider)

 

Code example:

FTM2_C4SC = 0x28; // set channel 4 as PWM Output
FTM2_C4SC = 0x00; // set channel 4 as Input Capture

When the code starts up, the channel is in Input Capture Mode and does not switch to PWM Mode.

 

Note: On the TPM this method works fine.

 

Suggestions?

 

Thanks,
David

Labels (1)
Tags (3)
10 Replies

853 Views
bigmac
Specialist III

Hello David,

Perhaps you could set the unwanted output for zero duty.  PWM mode would remain, but there should not be an output pulse present.

Regards,

Mac


0 Kudos

853 Views
datamstr
Contributor II

Hello Mac,

I found that I could not update the FTM Duty Cycle, so I placed the Init Code into a function and that did update the Duty Cycle. I discovered that the following code is needed to update Duty. I am puzzled why the counter must be stopped.

  /* FTM2_SC: TOF=0,TOIE=0,CPWMS=0,CLKS=0,PS=0 */

  FTM2_SC = 0x00U;                     /* Stop the counter */

  FTM2_C4V = CH4_Val;   // update Duty                                  

  FTM2_C5V = CH5_Val;  // update Duty                                   

  /* FTM2_SC: TOF=0,TOIE=1,CLKS=1,PS=0 */

  FTM2_SC = (FTM2_SC & (unsigned char)~(unsigned char)0x97U) | (unsigned char)0x48U;

Any thoughts on that?


Thanks,
David


0 Kudos

853 Views
eduardo_viramon
NXP Employee
NXP Employee

David, many of the registers in the FTM are buffered and updated in synch with the FTM clock at different moments. This is done to keep control applications synched and to avoid current or voltage ripples. If you want immediate update you have to, in fact, turn of the clock, update, and turn back on. But please notice that the duty cycle should update during the next PWM period in your application, according to the reference manual (12.4.10.3 CnVH:L registers in page 318 in PA16 RM).

Regarding your turning the channels on and off, when FTMEN = 1, the best way to do it is by using the Output Mask (FTMx_OUTMASK), you can also find it's description in the RM.

0 Kudos

853 Views
datamstr
Contributor II

Hi Eduardo,

I am not able to get the Duty Cycle to change without stopping the counter. I must be missing something to do with sync.

Thanks,

David

0 Kudos

853 Views
eduardo_viramon
NXP Employee
NXP Employee

Have you checked the RM chapter I mentioned to see in which case your particular FTM configuration would reload the channel values?

0 Kudos

853 Views
datamstr
Contributor II

OK, I made one more change, set CNTMAX = TRUE. Now the Duty Cycle is changing.


Thanks,
David

853 Views
digisnapmark
Contributor II

I'm running into a similar issue, so forgive my hijack.

9S08PT60, FTM2, simple PWM output.

If I leave FTMEN=0, the CV appears to buffer update fine when written, but if FTMEN=1, I can't figure how to get the counter to update.  SWSYNC=1, doesn't do it, CNTMAX=1 doesn't help.  The trick of shutting the PWM off (FTM2_SC=$00), writing the counter, then restarting the PWM does work, but clearly this is a workaround.

tanks

0 Kudos

853 Views
eduardo_viramon
NXP Employee
NXP Employee

Mark, the way registers update when FTMEN=1 depends on clocks and configuration. Section 12.4.10 of the S08PT60 ref manual describes each of these cases. The specifics of channel value are in section 12.4.10.3 in the bottom of page 357.

0 Kudos

853 Views
datamstr
Contributor II

Hello Eduardo,

Yes, I have been reading the PA16 RM. CLKS[1:0] is not 0:0, FTMEN = 1, the selected mode is not "Output Compare", and the SYNCEN bit = 1.

Therefore, the CnVH:L registers are updated by PWM Synchronization. Note: I am not sure why there are two references to software trigger, The SYS_SOPT2[FTMSYNC] bit and the SWSYNC bit. In my code I am writing to the CH4 and CH5 Values registers for FTM2 and then setting the FTM2_SYNC_SWSYNC = 1.

The PWM Duty Cycle is not changing.

Also, I saw the note that PWM Sync is only available in the combine mode. So I also set the bit as FTM2_COMBINE2_SYNCEN = 1 for Channels 4 & 5.

Any other thoughts?

Thanks,

David

0 Kudos

853 Views
datamstr
Contributor II

Hello Mac,

I am concerned about a runt pulse on CH 4 while starting the PWM output on CH 5 if I simply set the CH 4 Value to zero duty. I am thinking to try the Output Mask feature in the FTM. Perhaps doing both is the way to go.

Thanks,
David

0 Kudos