Computing stuff tied to the physical world

Detecting pulses

In Software on Oct 21, 2012 at 00:01

With yesterday’s solar setup operational, it’s now time to start collecting the data.

The pulse counter provides a phototransistor output which is specified as requiring 5..27V and drawing a current up to 27 mA, so my hunch is that it’s a phototransistor in series with an internal 1 kΩ resistor. To interface to the 3.3V I/O pins of a JeeNode, I used this circuit:

Pulse power

That way, if the circuit has that internal 1 kΩ resistor, the pin will go from 0 to 2.5V and act as a logic “1”. In case there is no internal resistor, the swing will be from 0 to 5V, but with the 10 kΩ resistor in series, this will still not harm the ATmega’s I/O pin (excess current will leak away through the internal ESD protection diode).

No need to measure anything, the above will work either way!

I considered building this project into a nice exclosure, but in the end I don’t really care – as long as it works reliably. As only 3 input pins are used, there’s a spare to also drive an extra LED. So here’s the result, built on a JeePlug board – using a 6-pin RJ12 socket:

DSC 4204

The RJ12 socket pins are not on a 0.1″ grid, but they can be pushed in by slanting the socket slightly. The setup has been repeated three times, as you can see:

DSC 4205

To avoid having to chase up and down the stairs while debugging too many things at once, I started off with this little sketch to test the basic pulse counter connections:

Screen Shot 2012 10 20 at 22 08 26

All the code does, is detect when a pulse starts and blink a LED one, two, or three times, depending on which pulse was detected. Note how the two MilliTimer objects make it easier to perform several periodic tasks independently in a single loop.

Tomorrow: logic to track pulse rates and counts, and sending results off into the air.

PS. Off-by-one bug – will be fixed tomorrow.

  1. Would this be the ideal situation for interrupt-based counting? Or do you need to debounce the Phototransistor?

  2. Could be done with interrupts, yes, but there’s probably no overwhelming reason to do so. Here I’m just polling once every millisecond, since that’s the resolution being reported. It’s a busy loop, but at under 10 mA consumption for an ATmega328 when running flat out, and with a USB adapter to power the whole thing, it’s good enough for me right now.

    Debouncing is already implemented, in essence: I only trigger on 7x “0” followed by 1x “1”, due to the way the I/O pins are scanned once every millisecond.

    Note that it might indeed be possible to read this thing out on battery power: we could pulse the 5V to the pulse counters’s phototransistor briefly once every 1 ms, then read it out, then turn off power again. Probably even on an AA Power Board @ 3.3V, even though the specs say that the phototransistors need 5V.

Comments are closed.