Strange Interrupt problem - Page 1
Forum section: electronics / beginners

author: Precious Roy
author_rank: Contributor
timestamp: November 17, 2016, 10:18:32 am
content: Hello everyone,I have been having these strange interrupt problems that i cant seem to solve. I am making an irrigation computer that has 64 valves that run on 24v ac connected to relayboards, and 4 water meters with hardware debouncinghttp://hackaday.com/2015/12/09/embed-with-elliot-debounce-your-noisy-buttons-part-i/i have been having this problem for a while and have tried multiple fixes, first one i tried was making the relayboard optoisolated as explained in this artticlehttps://forum.arduino.cc/index.php?topic=365156.30but no luck the problem is less but still not gone, in a different place where i have just one relay board i replaced them with solidstate relays and the problem is 100% gone but in this case i can not do that, so i know it is the relay boards causing the issue.i also tested keeping the arduinos separate from each other where the water meter arduino was powered through my laptop and opening the relays still caused the interrupt to trigger.to make things worse if i do not attach the debouncer but just have lose wires of about 10cm attached it still triggers.I attached an image of what my system kind of looks like and here is my interrupt code should be fairly strait forward.Code:#include <Wire.h>#include <Arduino.h>//--------------------------------------------------------------//I2Cuint8_t Address = 0x09; //I2C addressvoid ReceiveEvent(int DataAvailable);void RequestCallback();uint8_t Command = 0;//--------------------------------------------------------------//--------------------------------------------------------------//clock interrupt stuffconst uint8_t Clock1Pin = 3;const uint8_t Clock2Pin = 4;const uint8_t Clock3Pin = 18;const uint8_t Clock4Pin = 19;volatile uint16_t values = { 0,0,0,0 };void Clock1() { values++; };void Clock2() { values++; };void Clock3() { values++; };void Clock4() { values++; };void InitInterupt();void ResetClock(uint8_t clock) { values = 0; }uint16_t GetClockData(uint8_t clock);//--------------------------------------------------------------void setup(){Wire.begin(Address);// join i2c bus with address #8Wire.onReceive(ReceiveEvent);// MAster sends dataWire.onRequest(RequestCallback);// Master Requests data#ifdef _DEBUGSerial.begin(9600);#endifInitInterupt();}// Interrupt initialization for the 4 clocksvoid InitInterupt(){pinMode(Clock1Pin, INPUT);pinMode(Clock2Pin, INPUT);pinMode(Clock3Pin, INPUT);pinMode(Clock4Pin, INPUT);// Attach an interrupt to the ISR vectorattachInterrupt(digitalPinToInterrupt(Clock1Pin), Clock1, FALLING);attachInterrupt(digitalPinToInterrupt(Clock2Pin), Clock2, FALLING);attachInterrupt(digitalPinToInterrupt(Clock3Pin), Clock3, FALLING);attachInterrupt(digitalPinToInterrupt(Clock4Pin), Clock4, FALLING);}uint16_t GetClockData(uint8_t clock){uint16_t val = values;ResetClock(clock);return val;}void loop(){#ifdef _DEBUGSerial.print("Clock1: ");Serial.println(values);Serial.print("Clock2: ");Serial.println(values);Serial.print("Clock3: ");Serial.println(values);Serial.print("Clock4: ");Serial.println(values);#endif}/*I2C Commands0x00 = do nothing0x07 = send data back the values of all the clocks0x01 = clock10x02 = clock10x03 = clock20x04 = clock3*/void ReceiveEvent(int DataAvailable){#ifdef _DEBUGSerial.print("Got data ");Serial.println(DataAvailable);#endif// set requested dataif (DataAvailable == 1)Command = Wire.read();}void RequestCallback(){if (Command == 0x07)SendAllClockData();else if (Command >= 0x01 && Command <= 0x04)SendClockData();}void SendClockData(){#ifdef _DEBUGSerial.print("Sending back clock data for");Serial.println(Command);#endifuint8_t Buffer[sizeof(uint16_t)];memset(Buffer, 0, sizeof(uint8_t));uint8_t sensor = Command - 1;*(uint16_t*)Buffer = GetClockData(sensor);Wire.write(Buffer, sizeof(uint16_t));Command = 0;}void SendAllClockData(){#ifdef _DEBUGSerial.println("Sending all clock data");#endifconst uint8_t BufferSize = 4;const uint8_t intsize = sizeof(uint16_t);uint8_t Buffer[BufferSize * intsize];memset(Buffer, 0, BufferSize * intsize);for (size_t i = 0; i < BufferSize; i++){*((uint16_t*)(Buffer + (i * intsize))) = GetClockData(i);}Wire.write(Buffer, BufferSize * intsize);#ifdef _DEBUGfor (size_t i = 0; i < BufferSize * intsize; i++){Serial.print(Buffer);Serial.print(",");}Serial.println();#endifCommand = 0;}tell me if you need any more information

author: Ginettag20
author_rank: Regular Contributor
timestamp: November 17, 2016, 10:38:47 am
content: Maybe Im missing something but what is the strange problem ?It sounds like an electrical noise issue. If your using solid state relays and these fix the problems its likely to be because they employ zero crossing. So you wont be picking up the mains spikes on your inputs when switching. Check your grounding and consider ground loops etc if you have multiple supplies connected.Chris

author: Precious Roy
author_rank: Contributor
timestamp: November 17, 2016, 10:48:47 am
content: Hey chris, that is what i thought at first a ground loop but even with only my arduino attached to my laptop for power and nothing but the debouncer and reedswiches attached it still picks up the noise.can the 24v ac adapter make noise on the 230v mains that then gets picked up through my laptop ?Edit:just did a test where my laptop is running on battery power and powering the arduino, nothing else is connected and when i cycle through the relays it still triggers.could the relays be generating some king of emf or emp and that is what i am picking up?

author: Ginettag20
author_rank: Regular Contributor
timestamp: November 17, 2016, 11:05:00 am
content: Sorry I cannot really follow your circuit layout and would need a actual schematic. I just going off your comment that the problem went away when you used solid state switching of the mains. I would more expect the problem to be on your mains side inducing unwanted currents in the low voltage side. I cannot comment on the arduinos or code as I dont use them.Have you probed the interupt input using your scope (if you have a scope) single shotDont assume wires over a few centres actually provide a good 0v / grounds.Does the problem go away when you turn off the mains supply that you are switched ?I think your relay card has fly back diodes but they will induce some current spike when coils change state.Im still not sure what you are report as being a problem is it that your interrupt trigger when the relays switch.

author: Precious Roy
author_rank: Contributor
timestamp: November 17, 2016, 11:34:25 am
content: I do seem to be rathe vage, sorry.Arduino A: triggering on interruptsArduino B: has the relays connectedlet me clarify, In the image below is how i have it connected in my newest test. the one arduino is not connected in anyway to the other.when B is turning on and off the relays the arduino A is triggering when it is by no means connected to each other.The problem does indeed go away if i turn off the 24v ac adapter.So to clarify my problem It should not be triggering, but it does. even though i am powering it from separate power suppliesEdit:I do not have a scope so i can not test that.the relayboards and ar powered by a 13.5v power supply, the arduino has its own 5v converter and the the relay boards have there own as well. but that aside the problem above still remains.

author: Ginettag20
author_rank: Regular Contributor
timestamp: November 17, 2016, 12:51:07 pm
content: Hi I dont think I can offer much more advice. Use your test equipmnet if you have it to locate if your interrupt line is being triggered. Look at the wiring at the bottom of the box it looks like the cabling is wrapped aound itself make sure you have the cabling for you control and switching circuit seperated.Sorry dont think i can add anymore.Chris

author: rstofer
author_rank: Super Contributor
timestamp: November 17, 2016, 02:24:12 pm
content: I don't see any bulk capacitance on the little interface board(s). I would put at least 100 ufd on each. The Arduinos will have enough capacitance (probably) but your boards need something.Make sure your interrupt signal is either fully high or fully low (depending on which edge is used to trigger) and if it isn't all the way at the voltage rail, add a pull-up or pull-down resistor. I would assume a negative going interrupt edge so a pull-up of 1k or so might help. It depends on what is driving the signal. If I had enough current sink capability in the source, I would probably try to get the resistor down to 470 Ohms.For a certainty, I wouldn't route the power and ground as a long daisy chain of very small wire.Make sure the relays have kick-back diodes across the coil. Lacking these, there will be a very high voltage spike when the coil is de-energized.Without a schematic, it is absolutely impossible to provide much help beyond generalities.

author: Gixy
author_rank: Regular Contributor
timestamp: November 17, 2016, 06:14:49 pm
content: Snubbers are your friends. I had such problem when switching ON and OFF external lighting by relays. Solved with snubbers across the relays' commands. Conrad or Farnell have some.

author: CraigHB
author_rank: Regular Contributor
timestamp: November 17, 2016, 06:24:03 pm
content: That can happen with voltage spikes, it can make the MCU go into an indeterminate state. When switching inductive loads you may need a snubber across the switch. The inductance of the load can interact with the capacitance of the switch (if it's a MOSFET) and you get oscillations producing pretty big voltage spikes. Also with relays you need a flywheel diode for inductive loads. MOSFETs have a body diode which will do that for you.

author: Precious Roy
author_rank: Contributor
timestamp: November 20, 2016, 09:34:33 am
content: Quote from: rstofer on November 17, 2016, 02:24:12 pmThat is the only resolution i could find for the schematicsi have no idea if they have kick-back caps on it, and i have no idea what it is so i will do some researchEdit i found some good resolution pdfsand i am pretty sure it does not have flyback diode when looking at the schematics, so that could be my problem ?

author: EPTech
author_rank: Regular Contributor
timestamp: November 20, 2016, 02:31:28 pm
content: Hi there,I agree with Gixy on this one. Put snubbers over all switched inductive loads, in your case over the solenoids of the valves. I would recommend as close as possible to the valve but over the relais contact is also OK.I was experiencing a similar problem with my CNC machine. Whenever a tool change took place, it went into a servo error. After chasing a lot of geese, like ground loops, I finally discovered I could recreate the problem by operating the large air valve that blows air through the spindle while a tool change took place. Just to show that these broad spectrum noise bursts can even stirr up industrial electronics. I placed a snubber over the relay contacts and the problem never occurred again.

author: Precious Roy
author_rank: Contributor
timestamp: November 21, 2016, 08:25:30 am
content: Thanks for allo your help, i am a little shocked that the relay boards don't have those diodes on it, but thats what you get when buying cheap crap.what kind of diodes should i put on them does it mater? i am not to familiar with them.

author: EPTech
author_rank: Regular Contributor
timestamp: November 21, 2016, 08:48:42 am
content: The relay coils themselves are also inductive load. The pictures are somewhat blurry but I think I see freewheeling diodes in the relay drivers so that is pretty well covered. The snubbers are supposed to go over the relay contacts. They will take the edge off the broadband noise, generated when the contact opens and they will mildly dampen the spark. If you want to prevent the contacts from sparking even more, you need to put a MOV over the contact as well, rated at a higher voltage than the voltage you are switching. For 240VAC I mostly see 275VAC. IMO a 10mm MOV of 275VAC should suffice in your case.Happy watering.

author: Precious Roy
author_rank: Contributor
timestamp: November 21, 2016, 09:56:03 am
content: Quote from: EPTech on November 21, 2016, 08:48:42 amif you look at the"16ch schematic.pdf"you can see a high resolution image.but I don't see any diode in it, bit it might be meis it in the ULN2083?.I do regret buying these boards so to everyone who want to buy a 16 channel relay interface board from sainsmart DON'T they are crap to much hassle for the price.

author: salbayeng
author_rank: Frequent Contributor
timestamp: November 21, 2016, 09:58:46 am
content: Hi.Putting RC snubbers (or varistors) at the switched outputs should work, as others have suggested.Your relay drivers are ULN2003 with internal diode, so no action required there.You might want to check if there is anything hanging off the reset pin, it should have a 4k7 pullup and a 100nF capacitor. I once had a problem with noise getting into the reset line on one of my PCB's. With incorrect R and C.Sometimes it helps to put everything on a sheet of zinc plated steel (or aluminium), and connect all the grounds (usually the mounting holes) to the backplane.If you are programming the fusebits, ensure the brownout value is set to the lowest value (2.7v), it will ride through spikes on the 5v better.