Topic: GPIO pulse/tick counter

I would like to connect a flowmeter (http://www.swissflow.com/en/SF800/Flow_ … ifications) to my Infocast 3.5. Previously I have connected this meter to an interrupt line of an AVR to count pulses.

Frequency is fairly low at 100Hz to 2Khz

1) Is there a way to attach an interrupt to a GPIO pin to reliably catch rising or falling edges?
2) Is the 3.5 fast enough that I could just poll the GPIO for a pulse count at ~1Khz?
3) Is a GPIO even suitable for this purpose, or would I need some additional counter/accumulator IC in between the chumby and the flowmeter? If so, does anyone have any suggestions, perhaps one which supports i2c.

Re: GPIO pulse/tick counter

nebulous wrote:

1) Is there a way to attach an interrupt to a GPIO pin to reliably catch rising or falling edges?

Probably? Though I've never used hardware interrupts on anything except a microcontroller.

nebulous wrote:

2) Is the 3.5 fast enough that I could just poll the GPIO for a pulse count at ~1Khz?

I should think so. 2KHz is pretty slow compared to the 3.5's 454MHz. Check out Madox's Python GPIO library: http://www.madox.net/blog/2011/01/12/ch … n-library/

nebulous wrote:

3) Is a GPIO even suitable for this purpose, or would I need some additional counter/accumulator IC in between the chumby and the flowmeter? If so, does anyone have any suggestions, perhaps one which supports i2c.

If you're going to use an external IC, I'd probably just use an ATtiny. It should be pretty low-power in this application.

Re: GPIO pulse/tick counter

skcolb wrote:

2KHz is pretty slow compared to the 3.5's 454MHz. Check out Madox's Python GPIO library: http://www.madox.net/blog/2011/01/12/ch … n-library/

I'm going to try this route first for sure. Will probably end up using perl or C just because I'm crotchety about Python, but maybe this will be the catalyst to change smile

skcolb wrote:

If you're going to use an external IC, I'd probably just use an ATtiny. It should be pretty low-power in this application.

Yeah, it just seemed so silly to add a uC to such a beefy system. If there were an i2c accumulator that I could just throw on the existing bus, somehow that feels better. Irrational, I know, and hopefully completely unnecessary if I can just poll the pin.

Re: GPIO pulse/tick counter

Looked at Madox's Python script as well as the source for regutil, and was able to cook up something (using much of regutil as a basis) which worked just fine. I'll post the source if anyone is interested.

Polling the pin was fast enough, but highly inefficient. If I can get away with putting a usleep() in the loop or using a timer perhaps that will be enough. I saw in the documentation that the GPIO pins can be used as interrupt triggers, but I have no idea how I might go about writing code for that. Any pointers in that regard would be appreciated.

Re: GPIO pulse/tick counter

The python sleep function takes fractional seconds so you might be able to do everything in Python.

Re: GPIO pulse/tick counter

I was already able to do everything in C, which is my preference over Python. The main thing I'd like additional advice on now is how I might tie into an interrupt on a GPIO rather than polling the line, so if anyone has any pointers on that I'd appreciate it. Polling works, but feels icky.

Re: GPIO pulse/tick counter

So currently, your code polls a GPIO only?

Does the infocast have spare GPIO lines easily accessible?  I've done some brief looks at the CC and C1 and haven't found easily accessed GPIO.  It seems my best bet is going to be removing an existing peripheral.  I'd like to get at GPIO (or i2c) without having to permanently change my hardware.

Linux Guy - Occasional Chumby Hacker

Re: GPIO pulse/tick counter

Materdaddy wrote:

Does the infocast have spare GPIO lines easily accessible?  I've done some brief looks at the CC and C1 and haven't found easily accessed GPIO.  It seems my best bet is going to be removing an existing peripheral.  I'd like to get at GPIO (or i2c) without having to permanently change my hardware.

The Infocast indeed does have easily accessible GPIO and I2C. Check out the pictures at the developer's blog:
http://www.bunniestudios.com/blog/?p=1435

Re: GPIO pulse/tick counter

Have you downloaded and read the iMX233 manual?  You'll find everything you need in there.

Re: GPIO pulse/tick counter

Materdaddy wrote:

So currently, your code polls a GPIO only?

Yes, and as skcolb pointed out above, polling is easily fast enough. I put the polling code on a timer that catches all of the transitions at the flow rates I need and it only takes a few %cpu time according to htop. I would still love to use the standard Linux gpio module(if nothing else, so that I could use w1-gpio), but it doesn't come compiled on the device and I've yet to get a reliable cross compiling rig working.(It seems there are 5 ways to do it, but none of the instructions for them work without -to the newb at least- SuperSecretKnowlege.)

Materdaddy wrote:

Does the infocast have spare GPIO lines easily accessible?  I've done some brief looks at the CC and C1 and haven't found easily accessed GPIO.  It seems my best bet is going to be removing an existing peripheral.  I'd like to get at GPIO (or i2c) without having to permanently change my hardware.

If you consider soldering something to the board too much, then no, gpio isn't accessible. But, provided you're willing to do so, bunnie has made it quite easy to access a byte of GPIO, I2C, an additional USB port, 3.3v serial, and JTAG.

Re: GPIO pulse/tick counter

Actually, it looks like you can get pin headers which don't require solder. IMO it's not worth 10% of the cost of the Infocast to get them, but these guys sell them for some Xbox or cablemodem modifications.

http://www.modzstore.com/10+Pin+Solderl … 83075.aspx

Does anyone know what they're called to order from Mouser or Digikey or something? Could be useful for some things. I know it would have saved me a lot of frustration when I soldered the header in upsidedown on my 3.5. Ugh.

Re: GPIO pulse/tick counter

nebulous wrote:

Actually, it looks like you can get pin headers which don't require solder. IMO it's not worth 10% of the cost of the Infocast to get them, but these guys sell them for some Xbox or cablemodem modifications.

http://www.modzstore.com/10+Pin+Solderl … 83075.aspx

Does anyone know what they're called to order from Mouser or Digikey or something? Could be useful for some things. I know it would have saved me a lot of frustration when I soldered the header in upsidedown on my 3.5. Ugh.

http://www.mouser.com/ProductDetail/Har … fh4io90%3d ???

Linux Guy - Occasional Chumby Hacker

Re: GPIO pulse/tick counter

Materdaddy, the header you linked appears to be a solder-in type. Unusual in that it's double-ended, but doesn't look like it can be snapped in and out of 0.1" spaced mounting holes. The zoomed in image might help http://images.shoppit.co.uk/sizeimage.aspx?client=11159&image=solderless.jpg&height=500&width=500&colour=ffffff

Re: GPIO pulse/tick counter

Better yet, not the header and pins, just the solder-in pins, and right-angle: http://www.mouser.com/ProductDetail/Har … 37qMVdE%3d

Linux Guy - Occasional Chumby Hacker

Re: GPIO pulse/tick counter

Sorry, I thought you were asking specifically for solder in ones, since the ones you linked are about 10% the cost of the device itself, the latest one I linked is $0.24.

I've been placing mouser orders recently, when my infocast gets here, I'll see which configuration I want (right angle, or straight) and add one of the ~$0.25 ones to my next order.

Linux Guy - Occasional Chumby Hacker

Re: GPIO pulse/tick counter

I found that soldering hookup wire directly to the expansion port was the only way for things to fit nicely. Straight headers facing down interfere with the LCD cable, facing up won't fit under the speaker resonator, and right angle smooshes up against the back of the LCD. With a bit of "forceful encouragement" however, I think any of those configurations could be made to work.