Triggering PWM output using SCT

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Triggering PWM output using SCT

1,117 次查看
vikramshan
Contributor I

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.

Analyzer_output.png

 

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

PWMs_Trigger_time.png

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)
{
}
}

 

 

 

0 项奖励
回复
3 回复数

1,089 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

For your question, Pls check if what I say is your requirement.

You have an external trigger signal called the "master pulse", the red signal in your block diagram. When the trigger signal is coming, the SCTimer counter is synchronized, and starts to count, you hope to output only  one pulse for P1, P2 and P3 PWM signals, then silent and wait for another trigger. am I right?

If it is the case, of course, the SCTimer can do it with state update.

Pls confirm if it is your requirement.

xiangjun_rong_0-1736741537193.png

BR

XiangJun Rong

0 项奖励
回复

1,080 次查看
vikramshan
Contributor I
Thanks for your reply XiangJun.
As per your understanding, my requirement is same . External pluse "Master pluse" triggered and reference with that I need to trigger the PWM outputs in P0,P1,P2 with different edge time.

Once external trigger is happened and I need to start SCT timer count. According to different edge time values for P0, P1, P2, this needs to be match the condition to set the output in the respective ports.
0 项奖励
回复

1,069 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Okay, I see your requirement.

But I have not found an application note or code for your case.

Maybe this ticket is helpful.

https://community.nxp.com/t5/LPC-Microcontrollers-Knowledge/SCTimer-implement-traffic-signal/ta-p/11...

I suggest you develop the code with writing the SCTimer register instead of calling SCTimer driving api function..

You have an external triggering signal, you can configure the falling edge of the external trigger signal to generate event for example event0. You can have the event0 to limit the SCTimer counter, and update the state from state0  to state1.

You can use match1/match2 to generate event1/event2 and generate P1 PWM signal.

You can use match3/match4 to generate event3/event4 and generate P2 PWM signal.

You can use match5/match6 to generate event5/event6 and generate P3 PWM signal.

You can use  the event6(match6 is the largest match value) to update the state from state1 to state0.

all the event1/2/3/4/5/6 are only enabled in state1.

Pls try to develop the code.

Hope it can help you

BR

Xiangjun Rong

 

0 项奖励
回复