{"id":"iec-ctd","model_id":"CTD","name":"CODESYS CTD","summary":"CTD is a standard function block that decrements a counter value. A rising edge on the CD input reduces the current counter value CV by one, and LOAD set to TRUE loads CV with the start value PV. The output Q is TRUE when CV equals zero.","study_notes":["The block must be declared as an instance before use, e.g. CTDInst : CTD;","Results are read from the instance after the call, e.g. VarBOOL3 := CTDInst.Q; and VarWORD2 := CTDInst.CV;","Listed under the Counter group of the Standard library."],"safety_notes":[],"sources":[{"url":"https://infosys.beckhoff.com/content/1033/tcplclib_tc2_standard/74398987.html","title":"Beckhoff Information System","accessed":"2026-10-26"},{"url":"https://content.helpme-codesys.com/en/libs/Standard/Current/Counter/CTD.html","title":"CODESYS Group","accessed":"2026-10-26"}],"verification":{"status":"source_checked","checked_at":"2026-10-26","values":18,"method":"llm_source_check"},"updated_at":"2026-10-26","type":"instruction","spec":{"language":"structured_text","code":"CTD","group":"Counter","syntax":"CTDInst(CD:=VarBOOL1, LOAD:=VarBOOL2, PV:=VarWORD1);","parameters":[{"name":"CD","data_type":"BOOL","description":"Rising edge: decrementing CV by one"},{"name":"LOAD","data_type":"BOOL","description":"TRUE: Set CV to the start value PV"},{"name":"PV","data_type":"WORD","description":"Start value for decrementing"},{"name":"Q","data_type":"BOOL","description":"TRUE if CV = 0"},{"name":"CV","data_type":"WORD","description":"Current counter value"}],"dialect":"CODESYS","related":[],"standards":[]},"url":"https://machineschema.com/instruction/iec-ctd","license":"https://creativecommons.org/licenses/by/4.0/"}