Capture register updating with no signal on pin?

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

Capture register updating with no signal on pin?

474 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gastro54 on Thu Sep 20 09:58:42 MST 2012
Hi, I am having trouble getting the Timer 32-0 capture 1 function to work properly on my LPC11u24.

When I watch the CT32B0 CR1 register, I see values updating even though there is no signal connected to the PIO1_29 (CT32B0_CAP1) pin.   I've probed the pin with a scope, and it just shows a logic DC (3.3V).  I have tried disabling the timer32 interrupt and this still occurs.

EDIT:  Some more testing... The difference between successive LPC_CT32B0->CR[1] values is always 0x5DC0 = 24000 = 1/2000*PCLK, which is consistent with the 2.000 KHz interrupt frequency I was observing.  The fact that there is no jitter in the difference indicates that there is something in the code or the uC architecture that is causing this "ghost" capture event to occur, rather than real-world noise, etc.

main.c
#include "global.h"

int main(void)
{
  SysTick_Config(SystemCoreClock / 1000); // 1ms interrupt
  gpioInit();
  tPWMInit(); 
                                       
  while (1)
  {
    delay(500);
    LPC_GPIO->PIN[LED_PORT] ^= (LEDALL);
  }  
}
timer32.c
#include "timer32.h"

void tPWMInit(void)
{
  LPC_SYSCON->SYSAHBCLKCTRL |= BIT(9);         // enable clock to CT32B0 block
  LPC_IOCON->PIO1_29 |= ((0x2) |               // select CT32B0_CAP1 fn.
                         (0x2<<3));            // pull-up     
  LPC_CT32B0->CCR |= (BIT(CT32B0_CCR_CAP1RE) | // capture on rising edge
                      BIT(CT32B0_CCR_CAP1I));  // interrupt on capture
  LPC_CT32B0->MCR |= BIT(CT32B0_MCR_MR0I);     // interrupt on MR0
  LPC_CT32B0->MR0 = 0;                         // overflow detection
  LPC_CT32B0->TC = 1;                          // to avoid signaling an overflow on the first run
  // NVIC_EnableIRQ(TIMER_32_0_IRQn);             // enable the interrupt in the NVIC
    
  LPC_CT32B0->TCR |= BIT(0);                   // start counting
}
// timer32.h

#ifndef __TIMER32_H
#define __TIMER32_H

#include "global.h"

// temperature formula for SMT160-30: temperature = (dutyCycle - 32) / 0.47        

#define PWM_MAX_TIMER_VALUE F_SYSTEM_CLOCK
#define PWM_MEASURE_CYCLES 5 // number of cycles to average the pwm duty over

// bit names
#define CT32B0_IR_MR0INT 0
#define CT32B0_IR_CR1INT 5

#define CT32B0_MCR_MR0I 0
#define CT32B0_MCR_MR0R 1
#define CT32B0_MCR_MR0S 2

#define CT32B0_CCR_CAP1RE 3
#define CT32B0_CCR_CAP1FE 4
#define CT32B0_CCR_CAP1I 5

extern volatile uint32_t dutyCycle;

void tPWMInit(void);

#endif
0 Kudos
4 Replies

446 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gastro54 on Thu Sep 20 10:41:34 MST 2012
Yes, its a capture job. 

I am pretty sure I have the registers set up correctly to perform captures in my example code, but I cannot figure out why the LPC_CT32B0->CR[1] register value is changing with no input signal present.

I am trying to measure the time between consecutive captures.  I leave timer-32-0 free-running and plan to take the difference between successive reads of LPC_CT32B0->CR[1] in the timer32-0 interrupt (not shown in the example code because its irrelevant, and the problem exists with the interrupt disabled anyway).

I am using MR0 to detect timer overflows, so that I can do the correct arithmetic in case the timer overflowed between two consecutive captures.

From the usermanual:

Quote:
The 32-bit Timer Counter is incremented when the Prescale Counter reaches its terminal
count. Unless it is reset before reaching its upper limit, the TC will count up through the
value 0xFFFF FFFF and then wrap back to the value 0x0000 0000. This event does not
cause an interrupt, but a [B]Match register can be used to detect an overflow if needed[/B].

EDIT: I just made a GPIO toggle in the Timer32-0 interrupt to detect the capture frequency, and I saw a clean output of 1.000 KHz on the GPIO, meaning the capture interrupt is being generated at 2.000 KHz... not sure why.  This was with no input on the capture pin.
0 Kudos

446 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Sep 20 10:29:41 MST 2012

Quote: gastro54
Not sure I follow?  I am trying to measure a PWM signal's duty cycle.



So it's a simple capture job? Your match register usage is confusing me :eek:

How to capture a signal is shown in #4 of http://knowledgebase.nxp.com/showthread.php?t=2815
0 Kudos

446 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gastro54 on Thu Sep 20 10:19:45 MST 2012

Quote: Zero
That's no surprise if you start with a PWM sample :o

So what are you trying to do ?

Capture a signal or generate PWM :confused:


Not sure I follow?  I am trying to measure a PWM signal's duty cycle.
0 Kudos

446 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Sep 20 10:11:36 MST 2012

Quote: gastro54
Hi, I am having trouble getting the Timer 32-0 capture 1 function to work properly on my LPC11u24.



That's no surprise if you start with a PWM sample :o

So what are you trying to do ?

Capture a signal or generate PWM :confused:
0 Kudos