×

Subscribe to newsletter

subscribe to our weekly newsletter to get notified with latest story and article Subscribe now!




PLC BLOG | Counter in panasonic plc
Share on Facebook Share On Twitter Share on LinkedIn Share on Whatsapp


Counter instructions in panasonic plc

counter , used for counting bit. counter count if input is set to 1 or only true logic. counters are used where somthing counts, in this article you will learn about counter up, counter down, counter up/down, counter block.


counter down CTD

counter down count bits by the value 1 is subtracted from the current value CV for each rising edge detected at CD, except when LOAD is set or CV has reached the value zero. when current value CV (CV=0) reach to zero output set to 1. counter down have three input CD, LD and PV and two output Q and CV

  • CD clock generator input, data type, bool. at rising edge of CD value 1 is subtracted from the current value. at rising edge CV = CV-1
  • LD (Load) : data type Bool, if LD is set to 1 or at rising edge,Preset value PV load to current value CV.
  • PV preset value : it is a counter preset value data type INT, Preset value PV is the value subjected to subtraction during the first counting procedure .
  • Q output: bool data type counter output, set when CV = 0.
  • CV current Value: INT data type, Current value contains the current subtraction result (CV = current value).
  • instance type CTD By declaring this FB you create a copy of the original FB. This copy is saved under instance_name (user defined), and a separate data area is reserved.

at first time CV=0, and PV = value set by user or progrmmer, in this example PV = 3,
  • if Start_counter is set to 1 and load_counter_ctd is set to 0 then output is set to 1 and Current value subtracted by 1 with each rising edge.
  • if Start_counter is set to 0 and load_counter_ctd is set to 1 then output is set to 0 and Preset value loaded to Current value . now set load_counter_ctd to 0 and at each rising edge (start_counter =1) of start_counter CV subtracted by 1. when CV equal to zero output_ctd is set to 1. this is a actual working condition of CTD
"if you set Start_counter to 1 and without loading Preset value to current value, CV = 0 by default and at each rising edge subtracted by 1 and output always set to 1."


Up counter CTU

The function block CTU (count up) allows you to program counting procedures. If a rising edge is detected at Input CU, the value 1 will be added to Current value except when RESET is set. this procedure will be repeated until current value CV is greater than/equal to Preset Value PV, Then, signal_output will be set.

  • CU counter Up: input variables data type bool, clock generator at rising edge 1 will be added to current value except when RESET is set
  • R reset input : bool data type, CV is reset to zero for each rising edge at RESET
  • PV PreSet value: data type INT, if PV (preset value) is reached, Q is set
  • Q output: data type bool, is set if CV is greater than/equal to PV
  • CV current value : contains the addition result (CV = current value)
  • instance type CTU

if rising edge at the Start_counter(CU) detected, value 1 will be added to Current Value.for every rising edge detected at Start_counter, this procedure will be repeated until Output_ctu(CV) is greater than/equal to PV value. Then, out_ctu (Q) will be set. If reset is set (status = TRUE), current_value (CV) will be reset.


CTUD, Up/down counter

The function block CTUD (count up/down) allows you to program up and down counter in single blocks. working is same as above for both up and down counting. at same time only one operation possible either up count or down count. in CTUD, Up/down counter block have 5 input and 3 output.
  • Cu Count up data type bool
  • CD count Down data type bool
  • R reset counter data type bool
  • Ld Load Current value by PV, data type bool
  • PV preset value data type int
  • QU output counter up, bool data type
  • QD output counter down, bool data type
  • CV current value, data type INT
  • instance type CTUD

Count down:
If reset is set, the counter_current_value (CV) will be reset. If count_up is set, the value 1 is added to the counter_current_value(CV). This procedure is repeated for each rising edge detected at Count_up until the counter_current_value (CV) is greater than/equal to the Preset value PV. Then out_counter_up is set. The procedure is not conducted, if reset and/or set is/are set.
Count down:
If load_counter is set (status = TRUE), the PV, preset value will be loaded in the counter_current_value (CV). If count_down is set, the value 1 is subtracted at each clock. This procedure is repeated at each clock until the counter_current_value (CV) is smaller than/equal to zero. Then, Out_counter_down is set. The procedure will not be conducted, if reset and/or set is/are set or if CU and CV are set at the same time. In the latter case, counting will be downwards.


CT_FB, Down counter

Counters realized with the CT_FB function block are down counters. Each rising edge detected at Count the value 1 is subtracted from the elapsed value EV. Signal_output is set to TRUE if the elapsed value EV becomes zero. The count area SV (set value) is 1 to 32767.In order to work correctly, the CT_FB function block needs to be reset each time before it is used. The basic CT function (down counter) uses the same NUM* address area (Num* input). In order to avoid errors (address conflicts), the CT function and the CT_FB function block should not be used together in a project.
  • Count : data type bool, for each rising edge detected at Count, the value 1 is subtracted from the elapsed value EV until the value 0 is reached
  • reset : if set reset counter current value reset, data type bool.
  • Set value , set value data type int
  • C : signal output is set when EV becomes 0 data type bool
  • EV elapsed value : current counter value, data type INT
  • instance type CT_FB

Each rising edge detected at Start_counter(count) the value 1 is subtracted from the elapsed value EV. Signal_output is set to TRUE if the elapsed value EV becomes zero. when EV =0 then reset for next counting procedure.


some example of counter

in this example you manually set value for up counter and automatic reset if CV > PV, IN Move block, enter_counter_value and counter_value is int type.


 
Share on Facebook Share On Twitter Share on LinkedIn Share on Whatsapp


Suggested Post


 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

comment