Problems with sets of inputs and outputs with SCTimer

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problems with sets of inputs and outputs with SCTimer

738 Views
Rainbow73
Contributor III

Hi,
I configured 4 outputs from the MCUXpresso
tool as shown by the function SCTimer_1_int generated automatically by the tool (see below).

I added the LookSpeedCtrl function that I need to see if the pulse value changes on the inputs to understand if there has been a block of the connected devices.
What I see is that if I activate the code as shown under the command of the fourth output it no longer works. Instead if I remove the LookSpeedCtrl function it starts working again. Where is the problem in your opinion? What am I doing wrong?

Regards

 

void LookSpeedCtrl(void)
{
/* Schedule an event to look for a rising edge on input 1 */
if (SCTIMER_CreateAndScheduleEvent(SCTIMER_1_PERIPHERAL,
kSCTIMER_InputRiseEvent,
0,
kSCTIMER_Input_1,
kSCTIMER_Counter_L,
&initialRisingEdgeInput1) == kStatus_Fail)
{
PRINTF(" SCTIMER_CreateAndScheduleEvent1 ERROR \r\n");
return(-1);
}

if (SCTIMER_SetupCaptureAction(SCTIMER_1_PERIPHERAL,
kSCTIMER_Counter_L,
&CaptureReg1,
initialRisingEdgeInput1) == kStatus_Fail)
{
PRINTF(" SCTIMER_SetupCaptureAction1 ERROR \r\n");
return(-1);
}
/* Schedule an event to look for a rising edge on input 2 */
if (SCTIMER_CreateAndScheduleEvent(SCTIMER_1_PERIPHERAL,
kSCTIMER_InputRiseEvent,
0,
kSCTIMER_Input_2,
kSCTIMER_Counter_L,
&initialRisingEdgeInput2) == kStatus_Fail)
{
PRINTF(" SCTIMER_CreateAndScheduleEvent2 ERROR \r\n");
return(-1);
}

if (SCTIMER_SetupCaptureAction(SCTIMER_1_PERIPHERAL,
kSCTIMER_Counter_L,
&CaptureReg2,
initialRisingEdgeInput2) == kStatus_Fail)
{
PRINTF(" SCTIMER_SetupCaptureAction2 ERROR \r\n");
return(-1);
}
/* Schedule an event to look for a rising edge on input 3 */
if (SCTIMER_CreateAndScheduleEvent(SCTIMER_1_PERIPHERAL,
kSCTIMER_InputRiseEvent,
0,
kSCTIMER_Input_3,
kSCTIMER_Counter_L,
&initialRisingEdgeInput3) == kStatus_Fail)
{
PRINTF(" SCTIMER_CreateAndScheduleEvent3 ERROR \r\n");
return(-1);
}

if (SCTIMER_SetupCaptureAction(SCTIMER_1_PERIPHERAL,
kSCTIMER_Counter_L,
&CaptureReg3,
initialRisingEdgeInput3) == kStatus_Fail)
{
PRINTF(" SCTIMER_SetupCaptureAction3 ERROR \r\n");
return(-1);
}
/* Set the callback funcitons */
SCTIMER_SetCallback(SCTIMER_1_PERIPHERAL, SCT_Initial_Detection_Callback1, initialRisingEdgeInput1);
SCTIMER_SetCallback(SCTIMER_1_PERIPHERAL, SCT_Initial_Detection_Callback2, initialRisingEdgeInput2);
SCTIMER_SetCallback(SCTIMER_1_PERIPHERAL, SCT_Initial_Detection_Callback3, initialRisingEdgeInput3);

/* Enable interrupts for both events */
SCTIMER_EnableInterrupts(SCTIMER_1_PERIPHERAL, 1 << initialRisingEdgeInput1);
SCTIMER_EnableInterrupts(SCTIMER_1_PERIPHERAL, 1 << initialRisingEdgeInput2);
SCTIMER_EnableInterrupts(SCTIMER_1_PERIPHERAL, 1 << initialRisingEdgeInput3);

NVIC_EnableIRQ(SCTIMER_1_IRQN);

}

const sctimer_config_t SCTimer_1_initConfig = {
.enableCounterUnify = true,
.clockMode = kSCTIMER_System_ClockMode,
.clockSelect = kSCTIMER_Clock_On_Rise_Input_0,
.enableBidirection_l = false,
.enableBidirection_h = false,
.prescale_l = 0,
.prescale_h = 0,
.outInitState = (uint8_t)(0)
};
void SCTimer_1_init(void) {
SCTIMER_Init(SCTIMER_1_PERIPHERAL, &SCTimer_1_initConfig);
/* Initialization of state 0 */
SCTIMER_SetupPwm(SCTIMER_1_PERIPHERAL, &SCTimer_1_pwmSignalsConfig[0], kSCTIMER_EdgeAlignedPwm, 24000U, SCTIMER_1_CLOCK_FREQ, &SCTimer_1_pwmEvent[0]);
SCTIMER_SetupPwm(SCTIMER_1_PERIPHERAL, &SCTimer_1_pwmSignalsConfig[1], kSCTIMER_EdgeAlignedPwm, 24000U, SCTIMER_1_CLOCK_FREQ, &SCTimer_1_pwmEvent[1]);
SCTIMER_SetupPwm(SCTIMER_1_PERIPHERAL, &SCTimer_1_pwmSignalsConfig[2], kSCTIMER_EdgeAlignedPwm, 24000U, SCTIMER_1_CLOCK_FREQ, &SCTimer_1_pwmEvent[2]);
SCTIMER_SetupPwm(SCTIMER_1_PERIPHERAL, &SCTimer_1_pwmSignalsConfig[3], kSCTIMER_EdgeAlignedPwm, 24000U, SCTIMER_1_CLOCK_FREQ, &SCTimer_1_pwmEvent[3]);

LookSpeedCtrl();

SCTIMER_StartTimer(SCTIMER_1_PERIPHERAL, kSCTIMER_Counter_L);
}

 

 

0 Kudos
Reply
4 Replies

729 Views
Rainbow73
Contributor III

Hi,

I understand where is the problem.
I hadn't seen that the "SCTIMER_SetupPwm" function creates 2 events for each configured output.
So I having 4 outputs and 3 inputs I reach the 11 events created instead the maximum number of events is:


/* @brief Number of events */
#define FSL_FEATURE_SCT_NUMBER_OF_EVENTS (10)

Can I increase this define?Is there any problem with changing its value?

Best Regards

0 Kudos
Reply

717 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello

Hope you are well. Which part number are you using?
Each device has a limited number of events and that macro tells us the events available in the module. I do not suggest you change it.
You may consider using the CTimer for the PWM and not exceed the number of events available.

If you have more questions do not hesitate to ask me.
Best regards,
Omar
 


 

0 Kudos
Reply

712 Views
Rainbow73
Contributor III

Hello,
Thanks for your reply.

I am using an LPC54606.

For now we have solved it  managing two fans with the same pwm output. Are there any examples of PWM management with Ctimer instead of SCTimer? They might be useful to me.

Best Regards

0 Kudos
Reply

703 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Thank you for letting me know your part number.

The SCTimer of the LPC546xx family is limited to 10 events.
We have PWM examples with the CTimer at the SDK, I suggest you use it as a reference.

Omar_Anguiano_0-1627495669001.png


If you have more questions do not hesitate to ask me.
Best regards,
Omar
 

0 Kudos
Reply