Maybe someone has seen this before

I have a puzzling issue happening and hope that someone has come across it before. My description will be somewhat vague. It is happening in a program that has about 2000 lines of code. This is an arduino compatible plc. Automation Direct P1AM-100 to be specific. It is a MKRZero compatible unit..
So in a nutshell I am using this plc to do building HVAC control. It consists of several modules with various types of inputs and outputs there are about 60 points. Combinations of digital inputs, outputs, analogue inputs, outputs, and relay outputs.
I interface with it though a program written with Xojo using the xojo URL connection control to an ethernet module in the plc setup. Using a pc as a HID I send data from the pc to the plc using json with the ArduinoJson Library.
Everything is working remarkably well and has been up and running for several years.
I use a sqllite db to store the inputs, outputs, control, etc information.
I changed some of the records recently and made it so that the offending ID is now being used.
Now to the problem.
I have a table that has all of the controls source, means to turn the outputs on and off, it may reference another modules inputs or may refer to a function in the plc.
I have a readable point name and store it's id to the plc's memory. When I use the id of 30 the out put that that control id is tied to turns on no matter what. It is the only one that does it. It does not matter which module I use it on as soon as I use the id of thirty it turns on. if the id can be any number from 0 to 42 and it only occurs when the control has an id of 30. very strange. I have gone over the code for many hours trying to sort it out. None of my code is turning it on. My best guess unless someone knows is that it may be happening in the library from the plc mfg.
I thought it could be a mkrZero memory issue but I am using only 35% of space.

I store the control ids in an array of unsigned 8bit integers for use while the program is running.
It looks something like this;

This is a global array. One of many
ModuleNameContol[id]
as soon as it becomes 
ModuleNameContol[30]
the output that has this element assigned to turns on.

I can work around it by not using that id, but any ideas are appreciated.

Does that mean you are looking for vague answers?

Look between lines 101 and 1020 I think you will find your problem but the function in line 1778 may be causing interference. That concurs with the schematic you posted.

2 Likes

Thanks, I asked for it.

I was hoping that someone saw this problem before.

I would have been more helpful if you could have pinpointed it a little like between lines 500 and 900. My function is in line 1643. But thanks I will have a look.

Not likely unless someone has your exact project and your exact software. Guess it's time to debug.

I get it, thank you. I was merely hoping that someone had a very similar thing happen to them. I have often seen questions about situations that I have already been through and know what the solution is. That is what I was looking for. There is no way I could post my code because it would take hours to explain what is going on and I am a poor at documenting. Thanks for looking.

I have figured out what was causing the problem for those that may encounter it in the future. It is probably a problem that I should have known about and avoided. The issue was that I created a global array with 16 elements. They all contain 8 bit integers so I declared it as an 8 bit integer. For many years it was not a problem as the program was using only a small number of the elements. When the hardware expanded and all of the elements were being used putting the value 30 in one of the elements apparently was causing this problem. I changed the declaration to uint as apposed to uint8-t and the problem is gone. I don't fully understand why but it is fixed.

changed this 
uint8_t td2Ctrl[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
to this
uint td2Ctrl[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

using it like this
td2Ctrl[ch] ch is 14 and has a value of 30.

here is the whole function
static void P115TD201Process()
{
	byte outState = 0;
	byte stsLatch = 0;
	byte tsl = 1;
	byte tch = 1;
	byte zcfh = 0;

	for (int ch = 1; ch < 16; ch++)  // iterate through channels
	{
		stsLatch = td2Sts[ch];
		zcfh = 0;

		if (td2Ctrl[ch] > 0 && td2Ctrl[ch] < 8) // thermistor range
		{
			tsl = td2Ctrl[ch] > 4 ? 2 : 1;
			tch = td2Ctrl[ch] > 4 ? (td2Ctrl[ch] - 4) : td2Ctrl[ch];
			thermProcess(tsl, tch);
			zcfh = zoneCallForHeat[tsl][tch];
		}

		if (td2Md[ch] == 1 || zcfh == 2)  // on
		{
			outState = ON;
		}
		else if (td2Md[ch] == 2)  //auto
		{
			if (td2Sch[ch] > 0)
			{
				byte cv = td2Sch[ch] - 1;

				if (schStatus[cv])
				{
					if (td2Ctrl[ch] > 0 && td2Ctrl[ch] < 8) // thermistor range
					{
						outState = zcfh;
					}
					else
					{
						if (td2Ctrl[ch] == 0)
						{
							outState = 1;
						}
						else
						{
							outState = controlProcess(td2Ctrl[ch], p115td2_m4, ch);
						}
					}
				}
				else
				{
					outState = 0;
				}
			}
			else  // schedule off
			{
				if (td2Ctrl[ch] > 0 && td2Ctrl[ch] < 8) // thermistor range
				{
					outState = zcfh;
				}
				else
				{
					outState = controlProcess(td2Ctrl[ch], p115td2_m4, ch);
				}
			}
		}
		else //if (td2Md[ch] == 0)  // off
		{
			outState = OFF;
		}

		if (outState)
		{
			if (stsLatch == 0)
			{
				P1.writeDiscrete(HIGH, p115td2_m4, ch);  // value, Slot, channel
				td2Sts[ch] = 1;
			}
		}
		else
		{
			if (stsLatch == 1)
			{
				P1.writeDiscrete(LOW, p115td2_m4, ch);  // value, Slot, channel
				td2Sts[ch] = 0;
			}
		}
	}
}

That makes no sense, but if the problem has gone away, be happy!

Why do I have a feeling that the cause of the problem was writing beyond the bounds of an array or some such, and who knows if/when the problem is going to come back?

You're not the only one.

1 Like

Thanks for all of the input. I will keep an eye on it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.