diegohap
Hi. I have a little strange problem. I made the PLC project with Arduino and work just fine. I tried the HelloWorld example and it work just fine too. Then I modify that project and made a single traffic light and work just fine too:

TrafficLight.jpg 
Then I modify the same project again and I tried to make a Toggle Flip-Flop but it doesn't work at all.
Please, any ideas ?????. I emulate the exactly ladder on WindLadder editor and it work just fine.
My inputs are all low_active.
Here the Toggle Flip-Flop diagram:
Toggle.jpg   


Reply 0 0
thiagoralves
What is "not working"? Do you have any specific behavior you're getting from this program? It is useful to see your variables list to understand what type of variables are those.

In my quick analysis, Lamp will never turn on, because M0 is off all the time. The only line that sets M0 is the second from the bottom up, and it depends on the M0 itself to turn it on. So it will never work. Below is a working way of making a toggle flip-flop:
Capture.PNG 
Capture.PNG 

I tested on my Arduino with OpenPLC and it worked fine. My setup has active high inputs, so if your Arduino is configured for active low inputs, just change the two Input contacts on the program to Negated, and it should work as well. I put the program attached here for your reference.


Happy coding! [smile]
Reply 0 0
diegohap
I have edited the ladder, at the 3th line M0 now it will be Set when the button is not pressed and M0 is off. Remember, my buttons work with active LOW Loggic.
The program still not working. It just do nothing when I press the button. The Output QX0.1 Lamp remains OFF and Qx0.2 MemTest, shows what M0 are doing, remains always ON.
Reply 0 0
thiagoralves
Your logic is broken, it won't work that way. On the first line the Lamp is set, but right after it, on the second line your Lamp is reset because your button will still be on. Remember that ladder logic is evaluated in scan cycles. Even if you manage to have a super fast finger and press the button in a fraction of a millisecond, the state of your inputs will not change until the next scan cycle. Therefore, your entire program is evaluated with the same inputs until the end of the scan cycle, which means that your button is pressed for both first and second ladder logic lines, making the Lamp set and immediately reset after.

Copy my program and change both Input contacts to "negated" (because your buttons work with active low logic) and you will have your toggle flip-flop behavior.
Reply 0 0
diegohap
No, watch the first line carefully. In the second line the Lamp will NOT be reseted because in the first line M0 was reseted. M0 will be set only when the button is not presed and M0 off at the third line.
Thanks for the fast answer [smile]
Can you go online in the chat ?, it will be more easy [biggrin]
Reply 0 0
thiagoralves
I don't know what is wrong with your program, but I know that the one I sent you works because I tested it.

Perhaps PLCopen Editor is not liking your parallel outputs on lines 1 and 2. Can you post here the ST file it generates? One guess would be to create another rung between 1 and 2 saying that if Lamp is true then M0 is reset, and do the same thing for lines 2 and 3. But if everything fails, use my program.
Reply 0 0
diegohap
Hi thiagoralves. Sorry about the late. I check what you said and I found the proble. The problem is when the compiler create the ".st" file. It consider diferent actions in the line 1 and 2 when "lamp" and "M0" are "seted" or "reseted".
Here the "st" code by the compiler:

PROGRAM My_Program
VAR
I0 AT %IX0.2 : BOOL;
M0 AT %MX0.0 : BOOL;
Lamp AT %QX0.1 : BOOL;
MemTest AT %QX0.2 : BOOL;
END_VAR

IF NOT(Lamp) AND M0 AND NOT(I0) THEN
Lamp := TRUE; (*set*) END_IF;
IF NOT(Lamp) AND M0 AND NOT(I0) THEN
M0 := FALSE; (*reset*) END_IF;
IF Lamp AND M0 AND NOT(I0) THEN
Lamp := FALSE; (*reset*) END_IF;
IF Lamp AND M0 AND NOT(I0) THEN
M0 := FALSE; (*reset*) END_IF;
IF NOT(M0) AND I0 THEN
M0 := TRUE; (*set*)
END_IF;
MemTest := M0;

END_PROGRAM
CONFIGURATION Config0
RESOURCE Res0 ON PLC
TASK TaskMain(INTERVAL := T#50ms,PRIORITY := 0);
PROGRAM Inst0 WITH TaskMain : My_Program;
END_RESOURCE
END_CONFIGURATION

Here the "st" file fixed by me.
PROGRAM My_Program
VAR
button AT %IX0.0 : BOOL;
M0 AT %MX0.0 : BOOL;
lamp AT %QX0.0 : BOOL;
MemTest AT %QX0.1 : BOOL;
END_VAR

IF NOT(lamp) AND M0 AND NOT(button) THEN
lamp := TRUE; (*set*)
M0 := FALSE; (*reset*)
END_IF;
IF lamp AND M0 AND NOT(button) THEN
lamp := FALSE; (*reset*)
M0 := FALSE; (*reset*)
END_IF; IF NOT(M0) AND button THEN
M0 := TRUE; (*set*)
END_IF; MemTest := M0;
END_PROGRAM

CONFIGURATION Config0
RESOURCE Res0 ON PLC
TASK TaskMain(INTERVAL := T#50ms,PRIORITY := 0);
PROGRAM Inst0 WITH TaskMain : My_Program;
END_RESOURCEEND_CONFIGURATION


And here the ladder diagram
Toggle.jpg 

Can you see the problem ?. Can be fixed the problem at the compiler ??.
By the way, your code work just fine, I never doubt it. But my intrigue was about why my program doesn't work. Like you said, it doesn't compile parallel output lines right.
Reply 0 0
thiagoralves
I sent a message to the Beremiz-dev group with this issue. I'll see if this can be fixed or not.
Reply 0 0
diegohap
Thanks a lot. Hope they can fix it.
Reply 0 0
diegohap
Any news here ?
Reply 0 0
thiagoralves
Sorry, no news yet. I'll let you know when the bug has been fixed
Reply 0 0
diegohap
Any news ??.
Reply 0 0
thiagoralves
Hi Diego, yes I have news. I pushed a fix for this particular issue a few months ago. Sorry for not posting it back in here. There was another user with the same problem and I ended up posting there only. Just reinstall OpenPLC (you don't need to reinstall the editor, only OpenPLC) and you should be good to go.

There is a new module in OpenPLC called ST file Optimization, that looks for those parallel outputs and fix them during the compilation process. Therefore, OpenPLC should be able to handle parallel coils correctly now. Please try it out and report back if you find any inconsistencies.
Reply 0 0
skv
Thiago, could you backport your fix to Beremiz/matiec?
Reply 0 0
thiagoralves
I'll work on that after I finish OpenPLC v3.
Reply 0 0
Reply