Mechanical Relay will only catch a single edge on InterruptEdgeBoth

Hi Everyone,

I need a little help and a sanity check on the use of a mechanical relay with an interrupt port set to InterruptEdgeBoth.

_port = new InterruptPort(cpuPin, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);

Every time the relay is triggered, only a single edge will be reported from 3.3V to 0V and no report of 0V back to 3.3V. The relay is a single pole double throw and will trigger a pulse of 150ms with a rise and fall time of approximately 2.5ms. The signal is very clean when using an oscilloscope. I am monitoring uint data2 on the event handler to check to see if it changes from 0 to a 1 and vice versa. With the resistor mode in PullUp, data2 should start out in a state of 1 (3.3V) on the initial edge and then data2 should switch to 0 on the rising edge. I should be able to tell which edge is rising and falling, but currently, data2 will only ever read as a state of 1 and the interrupt will only ever trigger once.

I have used a wire to simulate a relay and tap Ground to emulate a pulse and this works great, so the code appears to be handling it as designed.

Is it possible this relay is too slow for the board?

Any thoughts or help would be greatly appreciated!


Hi aciciura and welcome to the forum

Can you describe how you have the relay wired, and what voltages you have connected where ?

@ aciciura -
If it is a mechanical relay the response times vary all over the place and they are noisy.

Suggest a solid state relay if you are using a mechanical one.

Hi Brett,

I am using a breakout board and pulling 3.3V into the normally open pin of the relay while wiring the ground of the breakout into the common of the relay. The relay is powered externally by a 12V DC power supply where this ground is tied into the FEZ Spider’s ground as well. The same power supply power the relay and the board. When the relay triggers, it should allow the 3.3V to ground. I originally thought the wiring of the ground was the issue, but I have tried multiple wiring configurations with the ground and have not had a different result yet. The model number of the relay is 842A-1C-S-12VDC.

@ WillGeorge

I completely agree on using the solid state relays. I am already looking into moving to an optical relay to clean up the pulse even further and quicken up the response times. I had debounce code in place to handle the 5 or 6 consistent bounces of the mechanical relay which worked very well when I was testing off an InterruptEdgeLow. I tested with and without the debounce code with the same result. I just want to make sure the length of the pulse was not the issue to where 150ms was too slow for it to pick it up.

Thanks for the quick responses!


A small wire about 3 inches long will trigger the interrupt between the pin held high on the break out board and the wire contacting ground AND it will trigger a rising edge and falling edge (data2=1 and data2 =0). Now, I put a single pole light switch between the same pin on the breakout board and the ground and it will only trigger the rising edge still (It will actually only trigger the rising edge once).

Does the length and/or impedance of the wire limiting the small current going through the relay stopping the pin from reading the falling edge?

a light switch is probably a very noisy switch. I don’t think it’s reflective.

impedance can have an impact, but I don’t know if there’s any way to predict how. You might look at the processor datasheet.

So let me take a step back. You have a 12v source, which is externally switched. You’re using that source to energise a relay, and you’re using the normally open contacts on the relay to signal to the micro that the external source is on. Is that accurate? Any other external components, diodes for example ?

A couple of things spring to mind. Have you tried using pulldown resistor setting rather than pullup ? Perhaps the processor behaves different in those scenarios. Have you tried using an external pullup/pulldown ?

@ Brett

Yup you nailed the configuration. I have tried an external Pull Up resistor up to 5V to no avail as well. Every test has the same outcome with no following edge being read.

I will have to take a look at the Pull Down to see if that could possibly make a difference. I will let you know. I did do a test with a longer wire (6") and that would intermittently miss the following rising edge, so it does appear that the impedance is playing a big role on reading the following edge.


@ aciciura - Did you ever get InterruptEdgeBoth to work?

@ aciciura - I am interested as well :wink: