Giter Club home page Giter Club logo

twincat-retentive-timers's Introduction

TwinCAT-Retentive-Timers

Standard library timers on TwinCAT count time by taking the difference between the current time from system timer and start time from system timer. While this is fine for most application, it is problematic for operations that require time to be retained even if the PLC is paused, stopped or turned off. For example, if a TON (Timer On-Delay) Timer is running and you stop the PLC Boot Project for a period of time, the TON will not resume from the point it was stopped. Instead it will skip time by the number of ms/secs/mins/hours it was stopped. This makes it useless for applications such as tracking the length of time a PLC has been running or retaining persistent time.

Retentive variants of the Standard library timers stop this from happen. They are based on PLC Task cycle time rather than system time. This means they will simply stop counting when the PLC Task Cycle is stopped and will resume from where they left-off as soon as the task cycle picks up. All arguments behave in the same manner as those of the standard library.

To see an example of the differences between Retentive Standard Library Timers and Normal Standard Library Timer, download this project, run it and follow the instructions in P_Example_1_TONs()

This project creates retentive variants of the standard library PLC timers:

  • TON - Timer On-Delay
  • TOF - Timer Off-Delay
  • TP - Pulse Timer

In this project the following will be implementated:

  • ๐Ÿ‘ FB_RTON - Retentive Timer On-Delay
  • ๐Ÿ‘ FB_RTOF - Retentive Timer Off-Delay
  • ๐Ÿ‘ FB_RTP - Retentive Pulse Timer
  • ๐Ÿ‘ FB_Timer - Pausable Timer
  • ๐Ÿ‘ FB_RTimer - Retentive Pausable Timer
  • ๐Ÿ‘ FB_Stopwatch - Normal Stopwatch
  • ๐Ÿ‘ FB_RStopwatch - Retentive Stopwatch

FB_RTON

Declaration:

(* <name of timer> : FB_RTON *)

// Declaring a Retentive Timer On-Delay
fbRTON : FB_RTON;

Implimentation

fbRTON(IN := bStart, PT := tSet_Time, Q => bElapsed_Time, ET => tElapsed_Time)

FB_RTOF

Declaration:

(* <name of timer> : FB_RTOF *)

// Declaring a Retentive Timer Off-Delay
fbRTOF : FB_RTOF;

Implimentation

fbTOF(IN := bStart, PT := tSet_Time, Q => bElapsed_Time_TOF, ET => tElapsed_Time_TOF)

FB_RTP

Declaration:

(* <name of timer> : FB_RTP *)

// Declaring a Retentive Pulse Timer
fbRTP : FB_RTP;

Implimentation

fbRTP(IN := bStart, PT := tSet_Time, Q => bElapsed_Time_RTP, ET => tElapsed_Time_RTP);

FB_Timer

Declaration:

(* <name of timer> : FB_Timer *)

// Declaring a Pausable Timer
fbTimer : FB_Timer;

Implimentation

fbTimer(bStart := bStart, bPause := bPause, tSet := tSet_Time, bElapsed => bElapsed_Time, tElapsed => tElapsed_Time);

FB_RTimer

Declaration:

(* <name of timer> : FB_RTimer *)

// Declaring a Retentive Pausable Timer
fbRTimer : FB_RTimer;

Implimentation

fbRTimer(bStart := bStart, bPause := bPause, tSet := tSet_Time, bElapsed => bElapsed_RTime, tElapsed => tElapsed_RTime);

FB_Stopwatch

Declaration:

(* <name of timer> : FB_Stopwatch *)

// Declaring a Stopwatch
fbStopwatch : FB_Stopwatch;

Implimentation

fbStopwatch(bStart := bStart, tElapsed => tElapsed_Time);

FB_RStopwatch

Declaration:

(* <name of timer> : FB_RStopwatch *)

// Declaring a Stopwatch
fbRStopwatch : FB_RStopwatch;

Implimentation

fbRStopwatch(bStart := bStart, tElapsed => tElapsed_Time);

twincat-retentive-timers's People

Contributors

fisothemes avatar runtimevic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

twincat-retentive-timers's Issues

create library and refactor code and change it to OOP...

Hello @fisothemes,
congratulations for spreading your work, I think it is the right way to improve.
I liked your idea implementing timers...
Would you like me to create a single FB that groups them all..., refactoring the code and passing it to the OOP paradigm and also create a timer library...
Tell me if you are interested and we can do it collaborating or I do it and see if you like it...
I wait your answer...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.