2

This is a child of my first problem, I am getting ghosting/bouncing on my digital input, but this question is more hardware related and specific to my problem. I have a RasPi model B.

I have read somewhere that when using interrupts, it is not possible doing a stable software debouncing and I have experienced it myself. I have setup a callback with bouncetime=350 but event though I have seen in my logfile that I was able to receive two inputs within 5ms. I also experience that I receive "ghost inputs" - for example I have an electrical meter connected to my RasPi but I have not connected the meter to a power souce... so it should NEVER be able to give out a pulse but even though it does (a few ghost pulses per day)!? This is a clear indication that there are interference on my wires and maybe the wires are influencing eachother so this is why I am searching for a proper hardware debouncing setup.

I have four electrical meters from Kamstrup. This is the pulse adaptor documentation mentioning that one pulse is 30ms +/-10% and I get one pulse per Watt used (1000 pulses/kWh). I have all four - (minus) wires connected to GND and their + wires to GPIO 0-3 (pin 11+12+13+15) and currently no other components used. I will probably never go beyond 10kWh power usage in my house so I can get 2.8 pulses per second which is aprox a 350ms bouncetime, which I am also using in my software (including using the built-in pull-up resistor):

GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# Create interrupt handler
GPIO.add_event_detect(11,GPIO.RISING, callback=eventHandler, bouncetime=350)
GPIO.add_event_detect(12,GPIO.RISING, callback=eventHandler, bouncetime=350)
GPIO.add_event_detect(13,GPIO.RISING, callback=eventHandler, bouncetime=350)
GPIO.add_event_detect(15,GPIO.RISING, callback=eventHandler, bouncetime=350)

My question is:

What exactly do I need to connect where, to setup a proper hardware debouncer for my digital electrical meter input?

I expect that I should connect a capacitor (100nF?) and maybe use a real resistor (10K ohm?) instead of the built-in but as I am not a hardware guy I have no clue which capacities to use and how exactly to connect it?

Can anyone help clarifying this? I have read countless webpages on hardware debouncing but still I am very much in doubt.

If anyone can suggest a ready-to-buy add-on to my RasPi model B, that can take care of this exact problem, I would be very interested too as I want to have the most trust-worthy setup as possible. A few ghost pulses per day is okay but currently I have no idea how faulty it is.

6
  • Please provide a schematic of your input stage to add clarity to what you are asking. Dec 10, 2014 at 22:20
  • Stop wasting your time. If you are using the internal pullups you are asking for trouble. Use 1kΩ pullups near the Pi. They cost less than 5c each.
    – Milliways
    Dec 10, 2014 at 22:47
  • @Chetan - what do you mean? I have pulse wires connected directly to GPIO and GND and I want to have a hardeware debounce solution instead of using the internal stuff
    – Beauvais
    Dec 11, 2014 at 9:17
  • @Milliways - I have seen various capacities being used - from 1kΩ to 10kΩ... how do know what is correct for my setup? And where should this resistor be mounted?
    – Beauvais
    Dec 11, 2014 at 9:18
  • There is no "correct" value. 1kΩ will result in a current of ~3mA which is within the Pi's capabilities (8mA per pin 50mA total) and a sufficiently low value to swamp interference.
    – Milliways
    Dec 11, 2014 at 11:01

2 Answers 2

1

The docs for the pulse adapter mentions that the "pulse output is galvanically separated" from the electricity meter.

Usually this means that you need to add a pull-up resistor on you input circuit to provide some input voltage for the GPIO. Connect the resistor between the GPIO and the positive supply of the processor. A good value for the pull-up is 1k ... 1k Ohm.

You may also want to reduce noise by

  • using a shielded, twisted pair line between the RPi and the meter
  • adding a simple low pass filter (e.g. 100 Ohm / 10nF).

For the optional low pass filter, connect the resistor between the input signal and the GPIO and the capacitor from the GPIO to ground.

As a result, you have three components connected to your GPIO: The pull-up resistor (1k Ohm to 3V3), the filter cap (10nF to ground) and the input resistor (100 Ohm) connected to the input signal.

I found a nice article detailing the protection of digital MCU inputs at digikey. Fig. 8 shows what I mean. Your input is connected to the input of the low pass filter (+) and ground.

5
  • Can you please elaborate on the low pass filter? How should this be connected and does it include one more resistor? A drawing would be nice ;-) Thanks
    – Beauvais
    Dec 15, 2014 at 8:27
  • @DHS Sorry, don't know how to add a sketch. Tried to better describe the circuit.
    – Ber
    Dec 15, 2014 at 19:51
  • Should the resistors and capacitor be connected in parallel or in serial? And should the low pass filter be connected to + or - of the input?
    – Beauvais
    Dec 16, 2014 at 8:45
  • @DHS added a link to a DigiKey tech article that explains this in more detail than I could.
    – Ber
    Dec 16, 2014 at 19:30
  • I have accepted your answer - not because I have verified it (I have no clue if it works or not) but because it is the best solution I have seen yet (with ref. to a good article) and I understand how to do it. I don't know if I will try it out but this is what I will use if I go ahead with it. Thanks
    – Beauvais
    Dec 16, 2014 at 19:56
0

Your application doesn't need denouncing as there are no mechanical contacts involved. The pulse adapter board has no mechanical contacts, relays, etc.

Debouncing is only needed if you connect mechanical contacts to digital inputs.

From Whatis.com - "Bouncing is the tendency of any two metal contacts in an electronic device to generate multiple signals as the contacts close or open; debouncing is any kind of hardware device or software that ensures that only a single signal will be acted upon for a single opening or closing of a contact."

Here is a excellent guide on debouncing.

On the other hand, your application may need signal conditioning. The pulses from the adapter bard may be of different amplitude that the PI can handle. Or the pulses may need filtering, etc. You can read more about signal conditioning here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.