aboutsummaryrefslogtreecommitdiffstats
path: root/src/hal/components/tof.comp
blob: 9e517fe700df7c7d9fb40c6df133ecd9ab5c0a81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/********************************************************************
* Description: tof.comp
*   IEC_61131-3 Time Off timer for HAL bit signals.
*
*   This is a HAL component that can be used to delay falling edge signals
*   for a certain amount of time.
*
*********************************************************************
*
* Author: Chad Woitas (aka satiowadahc)
* License: GPL Version 2
* Created on: 2021/06/10
* System: Linux
*
* Copyright (c) 2021 All rights reserved.
*
* Last change: 2021-11-02 - Conversion to comp format
*
********************************************************************/
component tof "IEC TOF timer - delay falling edge on a signal";
pin in bit in "Input signal";
pin out bit q "Output signal";
pin out float et "Elapsed time since falling edge in seconds";

param rw float pt "Delay time in seconds";

function _ fp "Update the timer";
license "GPL";
author "Chad Woitas";
;;
FUNCTION(_) {
        if(pt < 0) {
            pt = 0;
            rtapi_print_msg(RTAPI_MSG_WARN,
                            "tof: Delay time must be positive, resetting to 0");
        }
        if(et < 0) {
            et = 0;
            rtapi_print_msg(RTAPI_MSG_WARN,
                            "tof: Elapsed time rolled over, resetting to 0");
        }

        // Check timers
        if(in){
            // Reset Variables
            q = 1;
            et = 0;
        }
        else{
            // Update outputs
            if(et >= pt){
                q = 0;
            }
            else{
                et += fperiod;
            }
        }
}
bues.ch cgit interface