Simple pulse counter on emonpi2

hi,

I have an emonpi2, and a RIHXE12R power meter for my heat pump. I would like to use the pulse count output from the meter into emoncms, but cannot get it to register pulses.

I have wired the pulse output from the meter into ground and input on the analogue input, and added a 22k pullup resistor to the 3.3v output. (The docs are not clear but I assume it is an open-collector type opto isolator built into the meter). My multimeter shows pulses are going into the Pi (80ms pulses, 1/wh according to the spec).

I have added a logger and accumulator wh onto the Pulse feed in emoncms, but apart from 6 pulses recorded when I was setting up, it does not record the usage.

Is there a configuration change I need in emoncms to convert the adc to pulse mode, or am i using the wrong input? (The docs only seem to cover the emonpi and its use of the rj45 input, or reconfiguring the temperature inputs).

Thanks

Kevin

I suggest you download (if you don’t have it) the documentation for emonLibDB. This gives you information about how the pulse and analogue inputs can be set up and configured. You’ll need to read that alongside this Other sensors — OpenEnergyMonitor 0.0.1 documentation and the sketch - both the default values and anything set in the configuration menu.

As you saw pulses when setting up, look in particular at EmonLibDB_setPulseMinPeriod. I’ll look later at what Trystan has made available in the emonPi’s sketch - I don’t have an emonPi2 to play with - but do you really have an emonPi or a Heatpump Monitor? The reason I question it is the Heatpump monitor is subtly different to a ‘standard’ emonPi - and I’ve never found out what all the differences are.

You certainly should disable the analogue input, if only to avoid confusion.

One obvious question is, what are the ‘high’ and ‘low’ voltages of your pulse? (OK, I expect you might not be able to measure the ‘high’ voltage - you’d need an oscilloscope.)

Hi Robert,

Thanks for the input, …

Not sure of the relevance of the emonlibDB, that says it is explicitly for the TX4 (Arduino) (ie not emonPi2). (I have had the pulse input monitored by my own arduino sketch so I know the principle works). The OEM docs only refer to an optical pulse counter module directly monitoring the Meter LED, so any internal config / pullup / pulldown impedance are not mentioned.

I have an EmonPi2, NOT the HPM.

How and why disable the analogue input? The Pi2 Pulse channel seems to use that for pulse monitoring (an assumption as I cannot find any docs, but there is no mention of any changes to settings for use with the optical monitor. I could convert one of the temperature inputs to pulse, but that means dismantling the box and solder-linking some pads then changing config files - ok probably not rocket science, but would prefer to use the built-in pulse function.

I have got a ‘scope and monitored the pulse, which is a nice clean 3.3v high pulled down to 0v for 80ms.

regards

Here is part of the schematic diagram for the emonPi2

emonLibDB was written for the AVR128DB processor.

Because it uses the same physical input, disabling it will just remove the rather meaningless analogue measurement of your pulse from the output data.

You need to check the sketch for the pulse settings, I had to change the way the pulse is detected because the ‘old’ method was unreliable.

Here’s a clip from the emonLibDB documentation for the pulse and analogue inputs:

void EmonLibDB_setPulseMinPeriod(uint16_t _period)
void EmonLibDB_setPulseMinPeriod(uint8_t channel, uint16_t _period, [uint8_t
_edge=FALLING])
Sets the minimum period of time that the pulse must be active and in a steady state to be
recognised, in ms. This must be shorter than the duration of the pulse. (Note: this differs
from the definition in previous releases, and if the period is specified, its value should be
reviewed.) For electronic switches that do not exhibit contact bounce, zero may be used.
The channel number (one-based) defines the input to be used, and must be specified if
edge is specified. Input channels for the emonTx V4 are: 1 – ‘Pulse’, 2 – ‘Digital’, 3 –
‘Analog-Input’ – alternatively the names ‘Pulse’, Dig’ & ‘ADC’ may be used. The
appropriate solder links must be made on the p.c.b, and the ‘Analog-Input’ pulse input is
not available when the extender p.c.b. (c.t’s 7 – 12) is fitted. The edge on which the pulse
is detected may be specified if required (RISING or FALLING). Default: period = 20.

void EmonLibDB_setPulseEnable([uint8_t channel,] bool _enable)
Enables pulse counting. Pulse counting is initialised when the library is initialised, and
thereafter may be turned on or off as required. The change is applied at the next
datalogging. The pulse count is frozen whilst pulse counting is disabled. Input channels for
the emonTx V4 are: 1 – ‘Pulse’, 2 – ‘Digital’, 3 – ‘Analog-Input’ – alternatively the names
‘Pulse’, Dig’ & ‘ADC’ may be used. The appropriate solder links must be made on the
p.c.b, and the ‘Analog-Input’ pulse input is not available when the extender p.c.b. (c.t’s 7 –
12) is fitted. Defaults: ‘Pulse’ input, enable = false, edge=FALLING.

void EmonLibDB_setPulseCount([uint8_t channel,] uint32_t _pulseCount)
Initialises the pulse count. This will normally be used at start-up to restore a value saved
prior to a supply interruption or reset; although it may be used to synchronise the value
with another meter. Input channels for the emonTx V4 are: 1 – ‘Pulse’, 2 – ‘Digital’, 3 –
‘Analog-Input’ – alternatively the names ‘Pulse’, Dig’ & ‘ADC’ may be used. The
appropriate solder links must be made on the p.c.b, and the Analog input is not available
as a pulse input when the extender board (c.t’s 7 – 12) is fitted. The previous value is
overwritten. Default: 0.

void EmonLibDB_setAnalogueEnable(bool _enable)
Enables the (d.c.) analogue input. The analogue input uses the same multiplexer channel
as CT12, therefore it must not be enabled when the Expansion Board for CTs 7 – 12 is
fitted. The analogue input may only be used when when the Expansion Board is not fitted.
The voltage applied to the input connector should be within the range 0 – 1.024 V.
Damage is likely if it is allowed to go outside the range -0.3 – +3.6 V. Default: false.

Now looking at Trystan’s sketch for the emonPi2, he has got

int pulse_period = 100;

So there is your answer - your 80 ms pulse is not long enough and it’s rejected. You need to set the minimum pulse period to (probably) the library’s default of 20 ms, certainly less than your 80 ms pulse. You could even make it zero.

Quite why he has made it so long, when many electronic meters have a 100 ms pulse, is beyond me. I wrote this as clearly as I could:
“Sets the minimum period of time that the pulse must be active and in a steady state to be
recognised, in ms. This must be shorter than the duration of the pulse”
and it even says “For electronic switches that do not exhibit contact bounce, zero may be used.”

2 Likes

Thanks Robert.

Setting the pulse width to 1 (ms) has worked. :slight_smile:

I went into the admin > serial config, stopped the emonhub, selected the ttyAMA0 input and got the config screen. That had the pulse width setting at 100 as you said, hence the failure.

There is nothing on there to disable the analog input, but I have deleted the V feed on the input screen.

Thanks again

1 Like