Thanks. I could not find the FTM.c attachment, but in the meantime with lots of trial and error I have something that runs. I could not manage to achieve this with the SDK functions, and some of the necessary settings are not documented (or at least I could not find them). So here is the code, maybe it helps others:
int pwm_init(uint32_t f)
{
float clk = (float) CLOCK_GetFreq(kCLOCK_BusClk);
float modmax = 65530., fmod;
uint16_t fms, prescale, prescale_bits;
/* set prescaler 1...128 */
for (prescale_bits = 0U; prescale_bits <= 8U; prescale_bits++)
{
prescale = 1U << prescale_bits;
fmod = clk / prescale / (float) f;
if (fmod < modmax)
break;
}
if (prescale_bits > 7 || fmod < 100.)
{
PRINTF("no valid prescaler found\r\n");
return 1;
}
CLOCK_EnableClock(kCLOCK_Ftm3);
fms = PWM_FTM->FMS;
if (fms & 0x40U) // write protection enabled
PWM_FTM->MODE = 0x5U; // WPDIS=1, FTMEN=1
else
PWM_FTM->MODE = 0x1U; // don't touch WPDIS=1, FTMEN=1
PWM_FTM->CNTIN = 0x0U; // start from zero
PWM_FTM->CNT = 0x0U; // set this before setting MOD
PWM_FTM->MOD = (uint32_t) floor((double) fmod - 0.5); // round(fmod-1.0)
PWM_FTM->OUTINIT = 0x0FU; // High=inactive as default
PWM_FTM->OUTMASK = 0x0U; // all unmask // ghh
PWM_FTM->POL = 0x0U; // no inversion
PWM_FTM->COMBINE = 0x2121U; // Combine 0+1 and 2+3
PWM_FTM->SYNC = 0x0BU; // SYNCHOM,CNTMAX,CNTMIN
PWM_FTM->SYNCONF = 0xFB4U; // enhanced sync mode, software sync
PWM_FTM->PWMLOAD = 0x20FU; // Enable updates
PWM_FTM->CONTROLS[0].CnSC = 0x4U; // low active
PWM_FTM->CONTROLS[1].CnSC = 0x0U;
PWM_FTM->CONTROLS[2].CnSC = 0x4U; // low active
PWM_FTM->CONTROLS[3].CnSC = 0x00U;
PWM_FTM->CONTROLS[4].CnSC = 0x00U;
PWM_FTM->CONTROLS[5].CnSC = 0x00U;
PWM_FTM->CONTROLS[6].CnSC = 0x00U;
PWM_FTM->CONTROLS[7].CnSC = 0x00U;
PWM_FTM->CONTROLS[0].CnV = 0x0U;
PWM_FTM->CONTROLS[1].CnV = (PWM_FTM->MOD)/10;
PWM_FTM->CONTROLS[2].CnV = ((PWM_FTM->MOD)/10)*5;
PWM_FTM->CONTROLS[3].CnV = ((PWM_FTM->MOD)/10)*6;
PWM_FTM->SC = 0x08U | prescale_bits; // clock=system, starts timer
return 0;
}
void pwm_set_duty(float x1, float x2)
{
...
PWM_FTM->CONTROLS[0].CnV = start1;
PWM_FTM->CONTROLS[1].CnV = end1;
PWM_FTM->CONTROLS[2].CnV = start2;
PWM_FTM->CONTROLS[3].CnV = end2;
PWM_FTM->SYNC = 0x80U; // Trigger Software Sync
}