/******************************************************************** * 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; } } }