How to do a task every 10 minuts?

k2teknik
2014-11-18
2015-01-28
  • k2teknik - 2014-11-18

    I am new to this so my question may be to dumb, but I am lost and need some help.
    Every 10 minute I would like my program to do a calculation, no problem to do the calculation, but ho to trig it every 10 minutes?
    I was trying to use RTC in my LD, no luck, then I tried the TP but everything is just a oneshot, no repeting at all.

    BTW
    Where to find code snips in different CoDeSys languages, just small simple things?

     
  • Anonymous - 2014-11-20

    Originally created by: scott_cunningham

    If your hardware supports multi-tasking, you can define a task that runs every 10 minutes in the task manager. But I think you really want to know how to do it within the code...

    If you can live with a slight accumulation error, this solution works nicely and is simple. The timer below expires (Q goes true), disables itself on the next PLC scan (Q goes false) and then starts again on the next PLC scan. So if you start your system at 12:00, after some days, weeks or months, it will not occur at 12:00, but at some slightly later time.

    If you use ST language, it looks like this:

    VAR
    Β  Β Delay : TON;
    END_VAR
    Delay(IN:= NOT(Delay.Q), PT:= T#10m);
    If Delay.Q THEN
    Β  Β YourJob();
    END_IF
    

    In LD:

    IMPORTANT: YourJob is only called every 10 minutes in this example.

    If you really want your system to always trigger on the 10's (12:00, 12:10, 12:20 etc), then you will need to make a better solution using the RTC.

    Regarding sample code, search the internet for "user manual for plc programming with codesys 2.3". This has some basic examples. Additionally, you can goto http://www.oscat.de (in German) and download the OSCAT Basic library. You get then some "helper" function blocks and can see the code behind.

    IMG: timer.png

     
  • shooter - 2014-11-22

    go to resources, then tasks,
    make a new task running every 10 minutes. (this is done from internal clockpuls.)
    when you do this you must enter PLC_PRG also as a task freerunning because PLC_PRG is default and starts when no tasks are defined.

     
  • k2teknik - 2014-11-22

    scott_cunningham hat geschrieben:
    If your hardware supports multi-tasking, you can define a task that runs every 10 minutes in the task manager.
    My HW do, and thanks to shooter I manage to make something that works in that way too..

    Zitat:
    But I think you really want to know how to do it within the code...
    "You are right..
    Zitat:
    If you use ST language, it looks like this:

    VAR
    Β  Β Delay : TON;
    END_VAR
    Delay(IN:= NOT(Delay.Q), PT:= T#10m);
    If Delay.Q THEN
    Β  Β YourJob();
    END_IF
    

    In LD:
    IMPORTANT: YourJob is only called every 10 minutes in this example.
    If you really want your system to always trigger on the 10's (12:00, 12:10, 12:20 etc), then you will need to make a better solution using the RTC.

    Thanks.

    Zitat:
    Regarding sample code, search the internet for "user manual for plc programming with codesys 2.3".
    I manage to find some pdf's, they looks a bit like the help in CoDeSys?

     
  • k2teknik - 2014-11-22

    shooter hat geschrieben:
    go to resources, then tasks,
    make a new task running every 10 minutes. (this is done from internal clockpuls.)
    when you do this you must enter PLC_PRG also as a task freerunning because PLC_PRG is default and starts when no tasks are defined.
    Thanks, I manage to make this work, just had to play some with the freerunning of the PLC_PRG first.

     
  • shooter - 2015-01-28

    a free runner means this task is done whenever nothing else is running (and it has some work with priorities)

    when you do it with a timer it is not precise as the timer is reset every 10 minutes and that takes time.

    another way is to use the now() internal clock.

     

Log in to post a comment.