Hi,
I've tried multiple time to use complementary mode in K80 and i'm still unable to. The problem is that ch4 and ch5 outputs exactly the same(i know that they are paired) but in complementary mode ch5 should be inverted but it's not. Am i missing any setup? I tried different things and ch5 is never inverted.
Solved! Go to Solution.
Found a problem, 2 pins on MCU were shorted to each other, that's why i had same output on both of them and that's why PWM wasn't working at all when i tried to output 2 different things on 2 channels
Found a problem, 2 pins on MCU were shorted to each other, that's why i had same output on both of them and that's why PWM wasn't working at all when i tried to output 2 different things on 2 channels
Hi, Grzegorz,
I think if you set the bit 25 of the FTM0_COMBINE(COMP3 bit), the FTM0_CH4/FTM0_CH5 output signals will invert each other, I think you should clear the COMBINE3 (bit24) of FTM0_COMBINE for simplicity.
FTM0_COMBINE|=1<<25; //set COMP3 bit
FTM0_COMBINE&=~(1<<24); //clear COMBINE3 bit
If you still have issue, pls upload your code here so that we can have a review.
BR
XiangJun Rong
Hi Grzegorz
I just tried the following on a FRDM-K82F board (using uTasker FlexTimer HAL):
PWM_INTERRUPT_SETUP pwm_setup;
pwm_setup.int_type = PWM_INTERRUPT;
pwm_setup.int_handler = 0;
// Set up two complimentary output pairs which are phase shifted from each other
//
pwm_setup.pwm_mode = (PWM_EDGE_ALIGNED);
pwm_setup.pwm_frequency = PWM_FREQUENCY(1000, 128); // generate 1000Hz on PWM output
pwm_setup.pwm_value = _PWM_PERCENT(50, pwm_setup.pwm_frequency); // 50% PWM (high/low)
pwm_setup.pwm_reference = (_TIMER_0 | 0); // timer module 0, channel 0
fnConfigureInterrupt((void *)&pwm_setup); // enter configuration for PWM test
pwm_setup.pwm_mode |= (PWM_POLARITY); // complimentary output
pwm_setup.pwm_reference = (_TIMER_0 | 1); // timer module 0, channel 1
fnConfigureInterrupt((void *)&pwm_setup); // enter configuration for PWM test
pwm_setup.pwm_mode &= ~(PWM_POLARITY);
pwm_setup.pwm_mode |= (PWM_COMBINED_PHASE_SHIFT); // the following channel pair are phase shifted (only possible in edge aligned mode)
pwm_setup.pwm_phase_shift = _PWM_PERCENT(25, pwm_setup.pwm_frequency); // 45° phase shift
pwm_setup.pwm_reference = (_TIMER_0 | 4); // timer module 0, channel 2
fnConfigureInterrupt((void *)&pwm_setup); // enter configuration for PWM test
pwm_setup.pwm_mode |= (PWM_POLARITY | PWM_SYS_CLK | PWM_PRESCALER_128);// clock PWM timer from the system clock with /128 pre-scaler [clock is enabled here so that all prepared values are synchronised]
pwm_setup.pwm_reference = (_TIMER_0 | 5); // timer module 0, channel 3
fnConfigureInterrupt((void *)&pwm_setup); // enter configuration for PWM test
It generates 1kHz PWM 50% complimentary signals on PTC1, PTC2 and PTD4, PTD5, whereby the CH0,1 and CH4,5 are 45° phase shifted [binary attached]
This is a snap-shot of the FTM0 registers so that you can compare with yours.
Note that to get complimentary outputs on a channel pair the COMP0 flag needs to be set. Since it is possible to do the non-shifted channels in non-combined mode I have set up the first 2 independently but one phase reversed (using MS_ELS_PWM_LOW_TRUE_PULSES channel setting instead) but could have used combined mode to do the same. CH4/5 (the ones you are interested in) are in combined/complimentary mode.
Regards
Mark
Thanks for quick response, i double checked all registers. Everything works perfectly fine but not the complimentary mode.
I compared values from your registers with mine, there are slight differences but nothing major except that i did not setup C5SC and C5V( but any attempt on changing values there end up with dead output)
I got COMP2 set in FTM0_COMBINE register but not COMBINE(is it required? i dont need to shift PWM or add deadtime at this point).
CH4 and CH5 still looks the same, CH5 not inverted. By the way is there a way to unpair channels?
Grzegorz
If you don't set the COMBINE mode you are not pairing the channels (they are all independent) and so the other control bits will do nothing (or maybe have strange effects).
If you are programming at the low level (rather than using decent HAL/APIs that do the detailed work) you will need to understand the workings by reading the following and experimenting until all is fully clear: https://www.nxp.com/docs/en/application-note/AN5142.pdf
In case you don't actually need to pair the channels (not needed if not shifting or inserting dead-time, etc.) you can invert the output in its dedicated channel control register by using "Low-True Pulses" rather than "High-True Pulses":
This is what I explained as the way I did it on the first two channels; whilst I showed the COMBINE method on the second two channels (which are then paired) and can be phase shifted.
Note that the 0xa4 has inverted output to 0xa8 due to the setting detailed in the user's manual's table. Change these bits in the channel you want to have inverted and then it will probably work.
Regards
Mark
If you don't set the COMBINE mode you are not pairing the channels (they are all independent) and so the other control bits will do nothing (or maybe have strange effects).
Well that's strange because i'm not setting COMBINE and my channels are still somehow linked, change in one channel always affects the second one. And i get same output on both channels, without even setting COMBINE. I thought they're linked by default.
I've read AN5142, atleast the part with complimentary pwm and i can understand why there is A8 and A4 set in CnSC but i can't set them up like this because they're linked and setting up both channels end up with dead output.
I'm not using API's because i can't fully understand them and i'm trying to figure out the basics then i will get to the point where i can easily use them
Grzegorz
Channels are only paired when you combine them, otherwise they are independent - this is true for all Kinetis parts with FlexTimers or TMPs. If they are not behaving like this you must be setting something incorrectly or making a measurement mistake.
I changed the code to remove the PHASE_SHIFT (which is what is used to decide whether to use normal or combined mode) and have rebuild the FRDM-K82F binary (attached). Now it operates without the 45° phase shift and all 4 channels are independent.
Again I can show you the register content to do this - you will need to investigate all register details to work out what you are doing differently to explain the complications.
Regards
Mark
Kinetis: http://www.utasker.com/kinetis.html
Kinetis K82:
http://www.utasker.com/kinetis/FRDM-K82F.html
For less questions and restrictions, and faster, cheaper developments: try uTasker for Kinetis