mr_sack
I think the falling edge input modifier and F_TRIG function block not working correctly.

Here is my program with my own falling edge detection for comparison to show what I mean:

Anmerkung 2019-06-24 163740.png 

Following the IEC standard the output should not be true after  I started the simulation (and also in runtime).

Quote:
The R_TRIG and F_TRIG function blocks defined in 2.5.2.3.2 of IEC 61131-3 exhibit differentbehaviour following “cold restart” as described in 2.4.2 of that document. The Q output of anR_TRIG instance can be set to 1 on the first invocation but the Q output of an F_TRIG instancealways requires at least two invocations before being set to 1. This behaviour can be explainedas follows.–Since the default value of Boolean variables is 0, then if the CLK input is 1 on the firstinvocation, it means that the input has changed its value from 0 to 1 i.e. a rising edge hasbeen detected and thus the Q of an R_TRIG instance is set to 1.–In the case of an F_TRIG instance, the CLK input must first be detected as being a 1 beforea change of state from 1 to 0 can be detected. Thus, at least two invocations are needed.
Reply 0 0
thiagoralves
You are right. I'll take a look at this block and figure out what is wrong
Reply 0 0
yukia10
This simple example also does not seem to work. M0 becomes true when executed.
FE.png 
Reply 0 0
NaN
In the file Standard_Function_Blocks.xml, the code for F_TRIG is:
<ST>
  <xhtml:p><![CDATA[Q := NOT CLK AND NOT M;
    M := NOT CLK;]]></xhtml:p>
</ST>

It should be:
<ST>
  <xhtml:p><![CDATA[Q := M AND NOT CLK;
    M := CLK;]]></xhtml:p>
</ST>
Reply 0 0
thiagoralves
This change should to go MatIEC, not the Editor. This xml on the editor is just for reference. MatIEC uses its own library to generate the binary file in the end. You can check here for a reference on how to update the editor and MatIEC library: https://openplc.discussion.community/post/how-to-add-my-fbd-to-default-pouslibrary-10408620?pid=1310581219&highlight=add+custom+blocks
Reply 0 0
yukia10
Thank you, thiagoralves and NaN. I did the homework.

In editor/plcopen/Standard_Function_Blocks.xml:
<ST>
<xhtml:p><![CDATA[Q := M AND NOT CLK;
M := CLK;]]></xhtml:p>
</ST>

In matiec/lib/edge_detection.txt:
FUNCTION_BLOCK F_TRIG
VAR_INPUT CLK: BOOL; END_VAR
VAR_OUTPUT Q: BOOL; END_VAR
VAR RETAIN M: BOOL; END_VAR
Q := M AND NOT CLK;
M := CLK;
END_FUNCTION_BLOCK

In matiec/lib/C/iec_std.h:
// Code part
static void F_TRIG_body__(F_TRIG *data__) {
// Control execution
if (!__GET_VAR(data__->EN)) {
__SET_VAR(data__->,ENO,,__BOOL_LITERAL(FALSE));
return;
}
else {
__SET_VAR(data__->,ENO,,__BOOL_LITERAL(TRUE));
}
// Initialise TEMP variables

__SET_VAR(data__->,Q,,((__GET_VAR(data__->M,)) && !(__GET_VAR(data__->CLK,))));
__SET_VAR(data__->,M,,(__GET_VAR(data__->CLK,)));

goto __end;

__end:
return;
} // F_TRIG_body__()

It seems to work fine.
FE.png 
Thank you so much for your help.
Reply 0 0
thiagoralves

Nice work @yukia10! Would you mind pushing your changes to GitHub? Then other users will benefit from your fix too. Keep in mind that the MatIEC changes will have to be pushed to both OpenPLC Editor and OpenPLC_v3 (runtime).

Links:
https://github.com/thiagoralves/OpenPLC_v3

https://github.com/thiagoralves/OpenPLC_Editor

Reply 0 0
schlumpf
Should this be reported to upstream MatIEC at https://bitbucket.org/automforge/matiec_git, too?
Reply 0 0
yukia10
Thank you for your advice. I created an issue on the upstream.
Reply 0 0
thiagoralves
schlumpf wrote:
Should this be reported to upstream MatIEC at https://bitbucket.org/automforge/matiec_git, too?

Might be worth reporting if they haven't fixed it on their particular branch
Reply 0 0
Reply