Internet PLC Forum
General => Technical support => Topic started by: Tom 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.
-
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.
-
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.
-
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?
-
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.
-
Hi Gary,
Thank you for the response. I'll let you know how it turns out.
Thank you!
-
Works better than I hoped and ended up making things simpler.
:D
Thanks!!
-
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