Jump to content

Data Table read problem


Recommended Posts

I have the following problem :

 

In net 1, I read a column of a data table in MI100 ... MI 109 

in the same net (net 1) I search a certain value in the MI100...MI109, with a CALL subroutine that returns a returnvalue.

 

Is this allowed, or should I search this value in another net ?

 

Because sometimes (not always) I don't have the correct  returnvalue ?

 

program look likes this :

 

 read column and write to MI 100...MI 109  // search value into MI 1 // call subroutine for searching where MI 1 is in MI 100...MI 109 // put return value into MI 2 ( all this is place in one net ! )

 

or should it be like this ?

 

net 1 : read column and write to MI 100...MI 109

net 2 :search value into MI 1

net 3 : call subroutine for searching where MI 1 is in MI 100...MI 109

net 4: put return value into MI 2 

 

before I change my program, I want to know if this is the problem of bad readings !

 

 

 

 

 

Link to comment
Share on other sites

  • MVP 2021

It is bad programming practice to put instructions together in the same ladder rung that aren't conditional. The only real exception would be when you have a coil that must be activated by multiple situations, since coils should always only exist in a single net.

 

When you have an unnecessarily complex net, you run the risk of unpredictable results due to the compiler organizing the instruction differently than you might have expected.

Link to comment
Share on other sites

I have the following problem :

 

In net 1, I read a column of a data table in MI100 ... MI 109 

in the same net (net 1) I search a certain value in the MI100...MI109, with a CALL subroutine that returns a returnvalue.

 

Is this allowed, or should I search this value in another net ?

 

Because sometimes (not always) I don't have the correct  returnvalue ?

 

program look likes this :

 

 read column and write to MI 100...MI 109  // search value into MI 1 // call subroutine for searching where MI 1 is in MI 100...MI 109 // put return value into MI 2 ( all this is place in one net ! )

 

or should it be like this ?

 

net 1 : read column and write to MI 100...MI 109

net 2 :search value into MI 1

net 3 : call subroutine for searching where MI 1 is in MI 100...MI 109

net 4: put return value into MI 2 

 

before I change my program, I want to know if this is the problem of bad readings !

Hi Pascal,

 

Flex 727 is right. In ladder programming, the compiler can change the order of commands execution (in a single net) which may cause unexpected results. It is recommended to separate your code into simple structures - or one rung per net. This will also make your code more readable.

Link to comment
Share on other sites

Ok,

 

I think this will be the problem ( bad programming of me ! )

 

But 1 question about this issue :

 

is the order of commands execution always the same, or can it change in time. The most of the time, I get "good" values, but suddenly I get a wrong one !

Or is the time needed for an read data table column and put the values into the MI's taking some time, so this is sometimes slower and I get "bad" result.

this is because I want to explain my customer why the PLC sometimes gives the "wrong" values. 

Link to comment
Share on other sites

Ok,

 

I think this will be the problem ( bad programming of me ! )

 

But 1 question about this issue :

 

is the order of commands execution always the same, or can it change in time. The most of the time, I get "good" values, but suddenly I get a wrong one !

Or is the time needed for an read data table column and put the values into the MI's taking some time, so this is sometimes slower and I get "bad" result.

this is because I want to explain my customer why the PLC sometimes gives the "wrong" values. 

Pascal,

Once the code has been compiled and downloaded to the PLC, it will always be executed in the same order.

Getting an occasional "wrong" value is probably a problematic logic. If you are not sure why this happens, you are welcome to send the application to support@unitronics.com including details related to the issue, and we will point it out.

Link to comment
Share on other sites

  • 1 month later...

Hi,

I rewrote my program, so I divided the large rungs into more rungs.

 

But still I have a question and problem.

 

Is it possible that the PLC reads a bad value from the datatables while the data tables are updated with " remote access " ?

 

Every cycle I read the data table, but the customer changed the values of the data table and suddenly he had wrong values ?

I checked the program, but couldn't find any wrong programming.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...