Setup Input Capture SCT for LPC812

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

Setup Input Capture SCT for LPC812

854 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by seowwoo on Tue Dec 02 22:12:36 MST 2014
HI,
I tried to setup PIO_15 as CTIN_0 but nothing happen to trigger the interrupt at SCT_IRQHandler(). I used the PIO_17 as the input for CTIN_0(PIO_15) from the SysTick_Handler().

I used the example(nxp_lpcxpresso_812_periph_sct) from the lpcopen_2_01_lpcxpresso_nxp_lpcxpresso_812.zip and modified the code as follow: Could anyone help what wrong with my code in sct_init()? Thanks.

/*
* @brief State Configurable Timer (SCT) example
*
* @note
* Copyright(C) NXP Semiconductors, 2012
* All rights reserved.
*
* @par
* Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the
* LPC products.  This software is supplied "AS IS" without any warranties of
* any kind, and NXP Semiconductors and its licensor disclaim any and
* all warranties, express or implied, including all implied warranties of
* merchantability, fitness for a particular purpose and non-infringement of
* intellectual property rights.  NXP Semiconductors assumes no responsibility
* or liability for the use of the software, conveys no license or rights under any
* patent, copyright, mask work right, or any other intellectual property rights in
* or to any products. NXP Semiconductors reserves the right to make changes
* in the software without notification. NXP Semiconductors also makes no
* representation or warranty that such application will be suitable for the
* specified use without further testing or modification.
*
* @par
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, under NXP Semiconductors' and its
* licensor's relevant copyrights in the software, without fee, provided that it
* is used in conjunction with NXP Semiconductors microcontrollers.  This
* copyright, permission, and disclaimer notice must appear in all copies of
* this code.
*/

#include "board.h"

/*****************************************************************************
* Private types/enumerations/variables
****************************************************************************/

#define TICKRATE_HZ (10)/* 10 ticks per second */

#define GPIO_CAPTURE 15

static volatile uint32_t ticks;

/*****************************************************************************
* Public types/enumerations/variables
****************************************************************************/

/*****************************************************************************
* Private functions
****************************************************************************/

/*****************************************************************************
* Public functions
****************************************************************************/

/**
* @briefHandle interrupt from SysTick timer
* @returnNothing
*/
void SysTick_Handler(void)
{
++ticks;
/* Toggle Green LED PIO_17 */
Board_LED_Toggle(1);
}

/**
* @briefHandle interrupt from State Configurable Timer
* @returnNothing
*/
void SCT_IRQHandler(void)
{

if (LPC_SCT->EVFLAG & SCT_EVT_0)
{
/* Toggle Blue LED PIO_16 */
Board_LED_Toggle(2);
/* TODO: Read the capture registers */
/* Clear the Interrupt */
Chip_SCT_ClearEventFlag(LPC_SCT, SCT_EVT_0);

}

}

void sct_init(void)
{
/* Custom Initialization */
Chip_SCT_Init(LPC_SCT);

/* Use PIO0_15 as CTIN_0 */
Chip_SWM_MovablePinAssign(SWM_CTIN_0_I, GPIO_CAPTURE);

/* Configure the SCT as a 32bit counter using the bus clock */
Chip_SCT_Config(LPC_SCT, SCT_CONFIG_32BIT_COUNTER | SCT_CONFIG_CLKMODE_BUSCLK);

/* The match/capture REGMODE defaults to capture mode */
LPC_SCT->REGMODE_L = 1;
LPC_SCT->REGMODE_H = 1;

/* Enable an Interrupt on the Capture Event */
Chip_SCT_EnableEventInt(LPC_SCT, SCT_EVT_0);

/* event 0 is causing capture 0 */
LPC_SCT->CAPCTRL[0].U = SCT_EVT_0;


/* setup channel 0  capture event */
/* use CTIN_0, Rise, I/O condition only */
LPC_SCT->EVENT[0].CTRL = 0x00006400;
/* event happens in all states */
LPC_SCT->EVENT[0].STATE = 0xFFFFFFFF;

/* Enable the IRQ for the SCT */
NVIC_EnableIRQ(SCT_IRQn);

/* Unhalt the counter to start */
Chip_SCT_SetClrControl(LPC_SCT, SCT_CTRL_HALT_L, DISABLE);


}
/**
* @briefApplication main program
* @returnNothing (This function will not return)
*/
int main(void)
{
/* Generic Initialization */
SystemCoreClockUpdate();
Board_Init();

/* Enable SysTick Timer */
SysTick_Config(SystemCoreClock / TICKRATE_HZ);

sct_init();


while (1) {
//Board_LED_Toggle(0);
__WFI();
}

return 0;
}

Original Attachment has been moved to: sct_0.c.zip

Original Attachment has been moved to: lpcopen_2_01_lpcxpresso_nxp_lpcxpresso_812_0.zip

Labels (1)
0 Kudos
1 Reply

396 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Sun Dec 07 11:51:34 MST 2014
To change movable pin assignments the SWM clock must be enabled first.  You can disable the SWM clock after you have made your changes.

/* Enable SWM clock before altering SWM */
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);

        /* Use PIO0_15 as CTIN_0 */
       Chip_SWM_MovablePinAssign(SWM_CTIN_0_I, GPIO_CAPTURE);

/* Disable SWM clock after altering SWM */
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);


I tested your posted code not the attached file sct.c.  The code does work with these changes as long as there is a signal on PIO_15 that will provide the rising edge needed to trigger the interrupt!

This comment

/* The match/capture REGMODE defaults to capture mode */


is very misleading.  The match/capture REGMODE defaults to match mode, not capture mode.  Perhaps you should change it to:

/* The match/capture REGMODE defaults to match mode */
/* Change it to capture mode */
LPC_SCT->REGMODE = ((1 << 0) | (1 << 16));

0 Kudos