MCXN SCTIMER

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

MCXN SCTIMER

1,389件の閲覧回数
Vagni
Contributor IV

I successfully run the SDK sctimer_pwm_with_dutycycle_change example program on the MCX-N5XX-EVK board. I successfully changed the PWM mode from Center-Aligned to Edge-Aligned.

But I get the following issues:

  1. The SCT outputs a short high impulse when I set 0% duty cycle.
  2. The SCT outputs a short low impulse when I set 100% duty cycle.
  3. In addition to the dudty cycle, I also need to change the PWM frequency run-time, so I tried to re-configure the PWM with my following function:

 

short PWM_FreqSet( unsigned long pwmFreq_Hz, unsigned char duty)
{
	short RetVal = 0;
    sctimer_pwm_signal_param_t pwmParam;
    uint32_t sctimerClock = SCTIMER_CLK_FREQ;

	/* Stop the 32-bit unify timer */
    SCTIMER_StopTimer(SCT0, kSCTIMER_Counter_U);

	/* Configure PWM with the new frequency */
	pwmParam.output           = DEMO_SCTIMER_OUT;
	pwmParam.level            = kSCTIMER_HighTrue;
	pwmParam.dutyCyclePercent = duty;
	if (SCTIMER_SetupPwm(SCT0, &pwmParam, kSCTIMER_EdgeAlignedPwm, pwmFreq_Hz, sctimerClock, &eventNumberOutput) == kStatus_Success)
	{
		RetVal = 1;
		/* Start the 32-bit unify timer */
		SCTIMER_StartTimer(SCT0, kSCTIMER_Counter_U);
	}
	
	return RetVal;
}
​



But it does not work, although SCTIMER_SetupPwm() returns kStatus_Success. And, after the first calling to my PWM_FreqSet() function, the PWM timer does not work any more, I need to reset my board to recover it.

 

How to fix those issues on SCTIMER?

 

ラベル(2)
0 件の賞賛
返信
3 返答(返信)

1,360件の閲覧回数
Harry_Zhang
NXP Employee
NXP Employee

Hi @Vagni 

1. When setting 0% duty cycle or 100% duty cycle, This can be done by bypassing the PWM setup logic and directly setting output pin high.

2. I try to change PWM Frequency at Runtime.

    /* Configure first PWM with frequency 24kHZ from first output */
    pwmParam.output           = DEMO_FIRST_SCTIMER_OUT;
    pwmParam.level            = kSCTIMER_HighTrue;
    pwmParam.dutyCyclePercent = 50;
    if (SCTIMER_SetupPwm(SCT0, &pwmParam, kSCTIMER_CenterAlignedPwm, 48000U, sctimerClock, &event) == kStatus_Fail)
    {
        return -1;
    }

    /* Start the 32-bit unify timer */
    SCTIMER_StartTimer(SCT0, kSCTIMER_Counter_U);

    SCTIMER_StopTimer(SCT0, kSCTIMER_Counter_U);

    /* Configure PWM with the new frequency */
    pwmParam.output           = DEMO_FIRST_SCTIMER_OUT;
    pwmParam.level            = kSCTIMER_HighTrue;
    pwmParam.dutyCyclePercent = 50;
    if (SCTIMER_SetupPwm(SCT0, &pwmParam, kSCTIMER_CenterAlignedPwm, 24000U, sctimerClock, &event) == kStatus_Fail)
    {
	return -1;
    }
    SCTIMER_StartTimer(SCT0, kSCTIMER_Counter_U);

It can work.

HangZhang_0-1730434429340.png

HangZhang_1-1730434447701.png

 

BR

Hang

0 件の賞賛
返信

1,338件の閲覧回数
Vagni
Contributor IV

Thank you, Hang.

Your code is pretty much the same as mine, unless you use Center-Aligned PWM mode and the same dutycycle value when you change the PWM frequency.

Maybe changing the PWM frequency at run-time is possible only with the current dutycycle value?

What about the 'event' variable? It needs to be cleared before changing the PWM frequency at run-time?

0 件の賞賛
返信

1,302件の閲覧回数
Harry_Zhang
NXP Employee
NXP Employee

Hi @Vagni 

1. Maybe changing the PWM frequency at run-time is possible only with the current dutycycle value?

Yes

2. What about the 'event' variable? It needs to be cleared before changing the PWM frequency at run-time?

I test it, i change the PWM frequency at run-time directly, it can work.

BR

Hang

0 件の賞賛
返信