Author Topic: Continuous counting display  (Read 11748 times)

TTCSR

  • Newbie
  • Posts: 30
  • I'm a llama!
    • View Profile
Continuous counting display
« on: March 19, 2014, 07:19:29 AM »
I am setting up a test rig to cycle a switch and want to display it's number of cycles in the millions, however, the values I display are limited.  Is there anyway to display numbers in the millions or greater?

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Continuous counting display
« Reply #1 on: March 19, 2014, 09:58:05 AM »
TBASIC integer variables, A..Z are 32-bit signed values and they can represent values from -2,147,483,648 to 2,147,483,647. This is probably enough millions.

The ladder logic COUNTERS are limited to values between 0 and 9999.  You can chain multiple COUNTERs together to count to much larger values.

This example uses 3 COUNTERs that each count from 0..999 and as result count from 0..999,999,999.

There are 2 custom functions:
    [*]ResetCntrChain

    '  ResetCntrChain - Initialze COUNTERs and their associated contacts
    '
    '  The Present Value (PV) is set to 0 for all counters.  The default (reset) PV of
    '  a COUNTER is -1.  By seting the initial state of the counter to "0" this makes the
    '  value for each follow this sequence:
    '
    '    0,1,2,3..999,0,1,2,3...
    '
    '   The ClrIO statements reset the contact associated with each COUNTER.
    '
    CtrPV[Cntr_0] = 0 : ClrIO Cntr_0
    CtrPV[Cntr_1] = 0 : ClrIO Cntr_1
    CtrPV[Cntr_2] = 0 : ClrIO Cntr_2
    [/tt]
    [*]DisplayCnt

    ' DisplayCnt - Custom function to display current accumulated count on LCD
    '

    ' Build 32-bit integer from the PV (present value) of the chain of 3 COUNTERs
    '
    I = CtrPV[Cntr_2]
    I = I * 1000
    I = I + CtrPV[Cntr_1]
    I = I * 1000
    I = I + CtrPV[Cntr_0]

    ' Display count on LCD
    '
    SetLCD 1,1, STR$(I,9)
    [/tt]
    [/list]

    Gary D.
    « Last Edit: March 19, 2014, 10:01:22 AM by garysdickinson »

    TTCSR

    • Newbie
    • Posts: 30
    • I'm a llama!
      • View Profile
    Re:Continuous counting display
    « Reply #2 on: March 20, 2014, 04:13:46 AM »
    That's just AWESOME  ;D
    Worked perfectly and I am monitoring 8 seperate signals that go up to 999,999,999 each.
    Thank you very much!