sicamxdf



Currently I have a segment of code that is based on the operation by time and has been giving many laps and I do not find a satisfactory solution The description of the problem: Step 1: The program starts with ton with a duration of 3 sec Once Q of this timer is active then copy a variable it takes from the globals and copy it to a local variable Step 2: Parallel to the aforementioned timer 1 a timer 2 with a duration of 6 sec starts and at the end of the cycle of this one makes a comparison of the variable that was stored in step 1 with a variable that comes from modbus and stores the Result of the comparison for later use
3.- The cycle starts again As a comment if this exercise is performed with codesys or similar works without problem and when transferring the code in st and ld to open plc re initializing the timers the variables also disappear Thanks for your help in resolving this issue.

Thank you in advance
Reply 0 0
thiagoralves
It is hard to picture what you are trying to accomplish without your code. Could you please attach your project here as a .zip file?
Reply 0 0
sicamxdf
in this dummy i show you an example  after the rung 3 var1 and var2 preserves its values,   when i move this code to openplc  change the execute block with functions  and reflex the variables var1  and var2 in modbus adress %qw12,%qw13  then when the tmr0 is inactive var1 and var2 have  zero value, when the timer is stoped and q is set (btmr0) i can the the changes on vars in modbus registers when the rung 3 is executed the vars are cleared  



ok i  test.png 
Reply 0 0
thiagoralves
That's why I asked you the PLCOpenEditor project file, because without it it's hard to know what you are doing wrong. From the picture you sent, I guess that what you may be doing wrong is using a function to store your custom ST code block instead of a functionBlock. According to the IEC61131-3 standard, they are different things. Take a look at http://ua.automation.com/resources-tools/application-stories/programmable-logic-controller-plc/iec-61131-3-functions-and-function-blocks-what-is-the-difference

Basically, functions only executes a piece of code and exit, and functionBlocks retains internal variables' values after each cycle.
Reply 0 0
sicamxdf
As always thanks for your fast response and great effort i try with a fb instead function 
Reply 0 0
sicamxdf
Solved

solved.png 
cv block:
(* kpa and keepAlive are stored as external at %QW12 and %QW13*)
if act then
IF kpa < 1000 THEN
keepAlive := keepAlive + 1;
kpa := keepAlive;
END_IF;
end_if;

rt block:
(*etp1 is an integer var stored at %IW5*)
IF tmr_activo = FALSE THEN
s_tmr_activo := true;
END_IF;

IF tmr_activo AND btmr0 THEN
s_tmr_activo := false;
END_IF;

Again, a thousand thanks and taking advantage of the occasion, I could you recommend a good tutorial about SFC language

Reply 0 0
sicamxdf
Now for the sencond part of issue 

parte2.png 

 
if act then
if kpa = keepAlive then
out := false;
compara := 0;
else
out := True;
compara := 1;
end_if;
end_if;

When the plc is running through modbus I can see how the variables change depending on whether kpa and keepAlive are the same or not in %QW12 (keepAlive),13 (kpa) and 14 (compara), but this change is not reflected in the boolean variable in% QX5.3 (bKeepAlive), perform some tests and if i assign an address for example % IX0.0 I can see how Change the values ​​in the plc according to the programmed but not so if I change the assignment to% QX5.3 or % IX5.3

The configuration I am using is for raspberry with driver blank Once again, I appreciate your support.
Reply 0 0
thiagoralves
%QX5.3 is out of bounds for the Raspberry Pi driver. However, the modbus module should keep track of it out of the buffer. Please send me your project and I'll take a look
Reply 0 0
sicamxdf
Thanks a lot for your quick response,

Firstly so that you understand the context the project in general, it is based on a raspberry 2 + an atmega 328 which registers the operating temperature with 4 analog ports and controls the i / o.

The whole program is designed for the control of a chiller by a certain Brazilian for which there are no spare parts, and will replace an obsolete plc that now operates the system partially, so you already have a python + pyqt application that will serve As an HMI on a touch screen.

Second: a program in python scans the arduino inputs and by fixed modbus the% QXn.n registers that serve as reference to the PLC use% Qn.n since I can not force the contents of the% IXn.ny the same pgram reads the PLC output registers and fix arduino ports

Third: In case the program in python does not receive response from plc then it puts all arduino ports down

Fourth: In the case that the arduino does not receive data of the program in python in a lapse no more than 3 seconds the arduino puts under all the exits

Fifth: in case the plc does not receive change in the data from the arduino in a period of 3 seconds the plc deactivates all ports of exit, this is where it enters what I try to solve

Sixth: when reading the code and variables you will realize that the only jump that exists is in segment% IX1.n and the other assigndas correspond to various alarms and internal process variables.

Seventh: Considering your kind comments on the boundaries of the addresses I would like if possible indicate the limits concerning each type of project so that in your case you can realign some things or give them a different treatment

Thanking you in advance for your fine attention, attach the project file

pajustes.png  palarmas.png 

ptimers.png 

Sorry for the english translate tools some time write an strange things 
Reply 0 0
sicamxdf
Thanks again i have news

I made some changes an now its working

1.- The code is organized and put together all variables of the same type

2 They were moved to premises all the variables that were external made the adjustments in the control blocks

3. Re-reading the documentation on the website of the project I realized that to put the system to work the correct command is nodejs server.js and was using node server.js

I was doing intermediate tests between each of the steps I mentioned and after doing the last one can see the boolean variables in% IX.4.3 or% QX5.3

Something that I find curious is that even though the web page on port 8080 says that the plc is stopped, modbus continues to operate, while compiling the new program 3 of every 4 times stops the plc completely and I realize since the program in python begins to throw exceptions for faults in the communication with plc

As always, thank you for kindly attending to my request.
Reply 0 0
sicamxdf
Sorry i forgot upload the last program
Reply 0 0
thiagoralves
I'm glad it is working now. I just don't understand why you wrote a python program to communicate with the arduino if you could just use OpenPLC Arduino driver to do that? It would have made your life much easier. By using OpenPLC's Arduino driver, you can control the Arduino I/O as if they were OpenPLC's I/O. Check here: http://www.openplcproject.com/getting-started-arduino
Reply 0 0
sicamxdf
yes i know   but if i use this option i need to use a mega board  because i need 7 digital inputs and 5 digital outputs then i need a mega board at least and is it to big for the application and it size doesnt fit in the control box of the machine for that reason i use only the atmega 328 in own small custom pcb as io controller y temp  on an other board i have the relays and in another one i have the optocouplers and other componets to fit all into the chiller at the same space for occuípied for the actual plc

i like to know what do think  about my proyect?
Reply 0 0
thiagoralves
Your project seems really nice, specially the HMI portion of it. Is the HMI communicating directly with OpenPLC over Modbus to read the values? I just think that you could drop that python script entirely and make your life easier. If you need to rearrange how Arduino Pins are used by OpenPLC, I posted a solution here: https://openplc.discussion.community/post/change-arduino-pin-allocation-8326119?highlight=arduino+pins

So, you can just modify these files to have as many inputs you need. You can even use the analog inputs as digital input or output. This will avoid having one more thing between OpenPLC and the Arduino. You know, in engineering, the chances of failures in your project is directly proportional to the complexity of your project. Reducing the number of layers seems to be a good thing to reduce the number of possible errors as well.

Let me know if the project is running fine and specially if OpenPLC is being able to run uninterruptedly without issues.
Reply 0 0
sicamxdf
Ok thanks for the advice,  and i´ll try for that way i'll tell you  soon,  for now i working in fill the alarms an events tables in the hmi but your idea sounds very fine because the python needs to be supervised 

Again thanks for your kind attention 

 
Reply 0 0
Reply