K32L2B21: spark at the beginning of PWM sequence

cancel
Showing results for 
Search instead for 
Did you mean: 

K32L2B21: spark at the beginning of PWM sequence

139 Views
nre
Contributor II

Hello, i'm using K32L2B21 with MCUxpresso v.9.0.

When I start a PWM to generate a sound for a second time, an undesired sporadic pulse is generated at the beginning of the PWM sequence, as shown on the pic1. It could be because the duty cycle is 100% instead of 5% as expected.

Timer configuration is shown on pic2.

Initialization is following:

const tpm_config_t TPM1_config = {
.prescale = kTPM_Prescale_Divide_8,
.useGlobalTimeBase = false,
.triggerSelect = kTPM_Trigger_Select_0,
.triggerSource = kTPM_TriggerSource_External,
.enableDoze = false,
.enableDebugMode = false,
.enableReloadOnTrigger = true,
.enableStopOnOverflow = false,
.enableStartOnTrigger = false,
.enablePauseOnTrigger = false
};

const tpm_chnl_pwm_signal_param_t TPM1_pwmSignalParams[] = {
{
.chnlNumber = kTPM_Chnl_0,
.level = kTPM_HighTrue,
.dutyCyclePercent = 5U
}
};

void TPM1_init(void) {

TPM_Init(TPM1_PERIPHERAL, &TPM1_config);
TPM_SetupPwm(TPM1_PERIPHERAL, TPM1_pwmSignalParams, sizeof(TPM1_pwmSignalParams) / sizeof(tpm_chnl_pwm_signal_param_t), kTPM_EdgeAlignedPwm, 1000U, TPM1_CLOCK_SOURCE);
TPM_EnableInterrupts(TPM1_PERIPHERAL, kTPM_Chnl0InterruptEnable);
EnableIRQ(TPM1_IRQN);

}

 

main()

{

TPM_StartTimer(TPM1_PERIPHERAL, kTPM_SystemClock);

wait 10 s

TPM_StopTimer(TPM1_PERIPHERAL);

wait 2 s

TPM_StartTimer(TPM1_PERIPHERAL, kTPM_SystemClock);  //<---- here the spark is generated

}

 

Dynamically i'm setting the sound period by 

TPM_SetTimerPeriod(TPM1_PERIPHERAL, USEC_TO_COUNT(value, TPM_SOURCE_CLOCK));

 

0 Kudos
0 Replies