AnsweredAssumed Answered

Kinetis PWM Frequency Changes on Zero Crossing

Question asked by Gary Sinde on Sep 29, 2019
Latest reply on Oct 3, 2019 by Gary Sinde

I am currently using a PWM output on my MK22FN512 to tone a speaker based upon a measured signal from an antenna. I update the speaker about every 500 msec to 1000 msec and only use 100 Hz to 3000 Hz mapped to signal power (using a log function but that doesn't matter). 

 

On frequency changes, I get a little click and I am sure it is my software "FORCE" update of the PWM registers. I am not a motor control guy but there must be a way to change the frequency just as the sine wave crosses zero for no disruptions. It is not critical for me but would be a nice bug fix before I release the product.

I will dive in to the datasheet but I thought I would reach out to the community.

 

Current Code:

ftm_chnl_pwm_signal_param_t Speaker_Params;

 

void SpeakerFreq(unsigned int freq, unsigned int duty)
{
Speaker_Params.level = kFTM_LowTrue;
Speaker_Params.dutyCyclePercent = (duty & 0x3F);

 

FTM_SetupPwm(FTM0, &Speaker_Params, 1, kFTM_CenterAlignedPwm, freq, SOUND_CLOCK_SOURCE);

 

if (speaker_on == false)
   {

   // Only set level when turning on the speaker
   FTM_UpdateChnlEdgeLevelSelect(FTM0, Speaker_Params.chnlNumber, Speaker_Params.level);
   }

 

// Software trigger to update registers
FTM_SetSoftwareTrigger(FTM0, true);

 

speaker_on = true;
}

 

Thanks

Outcomes