Hello. This is Mr. Dongho Ha
I am trying FTM EPWM using KEXX_DRIVERS_V1.2.1_DEVD example.
My source code is below (using IAR Compliler)
---------------------------------------------------------------------------------------------------------------------------------
#include "common.h"
#include "gpio.h"
#include "ftm.h"
#include "sysinit.h"
#define ACT_LED_Init() GPIOA->PDDR |= GPIO_PTA7_MASK
#define ACT_LED_Toggle() GPIOA->PTOR = GPIO_PTA7_MASK
int main (void)
{
unsigned char i;
sysinit();
ACT_LED_Init();
printf("\nRunning the FTM EPWM_demo project.\n");
UART_WaitTxComplete(TERM_PORT);
// FTM2 is set as edge aligned pwm mode, high true pulse */
FTM_PWMInit(FTM2, FTM_PWMMODE_EDGEALLIGNED, FTM_PWM_HIGHTRUEPULSE);
FTM_SetFTMEnhanced(FTM2); //FTMEN enable
FTM_SetModValue(FTM2, 40000); //update MOD value, 16bit value, 1KHz
/* set clock source, start counter */
FTM_ClockSet(FTM2, FTM_CLOCK_SYSTEMCLOCK, FTM_CLOCK_PS_DIV1);
FTM_SetChannelValue(FTM2, FTM_CHANNEL_CHANNEL1, 0);
i=0;
while(1)
{
FTM_SetChannelValue(FTM2, FTM_CHANNEL_CHANNEL1, i*400);
if(i>=100)
{
i=0;
}
Delay_ms(10);
i++;
}
}
--------------------------------------------------------------------------------------------------------------------------------
I used FTM2 channel 1. (GPIO PTC1 FTM2CH1)
This example operate well. (0~100% variation for one second)
Modulation frequency : 1kHz.
But all FTM2 port output 1kHz pulse with fixed duty.
[ PTC0(FTM2CH0),PTC2(FTM2CH2),PTC3(FTM2CH3),PTB4(FTM2CH4),PTB5(FTM2CH5) ]
FTM2CH0~FTM2CH5 output 1Khz pulse regardless of GPIO setting(Input/Output).
I want to operate only PTC1(FTM2CH1) well.
And if FTM Module change , (using FTM0, FTM1) , MCU be halted.
Question1.
I want to operate only PTC1(FTM2CH1) well.
And I want to use other GPIO pins(PTC0, PTC2, PTC3, PTB4, PTB5) for input or output normaly.
Question2.
I want to use FTM0 or FTM1 EPWM well.
I tried 2days.
But I couldn't find any method.
I want help for these problems.
Thank you.
Solved! Go to Solution.
Hi,
Did you change SIM->PINSEL0 and PINSEL1? There are some functions you can use in sim.c, like
SIM_RemapFTM2CH2ToPTD0(); //ptc2
SIM_RemapFTM2CH0ToPTH0(); //ptc0
Otherwise these pin will always output PWM wave.
Regards,
Jing
Hi,
Many of the I/O pins are shared with on-chip peripheral functions. The peripheral modules have priority over the I/O, so when a peripheral is enabled, the associated I/O functions are disabled. So if you want to use PTC0, PTC2, PTC3, PTB4, PTB5, you can remap the ALT FTM2 function to other pin. But it seems you can't eliminate them.
Regards,
Jing
Hi,
Thank you for answer.
I changed port FTM2 CH1 -> FTM2 CH2 and remapped to PTD0
I tested this program using remap function.
However, the same symptoms are repeated.
PTC0, PTC1, PTC3, PTC4, PTC5 occur pulse.
Thank you.
Hi,
Did you change SIM->PINSEL0 and PINSEL1? There are some functions you can use in sim.c, like
SIM_RemapFTM2CH2ToPTD0(); //ptc2
SIM_RemapFTM2CH0ToPTH0(); //ptc0
Otherwise these pin will always output PWM wave.
Regards,
Jing
Thank you for answer.
I already tested by remap function.
But same result.
Thank you again.
Hi,
I try this on FTM_EPWM_demo project. I just add above 2 sentence and the PWM wave on ptc0 and ptc2 stop. Please try it again.
Regards,
Jing
I appreciate to you.
I tried this operation by your comment.
I used KINETIS KE06 44pin chip.
It don't have PTF, PTG port.
So I remapped PTC(FTM2) port to PTF(FTM2CH0) and PTG(FTMCH2~FTMCH5).
now PTC0, PT2~PTC5 input/output operate well and FTM2CH1 PWM also.
But I'm disappointed with MCU structure.
Thank you again for you.
Hi,
Yes, I agree with you. It's structure is a bit strange:smileyhappy: