Hello (bigmac)
I am trying to output a 6 channel PWMout for a 3 phase bridge with a MP16.
For this i setup the Flextimer2 within this module for edge aligned PWM , ch0 to ch5.
This setup works okay.
Now i want to use the combine + complementary mode on all channels, so that odd numbered channels will invert the even numbered PWM pulses, and also a dead time is inserted.
I am not able to do this
I am adding my Init routine which i am unable to make work.(just for testing i have updated channel values with the ones shown)
void Timer2_init(void) { FTM2C0SC = Channel0_Start; FTM2C1SC = Channel0_Start; //value is 0x24 FTM2C2SC = Channel0_Start; FTM2C3SC = Channel0_Start; FTM2C4SC = Channel0_Start; FTM2C5SC = Channel0_Start; // Timer1 period FTM2MOD = TIMER_OVERFLOW; //62.5us FTM2MODE = 0x05 ; //WPDIS and FTMEN enabled FTM2COMBINE0 = 0x13; //Dead time , Complementary ,combine FTM2COMBINE1 = 0x13; //Dead time , Complementary ,combine FTM2COMBINE2 = 0x13; //Dead time , Complementary ,combine FTM2DEADTIME = 0x86; // 83=3us //Initial duty cycle FTM2C0V = FTM2C1V = FTM2C2V = FTM2C3V = FTM2C4V = FTM2C5V = 0; //Start timer FTM2SC = 0x4A ; // for 16KHz PWM out } void interrupt 14 FTM2OVF (void) { FTM2C0V = 0; FTM2C1V = 120;// FTM2C2V = 0;// FTM2C3V = 140; FTM2C4V = 0; FTM2C5V = 160; FTM2SC_TOF=0; }
已解决! 转到解答。
Hi,
Actually, you still didn't understand well about PWM synchronization. please read that section(12.5.11) carefully, but not use those configuration we are not recommended, if you use those configurations, the results are not guaranteed.
Hope you understand.
B.R
XWP
Hi Abhijit,
I can't help you directly and I know it's obvious but have you checked the Freescale website? A quick "flextimer" search gave me several motor control application notes:
Thanks,
Ian
Hi Jagtap,
If (CLKS[1:0] not = 00 and FTMEN = 1) then FTMxCnVH:L registers are updated by PWM synchronization. For detailed info about PWM synchronization,please take refer to Section 12.5.11 of the reference manaul.
that means channel registers can't be loaded in the overflow ISR. If you wrote those channel registers before start the timer(CLKS = 0), then those value can be loaded immediately.Like below.
FTM2C0SC = Channel0_Start;
FTM2C1SC = Channel0_Start; //value is 0x24
FTM2C2SC = Channel0_Start;
FTM2C3SC = Channel0_Start;
FTM2C4SC = Channel0_Start;
FTM2C5SC = Channel0_Start; // Timer1 period
FTM2MOD = TIMER_OVERFLOW; //62.5us 10.
FTM2MODE = 0x05; //WPDIS and FTMEN enabled 11.
FTM2COMBINE0 = 0x13; //Dead time , Complementary ,combine 12.
FTM2COMBINE1 = 0x13; //Dead time , Complementary ,combine 13.
FTM2COMBINE2 = 0x13; //Dead time , Complementary ,combine 14.
FTM2DEADTIME = 0x86; // 83=3us 15.//Initial duty cycle 16.
FTM2C0V = FTM2C1V = FTM2C2V = FTM2C3V = FTM2C4V = FTM2C5V = 0;
//Start timer 18.
// load channel registers below.
FTM2C0V = 0;
FTM2C1V = 120; //
FTM2C2V = 0;//
FTM2C3V = 140;
FTM2C4V = 0;
FTM2C5V = 160;
FTM2SC = 0x4A; // start time
Hope it can solve your problem.
B.R
XWP
Hi Weiping
Can you write an init code for me?
I have channels 0,2,4 as complementary pairs of channels 1,3,5
I want to combine these pairs and add a deadtime between switching.
I have written this in every possible way with every possible register_bit enabled/disabled
I update the FTM2CnV values in its overflow register
Hello
Strangely an initialisation which the reference manual prohibits from using is giving me results what i require.
void Timer2_init(void)
{
FTM2MOD = TIMER_OVERFLOW; //62.5us
FTM2COMBINE0 = FTM2COMBINE0_DTEN_MASK | FTM2COMBINE0_COMP_MASK ;//| FTM2COMBINE0_COMBINE_MASK;
//The ref. manual says that the COMPLEMENTARY mode CANNOT be used without COMBINE mode
//I ignored it to see what happens
FTM2COMBINE1 = FTM2COMBINE0_DTEN_MASK | FTM2COMBINE0_COMP_MASK;//| FTM2COMBINE0_COMBINE_MASK;
FTM2COMBINE2 = FTM2COMBINE0_DTEN_MASK | FTM2COMBINE0_COMP_MASK;// | FTM2COMBINE0_COMBINE_MASK;
FTM2DEADTIME = 0x8C; // 8C=16MHz (sys clock)/4 = 4MH(250ns)
//250ns x 48 clock cycles = 12us, whereas i get close to 2us
FTM2C0SC = Channel_even_Start;// 0x28 , Edge aligned PWM , high true pulses
FTM2C1SC = Channel_odd_Start; // 0-1 channels in same limb or half bridge
FTM2C2SC = Channel_even_Start;//0x24, Edge aligned PWM , Low true pulses
FTM2C3SC = Channel_odd_Start;
FTM2C4SC = Channel_even_Start;
FTM2C5SC = Channel_odd_Start;
FTM2C0V = 0;
FTM2C1V = 0;// init all values to 0
FTM2C2V = 0;
FTM2C3V = 0;
FTM2C4V = 0;
FTM2C5V = 0;
FTM2SC = 0x49; // for 16KHz (8MHz/2 = 4MHz and MODULO count is 249)
}
void interrupt 14 FTM2OVERFLOW ISR(void)
{
// do some work and then update channel registers
FTM2C0V = sin_table[Duty_Cycle1]; // High true pulses
FTM2C1V = sin_table[Duty_Cycle1]; //Low true pulses
//same values since same limb but different pulsesFTM2C2V = sin_table[Duty_Cycle2];
FTM2C3V = sin_table[Duty_Cycle2];
FTM2C4V = sin_table[Duty_Cycle3];
FTM2C5V = sin_table[Duty_Cycle3];
FTM2SC_TOF = 0 ;
}
so you see. SO many things happening with prohibited usages
1)FTM2MODE = 0, and still DTVAL and DTPS can be written
2)COMPLEMENTARY mode used Without COMBINE mode
3)DEADTIME value written something else and result is something else
Please someone explain
Hi,
Actually, you still didn't understand well about PWM synchronization. please read that section(12.5.11) carefully, but not use those configuration we are not recommended, if you use those configurations, the results are not guaranteed.
Hope you understand.
B.R
XWP
I really don't understand why the initialisation you provided does not work?
I have read the document for at least 5 times since morning and got what SWSYNC and CNTIN does
Yet the provided code and the ones altered here do not work.
Am really worried now :smileysad:
Hi
It is working now with a bit of tinkering :smileyhappy:
FTM2CNTIN = TIMER_OVERFLOW/2;// does not work
FTM2CNTIN = 0; // works
One more rudimentary mistake i was making was regards the Clock to timer.
In TPMv2 and v3 CLKSB:CLKSA = 01 was BUS CLOCK
whereas in FLEXTIMER it is ICSOUT (When FTMEN =1)
Silly of me to overlook that
Otherwise now i observe proper sync between adjacent channels and calculated dead times appear on scope
Thanks for the support.Appreciated
Hi,
Please try to use following routines.
void Timer2_init(void)
{
FTM2C0SC = Channel0_Start;
FTM2C1SC = Channel0_Start; //value is 0x24
FTM2C2SC = Channel0_Start;
FTM2C3SC = Channel0_Start;
FTM2C4SC = Channel0_Start;
FTM2C5SC = Channel0_Start; // Timer1 period
FTM2MOD = TIMER_OVERFLOW; //62.5us 10.
FTM2MODE = 0x05; //WPDIS and FTMEN enabled 11.
FTM2SYNC |= 0x01; // load buffer when counter matches with FTM2CNTIN
FTM2CNTIN = TIMER_OVERFLOW/2; // load buffer when counter counts up to half of modulo
FTM2COMBINE0 = 0x33; //Dead time , Complementary ,combine 12.
FTM2COMBINE1 = 0x33; //Dead time , Complementary ,combine 13.
FTM2COMBINE2 = 0x33; //Dead time , Complementary ,combine 14.
FTM2DEADTIME = 0x86; // 83=3us 15.//Initial duty cycle 16.
FTM2C0V = FTM2C1V = FTM2C2V = FTM2C3V = FTM2C4V = FTM2C5V = 0;
FTM2SC = 0x4A; // for 16KHz PWM out 19.
//Start timer 18.
}
interrupt void FTM2OVF_ISR (void)
{
FTM2SC_TOF=0;
FTM2C0V = 0;
FTM2C1V = 120; //
FTM2C2V = 0;//
FTM2C3V = 140;
FTM2C4V = 0;
FTM2C5V = 160;
FTM2SYNC_SWSYNC = 1;
}
B.R
XWP
Hello Weiping
Thanks for the snippet
Unfortunately, it isn't working :smileysad:
The port pins associated with the Timers will never change state.
Even numbered channels stay at 0v and odd numbered channels stay at 5v.
I do not see any pulses
Hi Weiping thanks for replying
First of all i want you to know that I am really tired now with all this :smileycry:
I used the same settings in the same sequence.
Some unexplained things happen
1)Even though CHnIE is disabled , the CHnF is set and the program just hangs
2)Sometimes it functions correctly but i see that FTMCnV is not updated in the overflow ISR where i manually upload new values for the channel.
3)My Channel pins remain inactive throughout the state.
iansmusical I have checked a lot of documents and i believe i am doing the right things, yet no result
heres my init code
{
FTM2C1SC = Channel_odd_Start; // FTM2C2SC = Channel_even_Start; FTM2C3SC = Channel_odd_Start; // FTM2C4SC = Channel_even_Start; FTM2C5SC = Channel_odd_Start; FTM2MOD = TIMER_OVERFLOW; //62.5us // FTM2FMS_WPEN =0; FTM2MODE |= 0x05 ; //WPDIS and FTMEN enabled FTM2COMBINE0 |= 0x13; //Dead time , Complementary ,combine FTM2COMBINE1 |= 0x13; //Dead time , Complementary ,combine FTM2COMBINE2 |= 0x13; //Dead time , Complementary ,combine FTM2DEADTIME |= 0x86; // 83=3us FTM2C0V = 0; FTM2C1V = 0; FTM2C2V = 0; FTM2C3V = 0; FTM2C4V = 0; FTM2C5V = 0; FTM2SC = TIMER_START;
}
heres my ISR bit
FTM2C1V = sin_table[Duty_Cycle1]+125;//120 Deg apart+21 // R_BAR =0 ; // FTM2C2V = sin_table[Duty_Cycle2]+125;//240 Deg apart+10 // Y_BAR =0 ; FTM2C3V = sin_table[Duty_Cycle2]+125; // FTM2C4V = sin_table[Duty_Cycle3]+125;//120 Deg apart+21 FTM2C5V = sin_table[Duty_Cycle3]+125;//240 Deg apart+10 // B_BAR =0 ; FTM2SC_TOF = 0 ;
I find that the FTM2CnV values never update