Author Topic: Strange Interrupt problem  (Read 5822 times)

0 Members and 1 Guest are viewing this topic.

Offline Precious RoyTopic starter

  • Contributor
  • Posts: 18
  • Country: nl
Strange Interrupt problem
« on: November 17, 2016, 10:18:32 am »
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 debouncing http://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 artticle https://forum.arduino.cc/index.php?topic=365156.30

but 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: [Select]
#include <Wire.h>
#include <Arduino.h>

//--------------------------------------------------------------
//I2C
uint8_t Address = 0x09; //I2C address
void ReceiveEvent(int DataAvailable);
void RequestCallback();

uint8_t Command = 0;
//--------------------------------------------------------------

//--------------------------------------------------------------
//clock interrupt stuff
const uint8_t Clock1Pin = 3;
const uint8_t Clock2Pin = 4;
const uint8_t Clock3Pin = 18;
const uint8_t Clock4Pin = 19;

volatile uint16_t values[4] = { 0,0,0,0 };

void Clock1() { values[0]++; };
void Clock2() { values[1]++; };
void Clock3() { values[2]++; };
void Clock4() { values[3]++; };

void InitInterupt();
void ResetClock(uint8_t clock) { values[clock] = 0; }
uint16_t GetClockData(uint8_t clock);
//--------------------------------------------------------------

void setup()
{
Wire.begin(Address); // join i2c bus with address #8
Wire.onReceive(ReceiveEvent); // MAster sends data
Wire.onRequest(RequestCallback); // Master Requests data

#ifdef _DEBUG
Serial.begin(9600);
#endif

InitInterupt();
}

// Interrupt initialization for the 4 clocks
void InitInterupt()
{
pinMode(Clock1Pin, INPUT);
pinMode(Clock2Pin, INPUT);
pinMode(Clock3Pin, INPUT);
pinMode(Clock4Pin, INPUT);

// Attach an interrupt to the ISR vector
attachInterrupt(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[clock];
ResetClock(clock);
return val;
}

void loop()
{
#ifdef _DEBUG
Serial.print("Clock1: ");
Serial.println(values[0]);
Serial.print("Clock2: ");
Serial.println(values[1]);
Serial.print("Clock3: ");
Serial.println(values[2]);
Serial.print("Clock4: ");
Serial.println(values[3]);
#endif
}

/*I2C Commands
0x00 = do nothing
0x07 = send data back the values of all the clocks

0x01 = clock1
0x02 = clock1
0x03 = clock2
0x04 = clock3
*/
void ReceiveEvent(int DataAvailable)
{
#ifdef _DEBUG
Serial.print("Got data ");
Serial.println(DataAvailable);
#endif

// set requested data
if (DataAvailable == 1)
Command = Wire.read();
}

void RequestCallback()
{
if (Command == 0x07)
SendAllClockData();
else if (Command >= 0x01 && Command <= 0x04)
SendClockData();
}

void SendClockData()
{
#ifdef _DEBUG
Serial.print("Sending back clock data for");
Serial.println(Command);
#endif

uint8_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 _DEBUG
Serial.println("Sending all clock data");
#endif

const 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 _DEBUG
for (size_t i = 0; i < BufferSize * intsize; i++)
{
Serial.print(Buffer[i]);
Serial.print(",");
}
Serial.println();
#endif

Command = 0;
}

tell me if you need any more information
« Last Edit: November 17, 2016, 10:22:07 am by Precious Roy »
 

Offline Ginettag20

  • Regular Contributor
  • *
  • Posts: 54
Re: Strange Interrupt problem
« Reply #1 on: November 17, 2016, 10:38:47 am »
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

« Last Edit: November 17, 2016, 10:43:28 am by Ginettag20 »
 

Offline Precious RoyTopic starter

  • Contributor
  • Posts: 18
  • Country: nl
Re: Strange Interrupt problem
« Reply #2 on: November 17, 2016, 10:48:47 am »
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?
« Last Edit: November 17, 2016, 11:04:23 am by Precious Roy »
 

Offline Ginettag20

  • Regular Contributor
  • *
  • Posts: 54
Re: Strange Interrupt problem
« Reply #3 on: November 17, 2016, 11:05:00 am »
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 shot

Dont 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.

« Last Edit: November 17, 2016, 11:08:39 am by Ginettag20 »
 

Offline Precious RoyTopic starter

  • Contributor
  • Posts: 18
  • Country: nl
Re: Strange Interrupt problem
« Reply #4 on: November 17, 2016, 11:34:25 am »
I do seem to be rathe vage, sorry.

Arduino A: triggering on interrupts
Arduino B: has the relays connected

let 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 supplies

Edit:

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.
« Last Edit: November 17, 2016, 11:45:47 am by Precious Roy »
 

Offline Ginettag20

  • Regular Contributor
  • *
  • Posts: 54
Re: Strange Interrupt problem
« Reply #5 on: November 17, 2016, 12:51:07 pm »
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
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9888
  • Country: us
Re: Strange Interrupt problem
« Reply #6 on: November 17, 2016, 02:24:12 pm »
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. 
 

Offline Gixy

  • Regular Contributor
  • *
  • Posts: 232
  • Country: fr
Re: Strange Interrupt problem
« Reply #7 on: November 17, 2016, 06:14:49 pm »
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.
 

Offline CraigHB

  • Regular Contributor
  • *
  • Posts: 227
  • Country: us
Re: Strange Interrupt problem
« Reply #8 on: November 17, 2016, 06:24:03 pm »
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.
« Last Edit: November 17, 2016, 06:32:01 pm by CraigHB »
 

Offline Precious RoyTopic starter

  • Contributor
  • Posts: 18
  • Country: nl
Re: Strange Interrupt problem
« Reply #9 on: November 20, 2016, 09:34:33 am »
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.

That is the only resolution i could find for the schematics





i have no idea if they have  kick-back caps on it, and i have no idea what it is so i will do some research

Edit i found some good resolution pdfs

and i am pretty sure it does not have flyback diode when looking at the schematics, so that could be my problem ?

« Last Edit: November 20, 2016, 11:12:45 am by Precious Roy »
 

Offline EPTech

  • Regular Contributor
  • *
  • Posts: 168
  • Country: be
    • EP Technical Services
Re: Strange Interrupt problem
« Reply #10 on: November 20, 2016, 02:31:28 pm »
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.
Kind greetings,

Pascal.
 

Offline Precious RoyTopic starter

  • Contributor
  • Posts: 18
  • Country: nl
Re: Strange Interrupt problem
« Reply #11 on: November 21, 2016, 08:25:30 am »
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.
 

Offline EPTech

  • Regular Contributor
  • *
  • Posts: 168
  • Country: be
    • EP Technical Services
Re: Strange Interrupt problem
« Reply #12 on: November 21, 2016, 08:48:42 am »
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. ;)
Kind greetings,

Pascal.
 

Offline Precious RoyTopic starter

  • Contributor
  • Posts: 18
  • Country: nl
Re: Strange Interrupt problem
« Reply #13 on: November 21, 2016, 09:56:03 am »
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. ;)

if 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 me is 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.
« Last Edit: November 21, 2016, 09:57:43 am by Precious Roy »
 

Offline salbayeng

  • Frequent Contributor
  • **
  • Posts: 296
  • Country: au
Re: Strange Interrupt problem
« Reply #14 on: November 21, 2016, 09:58:46 am »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf