cpilote
Hi!
I'm getting familiar with OpenPLC Editor and I have a question about action Blocks.
I did the following program in SFC with Ladder actions and transitions:
Capture.png  these are my ladder actions: action0(left) action1(right)
   action0.png  action1.png 

these are my ladder transitions: transition0(left) transition1(right)
transition0.png  transition1.png    
When I use the debugging tool, once the step1 is active, the action0 is always active even when the transition1 is done and the step2 is active.  I would like each action to be only active during their respective step. There is probably a very simple reason why all of this is happening but since I'm a beginner I really have no clue.

Thanks for your help in advance,
Claudie
Quote 1 0
thiagoralves
I don't know what you did with your program, but this simple diagram worked for me:
Capture.png 
PB0, PB1, Lamp0 and Lamp1 are all BOOL variables. When PB1 is active and it transitions to Step 2, Lamp1 becomes active and Lamp0 becomes inactive, even if PB0 is still pressed. That's the behavior you want (action block modifier N). Attached is my project for reference.
Quote 0 0
cpilote
Hello Mr. Alves, thank you for your quick reply.
I think there is something I don't understand about the way action blocks work.
I made a slight modification to your code, I added an action block and a local boolean (action0 and "okay").
I simply used the two input to move from step 1 to step 3. I don't understand why DO3 doesnt go to false once we leave step2.

I added the project to this post, thank you. ss1.png  ss2.png 
Quote 1 0
thiagoralves
Now I see what you did with your program. You're associating an action block with an action. You see, an action is like an independent program that runs while the step is active. The step only controls if this independent program (action) is running or not. When the step goes inactive, the action stops and keeps its last state. It is like pausing this separate program. The action will only continue to run once the step goes active again. You can confirm this by debugging the action itself. You will see a little (Active) or (Inactive) writing on the top of the action when it is running / not running. Since all your action program does is turn a variable to TRUE, that variable will keep its on state even after the action program is stopped. Its state will only change when something else (another action or another action block) change its state again to FALSE.

If all you want to do is change the state of a variable depending on if the step is active or not, you should use an action block of type "variable" instead of type "action". Now, if you need more complex logic to run within the action block, you will certainly need to use an "action" type as you're doing, but just keep in mind that the variables inside your action will not automatically clear to FALSE or zero once your action goes inactive.
Quote 0 0
cpilote
Once again, thank you for you quick and clear response. It is much appreciated. 

Since I really need to use action block, what would be the cleanest way for us to clear to FALSE or zero once our action is inactive?
Quote 1 0
thiagoralves
The cleanest way is to address all variables in all steps. Let's say in step1 your variable VAR needs to be TRUE. If you don't do anything with VAR once it reaches step2, VAR will continue to be TRUE. If then you address all your variables on each step (this is actually a good programming practice) you will ensure that on each step, all your variables are in the state you want. So, if VAR needs to be FALSE on step2, write it on the action for step2. Don't assume your variables will be cleared between steps. For this reason, you will realize in the end that it is a lot easier to write actions in structured text than ladder logic. In fact, the editor even has an inline capability that allows you to write structured text code for an action without having to create a separate action.

Again, keep in mind that if all you need to do is change variables states, instead of creating action blocks of type "action" it is a lot easier to just create action blocks of type "variable". Then, all variables associated with the action block will be TRUE when the action is active and FALSE when the action is inactive. Action blocks of type "action" are useful if in fact you need to perform complex logic (count numbers, arithmetic operations, etc) in the action.
Quote 0 0