I want to set two PWM singals at a time ? But I the result is error.
My code :
SCTIMER_GetDefaultConfig(&sctimerInfo);
/* Initialize SCTimer module */
SCTIMER_Init(SCT0, &sctimerInfo);
/* Configure first PWM with frequency 24kHZ from first output */
pwmParam.output = DEMO_FIRST_SCTIMER_OUT;
pwmParam.level = kSCTIMER_HighTrue;
pwmParam.dutyCyclePercent = 90;
if (SCTIMER_SetupPwm(SCT0, &pwmParam, kSCTIMER_CenterAlignedPwm, 500U, sctimerClock, &event1) == kStatus_Fail)
{
return -1;
}
/* Configure second PWM with different duty cycle but same frequency as before */
pwmParam.output = DEMO_SECOND_SCTIMER_OUT;
pwmParam.level = kSCTIMER_HighTrue;
pwmParam.dutyCyclePercent = 90;
if (SCTIMER_SetupPwm(SCT0, &pwmParam, kSCTIMER_CenterAlignedPwm, 1000000U, sctimerClock, &event2) == kStatus_Fail)
{
return -1;
}
/* Start the timer */
SCTIMER_StartTimer(SCT0, kSCTIMER_Counter_L);
I find that the first PWM singal can't set successful when I set second PWM singal ,but the first PWM singal can work well when I just configure it. What make that happed?
thank you!
Solved! Go to Solution.
Hello yang1,
For one counter, only can generate one period PWM, when you set "1000000U" in
second PWM configuration, it will coverage the first setting "500u".
You can try to configure the SCT0 as two 16-bit counters.
BR
Alice
Thank you for your reply,I use two 16-bit counters to produce two pwms,but when I try to change their duty,it case a HardFault_Handler.
MY code:
i = SCT0->EV[eventCounterH].CTRL & SCT_EV_CTRL_MATCHSEL_MASK;
SCTIMER_StopTimer(SCT0, kSCTIMER_Counter_H);
SCT0->MATCH[i] = (5-1)<<16;
SCT0->MATCHREL[i] = (5-1)<<16;
SCTIMER_StartTimer(SCT0, kSCTIMER_Counter_H);
thank you!
Hello yang1,
For one counter, only can generate one period PWM, when you set "1000000U" in
second PWM configuration, it will coverage the first setting "500u".
You can try to configure the SCT0 as two 16-bit counters.
BR
Alice