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 pulses
FTM2C2V = 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