Hi there!
I am trying to generate a PWM signal using a TRK-KEA64 board. My project is using SKEAZN642 headers.
The approach was to use the FTM driver provided in Quick Start Package. But I can't really make it works!
My main.c code:
#include "FTM/FTM.h"
#include "GPIO/GPIO.h"
#include "CLK/CLK.h"
void ftm_callback()
{
FTM_ClrOverFlowFlag(FTM2);
OUTPUT_TOGGLE(PTC, PTC0);
}
void pwmSetDutyCycle(FTM_Type* pFTM, uint8_t ftmChannel, uint16_t dutyCycle )
{
uint32_t dc = pFTM->MOD - (pFTM->MOD) / (1000 / dutyCycle);
FTM_SetChannelValue(pFTM, ftmChannel, dc);
}
void PWM_Init(FTM_Type* pFTM, uint8_t ftmChannel, uint32_t clkFreqHz, uint32_t freqHz)
{
FTM_ConfigType FTM_Config = { 0 };
FTM_Config.modulo = 10000;
FTM_Config.clk_source = FTM_CLOCK_SYSTEMCLOCK;
FTM_Config.prescaler = FTM_CLOCK_PS_DIV1;
FTM_Config.mode = 1;
FTM_Config.toie = 0;
FTM_ChParamsType FTM_CH_Config = { 0 };
FTM_CH_Config.ctrl.bits.bMode = FTM_PWMMODE_EDGEALLIGNED;
FTM_CH_Config.ctrl.bits.bPWMPol = FTM_PWM_HIGHTRUEPULSE;
FTM_CH_Config.u16CnV = (FTM_Config.modulo);
FTM_Init(pFTM, &FTM_Config);
FTM_SetCallback(pFTM, ftm_callback);
FTM_ChannelInit(pFTM, ftmChannel, FTM_CH_Config);
}
int main(void)
{
FTM_Type *pFTM = FTM2;
uint8_t ftmChannel = 0;
CONFIG_PIN_AS_GPIO(PTC, PTC0, OUTPUT);
SIM_PINSEL |= SIM_PINSEL_FTM2PS0_MASK;
PWM_Init(pFTM, ftmChannel, DEFAULT_SYSTEM_CLOCK, 10000 );
pwmSetDutyCycle(pFTM, ftmChannel, 500);
while (1)
{
}
}
The interrupt was disabled intentionally!
The thing is that the code works perfectly on FRDM-KEAZ64 and the duty-cycle function is also working like a charm! But on TRK-KEA64 it does not! I observed actually that anything it's harder to do on TRK-KEA64 board than the others.
When interrupts are enabled, I can toogle the pin to generate an PWM with 50% duty-cycle but this is not what I want and I think doing this I will just misunderstand the purpose of FTM driver.
Any hint or idea? A working example of this would be highly appreciated!
PS: The example from QSP works on FRDM-KEAZ64 but not on TRK-KEA64!
PS2: I have also attached and example project!
PS3: It only seems to work with processor expert but I can't really figure out how and I can't really use PE in my project!