LPC11 timer capture

cancel
Showing results for 
Search instead for 
Did you mean: 

LPC11 timer capture

377 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nickich on Mon Jul 13 05:52:55 MST 2015
Hello,

I'm trying to get the capture configured in order to measure the time between the edges.
So far I have configured the following way:
Chip_IOCON_PinMux(LPC_IOCON, IOCON_PIO1_5, IOCON_MODE_INACT, IOCON_FUNC2);
Chip_TIMER_Init(LPC_TIMER32_0);
Chip_TIMER_TIMER_SetCountClockSrc(LPC_TIMER32_0, TIMER_CAPSRC_RISING_PCLK, 0);
Chip_TIMER_PrescaleSet(LPC_TIMER32_0, 1);//1=> every 2 PCLK clocks
Chip_TIMER_CaptureRisingEdgeEnable(LPC_TIMER32_0, 0);
Chip_TIMER_CaptureFallingEdgeEnable(LPC_TIMER32_0, 0);
Chip_TIMER_CaptureEnableInt(LPC_TIMER32_0, 0);
/* preemption = 1, sub-priority = 1 */
NVIC_SetPriority(TIMER_32_0_IRQn, 1);
NVIC_EnableIRQ(TIMER_32_0_IRQn);


but no interrupt (on TIMER32_0_IRQHandler()) is received.

Am I doing anything obviously wrong or am I missing something?
Labels (1)
0 Kudos
18 Replies

192 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue Jul 14 23:44:54 MST 2015

Quote: nickich
Just for the sake... The same code modified for TIMER16_0 works fine. TIMER32_0 doesn't.
Is there any difference in configuration between them that I'm missing?



No, that's the same mechanism, but there are a few pifalls 

- Some CAP inputs can be switched   
 
  In your case: IOCON_CT32B0_CAP0_LOC can select PIO2_9 as CT32B0_CAP0.

- If the pin has an AD function, it's necessary to select 'Digital functional mode' 

 
Chip_IOCON_PinMux(LPC_IOCON, IOCON_PIO1_0, IOCON_MODE_PULLUP |[color=#f00] IOCON_DIGMODE_EN[/color], IOCON_FUNC3);


0 Kudos

192 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nickich on Tue Jul 14 13:00:49 MST 2015
Good suggestion! Thanks!
0 Kudos

192 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue Jul 14 11:59:06 MST 2015

Quote: nickich
Is this the same project I've posted?



Yes, I just added

Board_LED_Toggle(0);


to scope the interrupt.

Of course you can also try to use Timer32B1   
0 Kudos

192 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nickich on Tue Jul 14 11:53:23 MST 2015
Is this the same project I've posted?
Yeah, I'm thinking it could be a HW issue as well, although I'm using brand new LPCXpresso (LPC11C24 Rev B) board.

I'll try to find another board.

Thanks for the help!
0 Kudos

192 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue Jul 14 11:47:37 MST 2015
Toggling PIO1_5 with 2V / 100Hz is generating interrupts here:

[img=1250x801]https://www.lpcware.com/system/files/Capture_1.JPG[/img]

Which hardware are you using? Is it a LPCXpresso11C24 board?

Could be useful to change the board, perhaps PIO1_5 is damaged  :((
0 Kudos

192 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nickich on Tue Jul 14 11:37:36 MST 2015
Just for the sake... The same code modified for TIMER16_0 works fine. TIMER32_0 doesn't.
Is there any difference in configuration between them that I'm missing?
0 Kudos

192 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nickich on Tue Jul 14 11:10:25 MST 2015
I'm toggling it with square wave signal.
I also tried pull-up - still nothing.
0 Kudos

192 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue Jul 14 11:03:18 MST 2015

Quote: nickich
The interrupt event doesn't happen at all.



Then check PIO1_5. You switched it to pull-up / pull-down inactive, so what are you doing to trigger an interrupt?
0 Kudos

192 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nickich on Tue Jul 14 10:43:11 MST 2015
The interrupt event doesn't happen at all.
I put the code to clear the interrupt (in case it happens).
IR register doesn't show pending interrupts.

Thanks. I'll have another look at the link.
0 Kudos

192 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue Jul 14 10:16:40 MST 2015
What's not helpful?

I've posted a link to a working example, I've explained you that your handler isn't clearing the capture interrupt (as shown in sample)?

0 Kudos

192 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nickich on Tue Jul 14 10:00:31 MST 2015

Quote: R2D2

Quote: nickich
...but I'm learning fast, I hope ;)



...then debug your interrupt handler and watch IR register...


well, that's not much helpful...
0 Kudos

192 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue Jul 14 09:48:51 MST 2015

Quote: nickich
...but I'm learning fast, I hope ;)



...then debug your interrupt handler and watch IR register...
0 Kudos

192 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nickich on Tue Jul 14 09:37:56 MST 2015
Yeah... Sorry...
but I'm learning fast, I hope ;)
The test project I'm using is attached.

0 Kudos

192 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Mon Jul 13 15:40:22 MST 2015

Quote: nickich
Here is the whole code...



:quest:

And again, code snippets...

Anyway, there's still much time to pass until christmas  :D

So I don't know what's your problem in detail, but your interrupt handler in nonsense. You don't clear the capture interrupt, as explained in several capture samples (https://www.lpcware.com/content/forum/lpc1114-my-isr-using-timer16-on-lpcxpresso).

If an interrrupt is triggered, your code is never leaving the handler...
0 Kudos

192 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nickich on Mon Jul 13 08:12:29 MST 2015
Ah, I got it. Thanks.
Here is the whole init and IRQ code.


Quote: R2D2

Quote: nickich
Am I doing anything obviously wrong...



Yes, you are posting code snippets  |(

So I've no clue if you start your timer somewhere or if you have an ISR at all...



Thanks R2D2. Sorry for the snipped. That was actually the whole init routine at the time...

Here is the whole code, which I expect to fire interrupt on edge change, where I can read the time between edges. Unfortunately no interrupt happens...

#define CAPDATA_SIZE256
static uint32_t capdata[CAPDATA_SIZE];
static int capdataidx = 0;
void TIMER32_0_IRQHandler(void)
{
__disable_irq();
if(capdataidx < CAPDATA_SIZE)
{
capdata[capdataidx++] = Chip_TIMER_ReadCount(LPC_TIMER32_0);
}
__enable_irq();
}

void cap_init(void)
{
capdataidx = 0;
Chip_IOCON_PinMux(LPC_IOCON, IOCON_PIO1_5, IOCON_MODE_INACT, IOCON_FUNC2);
Chip_TIMER_Init(LPC_TIMER32_0);

Chip_TIMER_Disable(LPC_TIMER32_0);
Chip_TIMER_TIMER_SetCountClockSrc(LPC_TIMER32_0, TIMER_CAPSRC_RISING_PCLK, 0);
Chip_TIMER_PrescaleSet(LPC_TIMER32_0, 1);//1=> every 2 PCLK clocks
Chip_TIMER_CaptureRisingEdgeEnable(LPC_TIMER32_0, 0);
Chip_TIMER_CaptureFallingEdgeEnable(LPC_TIMER32_0, 0);
Chip_TIMER_CaptureEnableInt(LPC_TIMER32_0, 0);
/* preemption = 1, sub-priority = 1 */
NVIC_SetPriority(TIMER_32_0_IRQn, 1);
NVIC_EnableIRQ(TIMER_32_0_IRQn);
Chip_TIMER_Reset(LPC_TIMER32_0);
Chip_TIMER_Enable(LPC_TIMER32_0);

}


and the main is mostly:
SystemCoreClockUpdate();
Board_Init();
Board_LED_Set(0, false);

cap_init();

UART_Init();
        CAN_Init();
UART_Start();

while (1)
{
}

/* DeInitialize UART0 peripheral */
NVIC_DisableIRQ(UART0_IRQn);
Chip_UART_DeInit(LPC_USART);

return 1;
}


The UART init code:
void UART_Init(void)
{
Init_UART_PinMux();
/* Setup UART for 115.2K8N1 */
Chip_UART_Init(LPC_USART);
Chip_UART_SetBaud(LPC_USART, 1500000);
Chip_UART_ConfigData(LPC_USART, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT));
Chip_UART_SetupFIFOS(LPC_USART, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2));
Chip_UART_TXEnable(LPC_USART);
/* Before using the ring buffers, initialize them using the ring
   buffer init function */
RingBuffer_Init(&rxring, rxbuff, 1, UART_RRB_SIZE);
RingBuffer_Init(&txring, txbuff, 1, UART_SRB_SIZE);
}

void UART_Start(void)
{
/* Enable receive data and line status interrupt */
Chip_UART_IntEnable(LPC_USART, (UART_IER_RBRINT | UART_IER_RLSINT));

/* preemption = 1, sub-priority = 1 */
NVIC_SetPriority(UART0_IRQn, 1);
NVIC_EnableIRQ(UART0_IRQn);
}


...that's most of the initialization...
0 Kudos

192 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Mon Jul 13 08:04:40 MST 2015

Quote: nickich
BTW. What's wrong with the code snippets being posted?



It's not debuggable  :((

If you post your main file or better your project, it's easy to load / flash / debug  ;-)

So it's a time-consuming guessing game and instead of getting a fast precise answer you might get no answer at all...
0 Kudos

191 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nickich on Mon Jul 13 07:41:05 MST 2015

Quote: R2D2

Quote: nickich
Am I doing anything obviously wrong...



Yes, you are posting code snippets  |(

So I've no clue if you start your timer somewhere or if you have an ISR at all...



Thanks R2D2. I might well forgotten to start the timers... I'll double check.
BTW. What's wrong with the code snippets being posted?
0 Kudos

191 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Mon Jul 13 06:58:43 MST 2015

Quote: nickich
Am I doing anything obviously wrong...



Yes, you are posting code snippets  |(

So I've no clue if you start your timer somewhere or if you have an ISR at all...
0 Kudos