x3828643
I try to make a Input(%IX0.5) and TOF timer and then output to a output coil(%QX0.2) and compile by MatIEC.

The compile it was succeed ,but the working's result is not correct.

Why? 

I use "and_logic" of this example: https://github.com/Felipeasg/matiec_examples

111.png  222.png  444.jpg  555.jpg 
Reply 0 0
thiagoralves
This is the correct behavior. The TON timer will keep the output off, unless the input is true for more than time PT. In your example, you must keep %IX0.5 true for more than 1000ms to see %QX0.2 going to true.
Reply 0 0
x3828643
I try to keep %IX0.6 true for more than 10000ms.but, when I keep %IX0.6 true
not yet over 10000ms %QX0.3 already true.

Why? 32.jpg  123.png  12.png 
Reply 0 0
thiagoralves
Have you tried to run your program on OpenPLC? I’ve run a bunch of TON and TOF tests with OpenPLC and they all ran fine. Your question is about a modified MatIEC example, so I don’t know if we can help you much.
Reply 0 0
x3828643
Yes, I try to use my program's st file working on Raspberry Pi and use "OpenPLC Server" to comple st file. It is Working well.

but, I want to use "MatIEC" to compile my program and get ANSI-C code.   

Where can find to conform MatIEC tools of OpenPLC Editor ?

I currently use this version:  https://bitbucket.org/mjsousa/matiec

13.jpg 

Reply 0 0
x3828643
I currently use this version  have many problems.
I currently using TON TOF TP on Linux ubuntu can not be used.
but ,But I use other functions are normal.

Reply 0 0
thiagoralves
OpenPLC uses an earlier version of MatIEC. The one you’re using is probably the most recent one directly from their repository. I know they have made many changes to MatIEC since I got an working version for OpenPLC, but I don’t know exactly what was changed.

Maybe the problem is not with MatIEC, but with the auxiliary files you created to generate a binary application. Anyway, you will probably get better help if you ask your question directly to the MatIEC development group (Beremiz):  https://sourceforge.net/p/beremiz/mailman/
Reply 0 0
x3828643
I agree with your opinion, because I tried iec2c of OpenPLC_v2 to make these ANSI-C code.
The compile it was succeed ,but Produce the same error the working's result is not correct.

so I think the problem lies in this the auxiliary files.

I want to created a main.c file with MatIEC's ANSI-C file to generate a binary application.

Is there any examples can refer to it? 
 
Reply 0 0
skv
x3828643 wrote:
I want to created a main.c file with MatIEC's ANSI-C file to generate a binary application.
Is there any examples can refer to it?

This is actually pretty easy.
On Beremiz mailing list there was discussion about porting Beremz to AVR and examples posted
there may be useful to get idea how matiec work and how it can be used in in a standalone application
Here is direct link to the post with simplest runtime for AVR 8-bit microcontroller.

I wanted to attach C and Makefile for similar simple runtime for GNU/Linux system, but this forum doesn't allow these types for some reason.


extern void __run(void);
extern int __init(int argc,char **argv);
extern void __cleanup(void);
#include <time.h>
#include <math.h>
#include <stdint.h>
#include <unistd.h>
#include "iec_types.h"
#include "iec_std_lib.h"
extern TIME __CURRENT_TIME;
extern unsigned long __tick;
TIME __PLC_PRG_TIME;

void PLC_GetTime(IEC_TIME *CURRENT_TIME)
{
    struct timespec tmp;
    clock_gettime(CLOCK_REALTIME, &tmp);
    CURRENT_TIME->tv_sec = tmp.tv_sec;
    CURRENT_TIME->tv_nsec = tmp.tv_nsec;
}
int main(int argc,char **argv)
{
  __init(argc,argv);
  for(;;) {
    PLC_GetTime(&__CURRENT_TIME);    
    __run();
    TIME now;
    PLC_GetTime(&now);
    __PLC_PRG_TIME = __time_sub(now, __CURRENT_TIME);
    STRING s = __time_to_string(__PLC_PRG_TIME);
    printf("%s\n", s.body);
    sleep(1);
    #ifdef PROFILE_PROGRAM_TICKS
    if (__tick > PROFILE_PROGRAM_TICKS)
      break;
    #endif
  }
  __cleanup();
  return 0;
}


PLC cycle is this example fixed and is not taken from the project in PLCOpenEditor, but this is enough to get the idea.
Beremiz does have proper handling for PLC cycle on GNU/Linux targets of course.
So you may be interested in looking into that.
Most of the code is needed for Debug and Logging, so you don't need it.


# Hey Emacs, this is a -*- makefile -*-
BEREMIZ_OBJS = $(BEREMIZSRC:.c=.o)
CC=gcc
CFLAGS+= -O2
CFLAGS+= -flto
CFLAGS+=-DTARGET_DEBUG_DISABLE
CFLAGS+=-DTARGET_LOGGING_DISABLE
CFLAGS+=-DTARGET_EXT_SYNC_DISABLE
CFLAGS+=-DTARGET_RETAIN_DISABLE
CFLAGS+=-DPROFILE_PROGRAM_TICKS=5
CFLAGS+=-I../project_files
CFLAGS+=-I../../../matiec/lib/C
CFLAGS+= -g

LDFLAGS=

debug:
  $(CC) $(CFLAGS) -E  resource1.c > resource1.C
all:
  @echo "*** all done ***"
  $(CC) $(CFLAGS) $(BEREMIZSRC) ../project_files/main.c -o PLC_PRG $(LDFLAGS)



Anyway because your questions are not related to OpenPLC it's may be better to ask on Beremiz mailing list.


Reply 0 0
thiagoralves
skv, that’s a good example. You can add project files (C source + makefile) if you just compress everything on a zip file. The forum accepts .zip compressed files.
Reply 0 0
Reply