Hi,
I have a very very simple requirement but just couldn't seem to find the answer in a reasonable amount of time.
I am using MCUXpresso and the K64 baremetal C drivers supplied. This job is super simple, I just have two PWM's on FTM0.I just want 100Hz PWM with varied high time, super simple motor controller application. For some reason the gap between high pulses varies when i update the PWM using the driver like this instead of just changing the hi time it seems to "start agian" or something and the low time increases between pulses.
I read the reference manual and figered i should set it like this:
//SETUP
ftm_config_t ftmInfo;
ftm_chnl_pwm_signal_param_t ftmParam[2];
PORT_SetPinMux(RC1_M_PORT, RC1_M_PIN, RC1_M_ALT);
PORT_SetPinMux(RC2_M_PORT, RC2_M_PIN, RC2_M_ALT);
ftmParam[0].chnlNumber = (ftm_chnl_t)RC1CH_PWM;
ftmParam[0].level = kFTM_LowTrue;
ftmParam[0].dutyCyclePercent = 0U;
ftmParam[0].firstEdgeDelayPercent = 0U;
ftmParam[0].enableDeadtime = false;
ftmParam[1].chnlNumber = (ftm_chnl_t)RC2CH_PWM;
ftmParam[1].level = kFTM_LowTrue;
ftmParam[1].dutyCyclePercent = 0U;
ftmParam[1].firstEdgeDelayPercent = 0U;
ftmParam[1].enableDeadtime = false;
FTM_GetDefaultConfig(&ftmInfo);
ftmInfo.prescale = kFTM_Prescale_Divide_16;
ftmInfo.pwmSyncMode = (uint32_t)kFTM_SoftwareTrigger;
//I thought this flag hsould tell it to update the PWM when it clocks back over to min and i should get my perfect 2XKhz PWM with varied "high time"
ftmInfo.reloadPoints = kFTM_CntMin;
FTM_Init(FTM0, &ftmInfo);
if(FTM_SetupPwm(FTM0, ftmParam, 2U, kFTM_EdgeAlignedPwm, 100U, TPM_SOURCE_CLOCK) != kStatus_Success)
{
while(1); //Stop for debug
}
FTM_StartTimer(FTM0, kFTM_SystemClock);
FTM_SetDutyCycle(FTM0, (ftm_chnl_t)RC1CH_PWM, 0);
FTM_SetDutyCycle(FTM0, (ftm_chnl_t)RC2CH_PWM, 0);
....
for(;;)
{
//software to do things to the PWM values
FTM_SetDutyCycle(FTM0, (ftm_chnl_t)RC1CH_PWM, new_HighTimePulseValue);
FTM_SetDutyCycle(FTM0, (ftm_chnl_t)RC2CH_PWM, new_LowTimePUlseValue);
FTM_SetSoftwareTrigger(FTM0, true);
}
//I dont want to use a percentage, i want exact numbers for my PWM, so I just made this function which does the same as the drvier FTM_UpdatePwmDutycycle(); function
void FTM_SetDutyCycle(FTM_Type *base, ftm_chnl_t chnlNumber, uint16_t dutyCycle)
{
base->CONTROLS[chnlNumber].CnV = dutyCycle;
}
I just want exactly 100Hz PWM with my custom high time...