Hi everyone, myself new to peripheral interface programming , started understanding and hands on programming in LPC54102 by NXP SDK examples.
I achieved three(Port 0, port 1, Port 2) PWMs output using SCT on defined configuration (Dutycycle, match register value).
Question on this topic is , I need to trigger all the three pwms outputs according to configure trigger time (edge time). Currently all the PWMs outputs are trigger at start of the duty cycle. I need to use the timer functionality to generate interrupt to trigger the output, if this is the way then it is normal way of using timer not SCT way which is autonomous.
Kindly give solution to configure the SCT to trigger the output on specified time with reference with master clock.
My program output is as follow as, pwm period is 100ns and its duty cycle is 6ns. It all triggers at the start of the duty cycle.

I want to trigger all the pwms with different trigger time(edge) as follows :

My example code built with default SDK example - 3PWMs with same state
int main(void)
{
sctimer_config_t sctimerInfo;
sctimer_pwm_signal_param_t pwmParam;
uint32_t stateNumber;
uint32_t eventFirstNumberOutput, eventSecondNumberOutput, eventPwm1NumberInput,eventPwm2NumberInput,eventPwm3NumberInput;
uint32_t sctimerClock;
/* Board pin, clock, debug console init */
/* attach 12 MHz clock to USART0 (debug console) */
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
/* enable clock for GPIO*/
CLOCK_EnableClock(kCLOCK_Gpio0);
CLOCK_EnableClock(kCLOCK_Gpio1);
BOARD_InitPins();
BOARD_BootClockPLL150M(); /* Rev B device can only support max core frequency to 96Mhz.
Rev C device can support 150Mhz,use BOARD_BootClockPLL150M() to boot core to 150Mhz.
DEVICE_ID1 register in SYSCON shows the device version.
More details please refer to user manual and errata. */
BOARD_InitDebugConsole();
sctimerClock = SCTIMER_CLK_FREQ;
/* Print a note to terminal */
PRINTF("\r\nSCTimer example to output edge-aligned PWM signal\r\n");
PRINTF("\r\nWhen user presses a switch the PWM signal will be seen from Out %d ",
(uint32_t)DEMO_SECOND_SCTIMER_OUT);
PRINTF("\r\nWhen user presses the switch again PWM signal on Out %d will turn off ",
(uint32_t)DEMO_SECOND_SCTIMER_OUT);
PRINTF("\r\nThe PWM signal from Out %d will remain active all the time ", (uint32_t)DEMO_FIRST_SCTIMER_OUT);
/* Default configuration operates the counter in 32-bit mode */
SCTIMER_GetDefaultConfig(&sctimerInfo);
/* Initialize SCTimer module */
SCTIMER_Init(SCT0, &sctimerInfo);
stateNumber = SCTIMER_GetCurrentState(SCT0);
/* Configure PWM params with frequency 24kHZ from first output */
pwmParam.output = DEMO_FIRST_SCTIMER_OUT;
pwmParam.level = kSCTIMER_HighTrue;
pwmParam.dutyCyclePercent = 10;
/* Schedule events in current state; State 0 */
/* Schedule events for generating a PWM with 10% duty cycle from first Out in the current state */
if (SCTIMER_SetupPwm(SCT0, &pwmParam, kSCTIMER_EdgeAlignedPwm, 10000000U, sctimerClock, &eventFirstNumberOutput) ==
kStatus_Fail)
{
return -1;
}
/* Schedule an event to look for a rising edge on input 1 in this state */
if (SCTIMER_CreateAndScheduleEvent(SCT0, kSCTIMER_MatchEventOnly, 1, kSCTIMER_Input_1, kSCTIMER_Counter_L,
&eventPwm1NumberInput) == kStatus_Fail)
{
return -1;
}
/* Set the output when we reach the PWM period */
SCTIMER_SetupOutputSetAction(SCT0, DEMO_FIRST_SCTIMER_OUT, eventPwm1NumberInput);
if (SCTIMER_CreateAndScheduleEvent(SCT0, kSCTIMER_MatchEventOnly,0, kSCTIMER_Input_1, kSCTIMER_Counter_L,
&eventPwm1NumberInput) == kStatus_Fail)
{
return -1;
}
/* Clear the output when we reach the PWM pulse value */
SCTIMER_SetupOutputClearAction(SCT0, DEMO_FIRST_SCTIMER_OUT, eventPwm1NumberInput);
pwmParam.output = DEMO_SECOND_SCTIMER_OUT;
pwmParam.dutyCyclePercent = 10;
if (SCTIMER_CreateAndScheduleEvent(SCT0, kSCTIMER_InputLowAndMatchEvent,1, kSCTIMER_Out_2, kSCTIMER_Counter_L,
&eventPwm2NumberInput) == kStatus_Fail)
{
return -1;
}
/* Clear the output when we reach the PWM pulse value */
SCTIMER_SetupOutputClearAction(SCT0, DEMO_SECOND_SCTIMER_OUT, eventPwm2NumberInput);
if (SCTIMER_CreateAndScheduleEvent(SCT0, kSCTIMER_InputLowAndMatchEvent,0, kSCTIMER_Out_2, kSCTIMER_Counter_L,
&eventPwm2NumberInput) == kStatus_Fail)
{
return -1;
}
/* Set the output when we reach the PWM period */
SCTIMER_SetupOutputSetAction(SCT0, DEMO_SECOND_SCTIMER_OUT, eventPwm2NumberInput);
// PWM3
if (SCTIMER_CreateAndScheduleEvent(SCT0, kSCTIMER_InputLowAndMatchEvent,1, kSCTIMER_Out_2, kSCTIMER_Counter_L,
&eventPwm3NumberInput) == kStatus_Fail)
{
return -1;
}
/* Clear the output when we reach the PWM pulse value */
SCTIMER_SetupOutputClearAction(SCT0, DEMO_THIRD_SCTIMER_OUT, eventPwm3NumberInput);
if (SCTIMER_CreateAndScheduleEvent(SCT0, kSCTIMER_InputLowAndMatchEvent,0, kSCTIMER_Out_2, kSCTIMER_Counter_L,
&eventPwm3NumberInput) == kStatus_Fail)
{
return -1;
}
/* Set the output when we reach the PWM period */
SCTIMER_SetupOutputSetAction(SCT0, DEMO_THIRD_SCTIMER_OUT, eventPwm3NumberInput);
/* Enable at the NVIC */
EnableIRQ(SCT0_IRQn);
/* Start the timer, use counter L as we are operating counter in 32-bit mode */
SCTIMER_StartTimer(SCT0, kSCTIMER_Counter_L);
while (1)
{
}
}