Counting on a GPIO input pin

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

Counting on a GPIO input pin

361 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by raimond on Sat Mar 12 01:40:24 MST 2011
Hi all,

Anybody knows about any issue about GPIO input pin reading on an interrupt? I have an application which need a frequency meter. The frequency is measured first sampling the input pin on a timer interrupt, detecting the edges by software, and then, the counter is reported to the second, on another timer interrupt.

The issue: I always have a few additional edges detected, for example, at 100Hz signal I have 100-106 Hz measured, not constant. Never 99 !

I suspected the gpio input not having schmitt-trigger driver, I added an external schmitt-trigger, no luck.

Frequency sampling: 10kHz. Input pin: P1.0. With P1.1 the same.

My application is a very mature one, I have done it on a Rabbit2000, Z8encore, and now I want to port it on an LPC1756. On previous micros I always got 100Hz sharp, not the LPC1756 case :(. I even have done an ATmega64 test, 100Hz sharp again.

I'm going to loose my confidence about the LPC17xx.

By the way, I use a good 12MHz crystal, and I'm working at 12Mhz without PLL. Pclk is 3MHz.

I have done many things, using the same timer for scanning/second reporting, using timer0, timer1, RIT..., disabling ints, enabling ints, using the input in all four modes...

By the way, when scanning at 400Hz, I get the 100Hz indeed, but there's no use, because I have to detect frequencies till 4kHz.

Any ideas?
0 Kudos
3 Replies

304 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by raimond on Sat Mar 12 09:40:52 MST 2011
Zero, you're great!:)

I was lucky enough to have a button input at P1.19 (CAP1.1) which I hardwired to my original P1.0 pin. Using counting mode of TIM1 with CAP1.1 as the input clock just... works.

By the way, I kept the TIMER0 as a base for frequency calculation, working as expected, but the SysTick is good too I suppose (my SysTick is very busy though).

So, the LPC1756 is back. Thanks a lot, I own you a virtual beer Zero! (or maybe NXP? :D)

Stil, no clue why software filtering is not working...


Raimond
0 Kudos

304 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Mar 12 05:21:27 MST 2011
1. Use capture input of Timer 0/1/2/3 to count (without interrupt)

2. Use SysTick Timer Interrupt (10-1000ms) to calculate frequency.

That's the way my frequency counter is working :):).
0 Kudos

304 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by raimond on Sat Mar 12 02:12:20 MST 2011
By the way, I have done some more debugging, and I think is just an GPIO issue, not timers or cpu frequency error.

I have counted the interrupts between the detected edges, and I have seen even ONE between edges at 10kHz, which is very fast on a 100Hz signal...

The scope is showing a very clean signal, which is anyway counted very well by a mega64...

So it's seems that there are 0-5 false triggers at 100Hz. 0-10 at 1000Hz. The problem is that they are just random, and the resulted precision is too low for my application (hehe I think that I'm kind of desperate to speak of precision of a digital counting :rolleyes:).

Too bad I lost my sources for my frequency generator. I had a program which generated one million pulses sharp at a given frequency. And my target it was supposed to count one million pulses sharp. And it did in the first too revisions (rabbit2000 and z8encore).
0 Kudos