lpcware

Trying to get capture to work

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by LynnF on Sun Mar 14 14:37:11 MST 2010
Hi,
Any help would be appreciated. I'm thinking my problem is that I can't see the forest for the trees. :)
I am trying to measure a frequency by counting the time between two rising edges on the PIO1_8 pin.
Here is my code:

Quote:

uint32_t StartByte, StopByte;
// Configure the capture pin connected to the humidity sensor
//PIO1_8, frequency counter capture
//CT16B1_CAP0 Capture input 0 for 16-bit timer 1
//LPCXpresso pin 22
LPC_IOCON->PIO1_8 &= ~0x07;
LPC_IOCON->PIO1_8 |= 0x01;
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<8);
// Load capture register (CRO) with TC on rising edge upon a capture event on pin 22
// also generate interrupt flag so we know when to start and stop the frequency count
LPC_TMR16B1->CCR = 0x05;
// Set pre-scaler value at 0
LPC_TMR16B1->PR = 0x00;
// Reset Timer Control Register to 0
LPC_TMR16B1->TCR = 0x02;
// Start Timer
LPC_TMR16B1->TCR = 0x01;

// Wait until a capture event occurs and the interrupt flag is set
while(!LPC_TMR16B1->IR & (1<<4));
// Set the StartByte = to the value in the capture register
StartByte = LPC_TMR16B1->CR0;
// Clear the interrupt flag
LPC_TMR16B1->IR &= ~(1<<4);
// Wait until the next capture event occurs and the interrupt flag is set
while(!LPC_TMR16B1->IR & (1<<4));
// Set the StopByte = to the value in the capture register
StopByte = LPC_TMR16B1->CR0;
// Turn off the timer
LPC_TMR16B1->TCR = 0;
// Turn off the capture control
LPC_TMR16B1->CCR = 0x00;



If you can see what I have wrong please advise, thanks!
I know the principal works because I already have this type function working on a MicroChip MCtrl and am porting the code to the LPC1343.

Outcomes