Dear Jan Rychter,
I have tested the K40, if I enable the FTM and output PWM signal, then clear the CLKS bits in FTM_SC to disable the FTM, the FTM_CHx channel will be in HIGH IMPEDANCE state, the external pull up/down resistor will determine the pin logic state.
I tested it on TWR-K40x256 board and CW for mcu ver10.6.
I attach the code here.
void FtmPinassignment(void);
void PWMOutput_EdgeAlignment(void);
void stop(void);
void delay(void);
int main(void)
{
int counter = 0;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
FtmPinassignment();
PWMOutput_EdgeAlignment();
FTM0_OUTINIT=0xFF;
delay();
stop();
asm("nop");
FTM0_OUTINIT=0x00;
PWMOutput_EdgeAlignment();
delay();
stop();
asm("nop");
for(;;) {
counter++;
}
return 0;
}
void PWMOutput_EdgeAlignment(void)
{
SIM_SCGC6|=0x03000000; //enable FTM0 and FTM0 module clock
FTM0_CONF=0xC0; //set up BDM in 11
FTM0_FMS=0x00; //clear the WPEN so that WPDIS is set in FTM0_MODE reg
FTM0_MODE|=0x05; //enable write the FTM CnV register
FTM0_MOD=1000;
FTM0_C0SC=0x28; //edge-alignment, PWM initial state is High, becomes low after match
FTM0_C1SC=0x28;
FTM0_COMBINE=0x02; //complementary mode for CH0&CH1 of FTM0
FTM0_COMBINE|=0x10; // dead timer insertion enabled in complementary mode for CH0&CH1 of FTM0
FTM0_C1V=500;
FTM0_C0V=500;
FTM0_C2SC=0x28;
FTM0_C3SC=0x28;
FTM0_COMBINE|=0x0200;
FTM0_COMBINE|=0x1000;
FTM0_DEADTIME=0x00;
FTM0_C3V=250;
FTM0_C2V=250;
FTM0_CNTIN=0x00;
FTM0_SC=0x08; //PWM edge_alignment, system clock driving, dividing by 1
}
void stop(void)
{
FTM0_SC=0x00;
}
void delay(void)
{
int i,j;
for(i=0; i<1000; i++)
{
for(j=100; j<100; j++)
{
asm("nop");
}
}
}
void FtmPinassignment(void)
{
SIM_SCGC5=SIM_SCGC5|0x3E00; //enable port A/B/C/D/E clock
PORTC_PCR1=0x400; //PTC1 in FTM mode :FTM0_CH0:
PORTC_PCR2=0x400; //PTC2 in FTM mode :FTM0_CH1
PORTC_PCR3=0x400; //PTC3 in FTM mode :FTM0_CH2
PORTC_PCR4=0x400; //PTC4 in FTM mode :FTM0_CH3
//PTD pins
PORTD_PCR4=0x400; //PTD4 in FTM mode :FTM0_CH4
PORTD_PCR5=0x400; //PTD5 in FTM mode :FTM0_CH5
//PTA pins
PORTA_PCR1=0x300; //PTA1 in FTM mode :FTM0_CH6
PORTA_PCR2=0x300; //PTA2 in FTM mode :FTM0_CH7
//configure PTB2 as FTM0_FLT3 as ALT6
PORTB_PCR2=0x600;
PORTC_PCR11=0x100; //PTC11 in GPIO mode and output mode
GPIOC_PDDR=0x800; //PTC direction register, PTC11 is in output mode
//in generally, PTC7 is in GPIO output mode, as an indicator to display if an ISR is executed
PORTC_PCR7=0x100; //PTC7 in GPIO mode and output mode
GPIOC_PDDR=0x80; //PTC direction register, PTC7 is in output mode
//PTA6 is toggled by ISR of PIT1 module, which can be an Fault or capture signal to test the Fault or capture function
PORTA_PCR6=0x100; //PTA6 in GPIO mode and output mode
GPIOA_PDDR=0x40; //PTC direction register, PTA6 is in output mode, PTA6 is pin5 of J4 on TWR-K40 board
//FTM1 quadrature mode input pin configuration
//PORTA_PCR8=0x600; //PTA8 is the FTM1 quadrature signal input pin
//PORTA_PCR9=0x600; //PTA9 is the FTM1 quadrature signal input pin
//PTB0 function as FTM1_QD_PHA
PORTB_PCR0=0x600;
//PTB1 functions as FTM1_QD_PHB
PORTB_PCR1=0x600;
}