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)
|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.
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?
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 (188.8.131.52 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.
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.
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 184.108.40.206 in the bottom of page 357.
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?
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.