Author Topic: Actual [UpCtr] Counter value  (Read 15108 times)

Tom

  • Newbie
  • Posts: 2
  • I'm a llama!
    • View Profile
Actual [UpCtr] Counter value
« on: February 18, 2009, 02:52:20 PM »
Hi,
Is it possible to display actual counter values on LCD display e.g. values for shift production counts etc.
I have the counter set value displayed but would like to show the actual [UpCtr] value.
Any help would be appreciated.

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Actual [UpCtr] Counter value
« Reply #1 on: February 18, 2009, 03:35:22 PM »
The preset value of a counter can be accessed in TBASIC.  The counters appear as an array of integers named ctrPV[n] (where "n" is the counter number 1..256).

If you wanted to display the value of counter #1 on the LCD you could do something like this:
 
SETLCD 1,1, STR$(ctrPV[1])

If you wanted to test if the current value of counter #21 is equal to 5:

IF ctrPV[21] = 5
    ' do something here with this knowledge
    '
ENDIF

If you wanted to force the current value of counter #2 to the value 11:

ctrPV[2] = 11

Have fun.

Tom

  • Newbie
  • Posts: 2
  • I'm a llama!
    • View Profile
Re:Actual [UpCtr] Counter value
« Reply #2 on: February 18, 2009, 04:00:08 PM »
Thanks for the prompt reply,
Since i posted my question i found a solution to the problem in the Programmers reference manual (p5-15).
it says;
X = X+1     '   Initial value of X = 0
SETLCD 1,1,"Cycle Count = "+STR$(X)

Your solution now gives me more options  
Thanks again.

ohioan1

  • Newbie
  • Posts: 4
  • I'm a llama!
    • View Profile
Re:Actual [UpCtr] Counter value
« Reply #3 on: March 05, 2012, 11:24:31 AM »
This works perfectly!

X = X+1    '  Initial value of X = 0
SETLCD 1,1,"Cycle Count = "+STR$(X)


I do have one question. How would I clear the counter to zero when another input is activated?



garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Actual [UpCtr] Counter value
« Reply #4 on: March 05, 2012, 03:31:37 PM »
I'd suggest that you call a Custom function to load a value of 0 into a COUNTER.  

You will find that the Function [RSCtr], Reset Counter will set the counter to a special value of "-1" and the contact that is associated with the counter.

I assume that you are not using the contact that is associated with the counter and are only interested in the Present Value of the counter.

In the following ladder logic code there are two special functions, ZeroCnt and DispCnt.  

Custom Function named "ZeroCnt":

ctrPV[1] = 0

Custom Function named "DispCnt:

SETLCD 1,1,STR$(ctrPV[1])+"          "


Good luck,

Gary D.


ohioan1

  • Newbie
  • Posts: 4
  • I'm a llama!
    • View Profile
Re:Actual [UpCtr] Counter value
« Reply #5 on: March 06, 2012, 03:01:08 AM »
Hi Gary,

Thank you for the response.  I'll let you know how it turns out.  

Thank you!



ohioan1

  • Newbie
  • Posts: 4
  • I'm a llama!
    • View Profile
Re:Actual [UpCtr] Counter value
« Reply #6 on: March 06, 2012, 04:48:54 AM »
Works better than I hoped and ended up making things simpler.  

 :D


Thanks!!

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Actual [UpCtr] Counter value
« Reply #7 on: March 06, 2012, 11:11:59 AM »
Glad to help.

Please remember that the use of the ladder logic COUNTERS do come with some limitations:
  • The COUNTER resets to an special value of "-1".  This happens as a result of PLC reset, PLC power up and the use of the [RSCtr] Special function.
  • The maximum value that the counter can reach is determined by the Set Value in the I/O table.
  • The maximum Set Value is 9999 decimal.
  • The COUNTER will down count from 0 to the Set Value.  There are no negative numbers other than the special "-1" value.
  • The contact associated with the COUNTER has some interesting behaviors in regards to when the contact is active.
You may find that using custom functions to increment, decrement and reset a simple variable may give you more flexibility than using one of the ladder logic counters.

Gary D
« Last Edit: March 06, 2012, 11:25:39 AM by garysdickinson »