Unity Pro M340 - step not executing

bogu

Lifetime Supporting Member
Join Date
Mar 2020
Location
Alberta
Posts
22
Greetings,
I'm new at PLC programming, but good a logic - so I thought.
I've inherited a PLC system, which is presently operating in the field just fine - vintage 5 years old. I can't get the code to execute on my desktop using the Unity Pro V12.0 simulator. I've reduced the code to a bunch of test routines - which are failing.
- The main SFC cycles fine. Changing BOOL values changes the path.
- The SFC steps show as TRUE when the plc cycle passes through them.
- However, the Structured Text (ST) in the SFC step does not execute at all. IE: The 'Main_2A.x THEN' resolves as TRUE but does not enter the line below. The inherited PLC system uses this approach everywhere.
Thoughts?

plc2.JPG

plc1.JPG
 
To me it looks like its doing what it should. BC_main2a is on according to your animation table...And the condition for the step to go through the transition is not bc_main2a
 
Hmmm.... some things sort of work now? I made some changes.
Nomenclature - Sequential Function Chart = SFC, Structured Text = ST

Main Chart:
• On initialization the SFC is free running. Toggling bc_main1A/2A places the SFC into step Main_1A/2A accordingly = good.
• When in Main_2A, the ST goes to the ‘IF Main_2A.x THEN etc.’, this initializes the 'id_stepNumber' to 2000. This works and execution transfers to another chart.
C2000 chart:
• Step2000 contains the condition 'id_stepNumber = 2000' so it passes through.
• Step B_2000 in the ST has the ‘IF B_2000.x = TRUE THEN’ which is where execution stops.
• For some reason its not processing the time check ‘IF B_2000.t > T#1s THEN’. If I remove this it executes fine.

The topology uses a main chart that calls a bunch of different charts as needed. This is the way the original code was written. Just now, it always halts on the ‘step.t’ time check??

plc3.JPG
 
I believe the contents of the step_2010 transition logic should be


Code:
if id_stepnumber = 2010 then
step_2010 = true;
end_if;


where I have used FB SFC transition sections we wrote to a tag with the same name as the section for the result or return value of the transition section.


Maybe with ST you can just put a condition in there?



maybe put a line such as my_step := id_stepNumber; in the transition section and see what value stepnumber has when the transition section is being executed. maybe it is being written to a value other than 2010 elsewhere in your program.


one reason to use SFC for a state machine is to avoid having a 'magic number' for the state that is written to in many different places.


I generally use boolean tags for transition sections, and then have one program section which controls the transitions, instead of having the logic sprinkled around in dozens of little sections.
 
Thanks for the feedback.
I think I implemented what you described. Using BOOL variables for the transition section control.
- Note – the transition section only accepts BOOL results. I cannot use conditions like If-Then.
The code executes now: Main jumps to C2000 when ‘b_stop2000’ is TRUE, but the SFC C2000 never ends. Just keeps looping, even though in step B_2040 all the BOOL is reset.
I’m still not certain how a PLC executes code. Can a child SFC change variables the Parent SFC sets? Is there a parent / child relationship?
plc4.JPG
 
main_2a.x is setting b_step2000 so after B_2040 despite b_step2000 being reset it is just set again in main_2a.x and so after going from step B_2040 to the beginning of the sequence step B it immediately leaves step B again and begins the sequence.


here's a couple tips for beginning PLC programming
1) don't use ST. use ladder or FB. in schneider PLC FB is better than ladder. it will animate better and show you what is going on.

2) don't write to the same tag more than once
3) don't use latches such as SET and RESET on a bit unless absolutely necessary. in function block use the blocks SETD and RESD for latches if you need them.
4) try and make every tag that is written be written to every PLC program scan. it makes for a simpler program
 

Similar Topics

If I am disconnected from M340, I cant see the Values. Unlike RSLogix when one gets to choose upload state values upon exit, and these state...
Replies
4
Views
2,264
I am trying to make a function that count the number of True BOOL inn a specific Array and return the count to an INT AlarmArrayActiveAlarms. I...
Replies
8
Views
4,442
Hello all, My company have sourced a Modicon M340 PLC with a Magelis (XPT GTO4310) HMI. The intention here is to use this setup in order to...
Replies
6
Views
3,697
I am having trouble with creating a shift register in Unity Pro on my Schneider M340. I am using the FFB SHR to try and get this to work. I have...
Replies
13
Views
5,077
Hi, Is it possible to scale the 4 to 20mA output of a Vegaflex 63 TDR Level Senor mounted on an inclined horizontal cylindrical diesel tank with...
Replies
5
Views
3,242
Back
Top Bottom