Capture Error

Questions on other types of hardware and getting it talking to the ARM CPU
Post Reply
danlee58
Posts: 210
Joined: Thu Jan 17, 2013 2:29 am

Capture Error

Post by danlee58 » Thu Feb 13, 2014 9:35 pm

I am trying to measure the Period of a pulse train with a SuperPro using Timer1 to count PCLK between Interrupts on Pin18. If I have 200 pps on pin 18, I expect to read 125000 with PCLK = 25Mhz. I seem to get 1/100 of that or 1250 PCLK Transitions in the 5msec time between transitions. I have the PR set to 0.



danlee58
Posts: 210
Joined: Thu Jan 17, 2013 2:29 am

Re: Capture Error

Post by danlee58 » Fri Feb 14, 2014 1:04 am

I think that the problem might be due to this code.

printf("%d\n"), Timer Count;

The Timer Count is a 32 bit value, and might overflow a 16 bit function(65535).

basicchip
Posts: 835
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: Capture Error

Post by basicchip » Fri Feb 14, 2014 8:22 am

I think you are talking about C, and that should have produced a compile error, in which case new code was never loaded.

If it's BASIC, you should also get an error.

printf("%d\n",TIMER); //TIMER is a #define in C, not sure what your reference to Counter is and would error on the space between them

In C the a variable defined as short is limited to 65K, but type int is 32 bits

danlee58
Posts: 210
Joined: Thu Jan 17, 2013 2:29 am

Re: Capture Error

Post by danlee58 » Sun Feb 16, 2014 7:16 pm

Yes, it is C.


The actual code is:

printf("%d\n"), Timer_Count;

Timer_Count is a long unsigned int.

I get no Compiler Errors or Warnings.

basicchip
Posts: 835
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: Capture Error

Post by basicchip » Mon Feb 17, 2014 10:16 am

This is cut nd paste from some code I used to measure a 1KHz incoming clock based on the IRC and capture0 of the timer. This was done on an 1800 series part, so the pin setup won't exactly be the same

Code: Select all

void setupTIMER0 (void) {
	 
		LPC_CGU->BASE_M3_CLK = (1<<11) + (1<<24);		// IRC
	
		LPC_CCU1->CLK_M3_TIMER0_CFG = 1;
		LPC_CCU1->CLK_M3_BUS_CFG = 1;
		LPC_CCU1->CLK_M3_SCU_CFG =1;
	
		LPC_SCU->SFSP0_8 = (1<<6) + 2;					// TIMER0 CAP0 input
	
		LPC_GIMA->CAP0_0_IN = (2<<4);
		
		LPC_TIMER0->TCR = 1;				// enable TIMER0
		LPC_TIMER0->PR = 0;					// no prescale, count on every PCLK
		LPC_TIMER0->PC = 0;					// no prescale, count on every PCLK

		LPC_TIMER0->CCR = 5;				// on CAP0 rise capture TC and set interrupt
		LPC_TIMER0->CTCR = 0;				// timer mode
	
		LPC_TIMER0->IR = 0xff;			// clear all interrupts
}

void main(void) {

	setupTIMER0();

	while(1)

		if (LPC_TIMER0->IR & (1<<4)) {		// capture event
			KHZsamples[KHZindex++] = 	LPC_TIMER0->CR[0];
			
			LPC_TIMER0->IR = 0xff;			// clear all interrupts
			KHZindex &= MAXsample;			// wrap on MAXsample samples
		}
	}
}

basicchip
Posts: 835
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: Capture Error

Post by basicchip » Mon Feb 17, 2014 10:22 am

some code comments--

For 32 bit unsigned register values, I use unsigned int, I'd have to lookup what you get when you make it long, and I try to keep my code simple

printf("%d\n",x); // is what you want to use

while

printf("%d\n"),X; //may be almost legal, it won't do what you want

because, you want to pass the value of x to printf, which is done within the ()

expression,expression; //is legal in C, with both printf and x being expression, but it is unlikely what you want to do. I don't think I've ever used , between expression except in function calls. Remember I KISSS, 3rd S for software

The only expression; I normally use is

i++:

danlee58
Posts: 210
Joined: Thu Jan 17, 2013 2:29 am

Re: Capture Error

Post by danlee58 » Wed Feb 19, 2014 9:21 pm

I did a data log of the output from the printf("%d\n",x); statement. The printf function is working correctly. However the data shows ~1000 counts per interrupt. It should be 125000 to 150000 counts between interrupts. The interesting part of the data is that once-in-a-while, I get a sample that is in the right ballpark. I thought that this data was an error, since most data shows lower counts, but it is in fact the lower count data that's wrong.

I need to go over my input circuit to find out where the extra pulses are being generated.

Post Reply