SCTIMER_SetupCaptureAction not working ?

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

SCTIMER_SetupCaptureAction not working ?

982 Views
asier
Contributor III

Hi,

I'm using LPC822. I want to measure an input square wave signal from a falling edge to next falling edge. My code:

uint32_t fallEvent;
uint32_t CaptureT;

void CAP_init(void)
{
// configure the input mux for the sct timer input0 from external pin
INPUTMUX_Init(INPUTMUX);
INPUTMUX_AttachSignal(INPUTMUX, 0U, kINPUTMUX_SctPin0ToSct0);

sctimer_config_t sctimerInfo;

/* Enable clock of sct. */
CLOCK_EnableClock(kCLOCK_Sct);

SCTIMER_GetDefaultConfig(&sctimerInfo);
sctimerInfo.enableCounterUnify = false; // 2 contadores (H y L) de 16 bits cada uno
sctimerInfo.clockMode = kSCTIMER_System_ClockMode;
sctimerInfo.clockSelect = kSCTIMER_Clock_On_Rise_Input_0;
sctimerInfo.enableBidirection_l = false;
sctimerInfo.enableBidirection_h = false;
sctimerInfo.prescale_l = 3U; // dividido por 4
sctimerInfo.prescale_h = 0U; // dividido por 1
sctimerInfo.outInitState = 0U;
sctimerInfo.inputsync = (1 << 0U); // Sincronizar la entrada con el reloj del SCT para no perder pulsos.
/* Initialize SCTimer module */
SCTIMER_Init(SCT0, &sctimerInfo);

SCTIMER_CreateAndScheduleEvent(SCT0, kSCTIMER_InputFallEvent, 0u, kSCTIMER_Input_0, kSCTIMER_Counter_L, &fallEvent); //creates event on data input pin transition
SCTIMER_SetupCaptureAction(SCT0, kSCTIMER_Counter_L, &CaptureT, fallEvent); //captures input on pin fall transition event

// Define event interrupt callback
SCTIMER_SetCallback(SCT0, ctimer_cap0_callback, fallEvent);

// Enable interrupt
SCTIMER_EnableInterrupts(SCT0, 1<<fallEvent);
NVIC_EnableIRQ(SCT0_IRQn);

SCTIMER_StartTimer(SCT0, kSCTIMER_Counter_L);
}

void ctimer_cap0_callback(void)
{
     uint32_t capturelatch;

     capturelatch = CaptureT; // It fails

     //capturelatch = SCT0->COUNT; // It works

}

When fall event happens "ctimer_cap0_callback" is called but "CaptureT" register has 0 value. In the other hand, if I read STC0->COUNT counter value is correct. Why CaptureT is not getting counter value when defining "SCTIMER_SetupCaptureAction" ? 

Thanks,

Asier.

0 Kudos
3 Replies

963 Views
asier
Contributor III

Any answer about that ? 

Should I keep a sequence at defining Event, Limit, Capture or another action ? 

Thanks,

Asier.

0 Kudos

946 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello

 

Thank you for your interest in NXP Semiconductor products and the opportunity to serve you.

The sequence you are following for setting the events is correct. SCTIMER_SetupCaptureAction seems the ideal option for what you try to accomplish  From this I can suggest to modify this line:

sctimerInfo.clockSelect = kSCTIMER_Clock_On_Fall_Input_0;

 

SCTIMER_CreateAndScheduleEvent returns an status flag, you could check that flag to assure that the event was successfully created.

 

Let me know if this helpful, if you have more questions do not hesitate to ask me.

Best regards,

Omar

0 Kudos

928 Views
asier
Contributor III

Hello Omar,

Why do you suggest "sctimerInfo.clockSelect = kSCTIMER_Clock_On_Fall_Input_0;" ?

I was not getting capture value in my variable (CaptureT), so finally I've writed code this way:

SCT0->SCTCAPCTRL[0] = (1U << fallEvent); 

SCT0->REGMODE = (1U << fallEvent); // Capture mode

SCT0->LIMIT = (1U << fallEvent);

Thank you for your time,

Asier.