B&R automation studio Counter Function Blocks Programming In ANSI C | CTU | CTD | CTUD
Up counter increments counter value by 1. Downward counter decrement counter value by 1. in ANSI C programming you can use Counter as function statement. so first declare Counters function in a programming than you can use their parameter in programming for example if we want to use UP Counter(CTU), first declare counter name instance type in variable table. than call counter in a program . for example CTD(&CTD_0); CTD() is function of UP Counter in c programming and CTD_0 is a instance name.
How To Add Counter in B&R Automation Studio
Counters Are Function Block, To Insert Counters Function Block In Your Project Select Function Block From Instructions Menu then Select External Library, and select any counter from menu and add to your project.
How to Declare Counter Parameter in B&R Automation Studio
All Counters Functions Block Have Instance type, and have some parameter which define on variable table. below is a variable table for Upward counter (CTU).Instance type is important for function block. Declaration Of Instance Name May Be Local Or Global, open any variable table where you want to declare counter, then right click and select add variable then first enter name of counter then in a type click to browse button and then select function block from category and select counter, or you can directly enter Instance type. Upward counter Instance type is CTU, for Downward counter Instance type is CTD and for Upward/Downward counter Instance type is CTUD. in a below image all three counter define with instance name.
B&R Automation Studio Downward counter CTD Counter Instruction In ANSI C
Downward counter decrements counter value by 1 every time its input goes from false to true (positive edge). initially counter value is zero if the load is set than preset value transfer into counter value. counter output is set to true when counter value is equal to zero. if counter value is zero in a downward counter and counter down(CD) is change from false to true than no decrement in counter value. following is the parameter for downward counter
Input Parameter
.CD counter input bit when this bit changes from false to true (rising edge) counter value decrement by 1. data type is bool
.LOAD if load bit is set to true then preset value(PV) move to Counter value (CV).data type bool
.PV preset value or counter start value, data type is UINT.
Output Parameter
.Q output of counter it set to true if the counter value equals to zero.
.CV it is counter value, rising edge of CD counter value decrement by 1. data type is UINT
in this example CTD_in is counter input if tha CTD_in. rising edge of CTD_in decrement counter value by 1. CTD_load is bool data type if CTD_load is set to true than CTD_PV value move to counter value. CTD_pv is counter preset value.
B&R Automation Studio Upward counter (CTU) Instruction In ANSI C
Upward counter or up counter(CTU) is increments counter value by 1 every time it's input changes from false to true. if the counter value(CV) reaches to preset value(PV) and if counter up bit changes from false to true counter value continue increments upto 32766 and counter output is true. If the reset bit set to true than counter value initialized to zero and counter output is false.
Input Parameter
CU counter input bit, when this bit changes from false to true (rising edge) counter value increments by 1. data type is bool
Reset reset counter value(CV) to zero
PV preset value or counter start value, data type is UINT.
Output Parameter
Q output of counter it set to true if the counter value equals to greater then preset value(PV).
CV it is counter value, rising edge of CU counter value increments by 1. data type is UINT
B&R Automation Studio Upward or Downward counter (CTUD) Instruction In ANSI C
Upward or Downward counter (CTUD) Instruction work either as upward counter or downward counter, selection of counter operation is depend on counter selection input bit. if the counter down(CD) bit set to true then CTUD work as downward counter if the counter UP bit set to true (CU) then counter work as upward counter. Following is parameter of Upward or Downward counter (CTUD)
Input Parameter
CU counter UP input bit, when this bit changes from false to true (rising edge) counter value increments by 1. data type is bool
CD counter down input bit when this bit changes from false to true (rising edge) counter value decrement by 1. data type is bool
Reset reset counter value(CV) to zero
LOAD if load bit is set to true then preset value(PV) move to Counter value (CV).data type bool
PV preset value or counter start value, data type is UINT.
Output Parameter
QU counter up output of counter it set to true if the counter value equals to greater then preset value(PV).
QD counter down output of counter it set to true if the counter value equals to zero.
CV it is counter value, rising edge of CU counter value increments or decrement by 1. data type is UINT