Pulse counting and interrupts: Work perfectly or Not at all

I am not sure if this is hardware or software: I am almost totally stumped.

My software is attached

My program reads pulses from the ADE7769 energy metering IC. They are positive-going pulses
35us wide and I change them to negative-going with an NPN transistor, Output connected to Pin 1.

I have used the meter quite a bit, running it overnight one time and I have also connected it to my treadmill to record power during a workout. I have checked various loads (mesaured with ADE7769) to push the pulse rate up to make sure the imp could perform when the pulses come in at a high rate - and it has always performed in that regard.

in other words, nominally it has been shown to work.

My problem is that sometimes when the device boots up I get 0 pulses (I use interrupts). I also have tried using code that employs the pulse counter function and I have the same result.

What I cannot figure out is why the device is appearing to ‘decide’ at boot whether it will perform or not and I have never seen it randomly stop or begin working while in operation.

I have tried:

  • changed from wall-wart supply to lab supply
  • changed to 9V battery power to eliminate any source of noise
  • changed to testing an incandescent light bulb for power draw rather than anything with switching power supplies.
  • changed out the energy meter IC, checked solder joints - even ran the board through reflow after which I breifly believed the problem to be solved.

I read the signal on a scope to verify the pulse is there - at least on the outside of the SD card holder.

My next actions will be to change my circuit to low-side sensing rather than high-side sensing (just by changing the phase wire for neutral) and this will allow me to more easily scope the signal and check for noise but…

It is just puzzling to me; if I had a noise issue I would expect poor performance from the meter, not 100% or 0% performance.


Hmm. When it works, if you then power cycle without moving the card, does it work on the next boot? The suspicion is that there’s a socket contact problem and it’s random whether it connects ok.

Other people on the forum have had sporadic socket problems, but this is pretty rare.

Thanks Hugo, I think that is it. When working or not working the device had been stable in being stuck that way. I only got changes when I messed with the hardware and then I ended up making a bunch of false conclusions…

Being a mech. engineer I am conditioned to look for problems in hardware and software ; ) but this is a mechanical problem.

I put a piece of Kapton tape across the end of the card, believing I needed to thicken it. This got me some sporadic counts but as I wiggled the card I found it seemed inconsistent.

{I have wired my circuit to be low-sensing so I can finally touch it without getting a shock; it is what prevented me discovering the issue}

Next, I pushed the card IN as if to remove it and my results cleaned up. However, this is an Amphenol push-push socket so as soon as I let go it popped out.

What is the workaround? In which dimension do I need to trim? Thicker? how much? Do I need to trim from the front edge of the card? or something else? The socket does not appear mis-placed or damaged but I suppose I could try installing a fresh one…

Glad I may be able to stop attempting to widen the pulse. I thought maybe the 35us pulse was too ‘fast’ so I was playing with diodes in my transistor circuit to widen it.

Glad I may be able to stop attempting to widen the pulse. I thought maybe the 35us pulse was too 'fast' so I was playing with diodes in my transistor circuit to widen it.

My simple experiments show that the imp can comfortably count pulses 20ns wide, so 35us shouldn’t be an issue. I posted some results in the hardware section.

Cool!, thanks sjm,

My actual code does not use the PULSE_COUNTER, I just put that in for troubleshooting. My code uses the interrupts and I have found those to work well in my application.

I just need to figure out how to make the card get a reliable connection to the socket.