WC32 counter operation

rossw

Active Member
CAI, or anyone who's used the counters on the WC32, can you give me some more specifics on them please?
 
While I can find references in the manual to "COUNTER1", "COUNTER2" and "COUNTER3", there's also a reference to "COUNTER" (no number) which states it will count to a maximum of 2MHz.
 
Does this also apply to COUNTER1-3? If not, what speed can it count to?
 
WC8 also has frequency - that entry has been commented out of the WC32 reference, does that mean no time component in this one?
I see in the setup page for the counters that I can set them to count on rising, falling or both edges. (Does the 2MHz limit apply to the input frequency, or the counting rate? Ie, a 2MHz signal counting on both edges would have a 4MHz counting rate).
 
Which TTL input connects to which counter? (one could assume TTL1 -> Counter1, but that's a dangerous assumption)
I don't see a command to clear the counter - do I assume it's done with   SET COUNTER1 0  ??
Are they full 32-bit counters? Are calculations done on them unsigned or do they flip to negative at 2^31?

Thanks!
 
Hi Ross,
 
WC32 counters are different from WC8 counters.  WC8 counter is a hardware counter, so that it can count up to 2MHz.  WC32 counters are interrupt driven software counters, that means they are much slower than WC8 counters, but it does allow specify the trigger edge. I don't think we stated WC32 can count up to 2MHz, since we did not test that counter speed.  WC8 2MHz counter speed was tested.
 
In WC32 programming guide, for the COUNTER1,3 documented their related TTL input pins.  On the v4.02.13 user guide, they are on page 13.
 
CAI_Support said:
WC32 counters are interrupt driven software counters, that means they are much slower than WC8 counters, but it does allow specify the trigger edge. I don't think we stated WC32 can count up to 2MHz, since we did not test that counter speed.  WC8 2MHz counter speed was tested.
 
OK, That's what I thought - and hence the question about 2MHz (since it was in the guide I had (4.02.02)).
What speed has the WC32 been tested to? What is the minimum pulse-width for reliable (guaranteed) counting?
 
 
CAI_Support said:
In WC32 programming guide, for the COUNTER1,3 documented their related TTL input pins.  On the v4.02.13 user guide, they are on page 13.
 
Thanks, found that guide now and have replaced my old one!
 
Unrelated - can you confirm that WC32 has RAM1-16, but only RAM1-8H and L? (Is there a reason we can't have RAM9-16H and L also?)
 
Suggestion for enhancement - in addition to KEYUP, KEYDOWN etc, how about an "ANYKEY", so we can easily check for any key being pressed and only branch to that code if there is something to do and for debouncing?
 
How about a special reference to in PRINT1/PRINT2 to convert a supplied parameter to a "fixed-point" form, eg
   PRINT1  "Water:" T1%1 "DegC"   -  to take the value of T1, and display "255" as "25.5"  (or a RAM or VAR, the same way)
 
Failing that, a way to construct STR values.
255 can be broken using   (value/10) "." (value%10) but there isn't an easy way that I can see to create anything to make this job easy?
 
Additional thoughts, comments - should I make a new thread for the UM216 and WC32?
 
The userguide says PRINT1 and PRINT2 commands take "one or more" double-quoted strings. It appears it will take from one to three, no more.
There are a few additional things that I've found irritating or restrictive.
Despite the UM216 clearly being able to display lower-case letters (eg, display the value of a temperature input with no sensor connected and it says "invalid"), any text entered as parameters to the PRINT commands is converted to ALL UPPER CASE. It should not.
If a print string is longer than 16 characters, the UM216 will scroll it.... but you cannot enter a string longer than 16 chars on the PRINT lines, except where it is done with the STR variables.
There are no commands to concatenate strings and numbers.
If I wanted to display for example that I added "30Kg wood 47m ago" - I cannot - because I can't see any way to send 2 variables and two strings.
Similarly, to display "Outlet: 75.5C" is impossible. (Which also raises another bug: non-encapsulated spaces are silently dropped).
PRINT1 "Outlet: " T1 "C" (with T1 at 75.5 degrees) would display
 
   OUTLET:755C
 
I can add a space by sending char 128
 
PRINT1 "Outlet:" 128 T1
and I get
 
   OUTLET: 755
 
But I can't then add the "C", and I still can't get the decimal. Closest I can do is
 
  div T1 10 RAM1
  PRINT1 "Outlet:" 128 RAM1
to get
 
  OUTLET: 75
 
It's not very pretty though :(
 
Yes, PLC commands are designed to take up to three "parameters", that is the limit of PLC engine. If takes more, then it will make all other commands waste a lot of spaces. 
 
We will need to see how to avoid convert lower case letter into upper, since PLC engine for easier compiling, always convert everything into upper case first.  We will need to see if we could skip the string elements being converted.  One way to bypass that is to use string table to define your string, then PRINT1 or  2 with STRx
 
I will pass your comments to our developers to see what to do with the space and upper case issue.
 
Possible solution? A couple of new commands, we have
 
PRINT1  and   PRINT2
 
How about ENDPRINT (1 and 2) to print to the end of the current line - basically extending it?
It does raise another question: the UM216 can only accept a maximum of 32 chars per line (and displays 16 at a time, scrolling if need be).
Why then, can the strings be 127 characters long if we can only use 32 at most? Isn't this a waste of space that could be used for other things?
(Like instead of 32 x 127 char strings, we could have 128 * 32-char strings - although why we might need that many eludes me just now!)
 
Hi Ross,
 
String table is not designed for PRINT commands only.  It plans to be used for future functions.
 
CAI_Support said:
WC32 counters are interrupt driven software counters, that means they are much slower than WC8 counters
 
Wayne, will the WC32 count reliably, single-edge (rising or falling, I don't care), *at least* up to 27KHz ?
 
Ross, 
 
We did not test, but WC32 runs on 80MHz clock, it can handle interrupt really fast. Unless it is in the middle of certain action blocked interrupt, it should work a lot of faster than 27KHz
 
CAI_Support said:
Unless it is in the middle of certain action blocked interrupt, it should work a lot of faster than 27KHz
 
OK, so "unless".... what operations does it perform where interrupts are disabled?
If it's particular command(s), I can try to avoid using them.
 
Does each counter have its own ISR? If I have two (or potentially, three) inputs all clocking away at (up to) 27KHz? They would be completely asynchronous and could happen at exactly the same time, or several microseconds apart.
 
On WC32, Ethernet, USB, RS232 communication all disable interrupt in certain section of its processing to ensure proper operation. However, that normally are very brief blocking.
 
Interrupt is not lost, that is stored in the hardware interrupt register, so that once the interrupt block released, it will start process the interrupts one by one. Even you have more than one interrupts happened at the same time, they are processed one by one.
 
Back
Top