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