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.