CO1 Counter Add-On
ADwin
26
ADwin-Gold
USB / ENET, manual version 3.8, October 2005
For further processing of the values in the
ADbasic
program, transfer the val-
ues into the latch register and read them out there.
Please pay attention to the fact that the
CNT_SET
instruction depends on the
CNT_MODE
instruction.
If you disable or enable a specified counter, then you also enable the running
counters (= set bits). If you do not set the bits of these counters (unintention-
ally), they will be disabled.
8.2.1 Evaluation of the Counter Contents
The binary counters of the CO1 add-on generate 32-bit values, which are inter-
preted by
ADbasic
as numerical values according to the model of the circle
below: The most significant bit (MSB) is interpreted as a sign, the highest pos-
itive number (2
31
-1) follows the highest negative number (-2
31
) and the lowest
positive number (0) follows the highest negative number (-1).
Circle
Fig. 20 – Circle for the interpretation of counter values
Please pay attention to the following rules for programming:
a) Process the read 32-bit value only with variables of the type
INTEGER
or
LONG
.
ADbasic
then keeps internally the read bit pattern unmodified and
automatically considers the transition from the positive to the negative
range of numbers. Then you get:
Count direction
b) The count direction (up or down) can reliably be derived from the
Sign of the difference
: [
new
counter value]
minus
[
old
counter value]
and not from the comparison of the counter values.
"Overflow"
For programming please remember that an "overflow" between the reading out
of two counts - i.e. the current counter value "laps" the last counter value which
has been read out - is not registered. Such a lap overflow occurs after some
3½ minutes with an input frequency of 20 MHz or after more than 14 minutes
with 5 MHz.
Example programs
You will find several example programs for the
CO1
add-on in the directory
<
C:\ADwin\ADbasic3\samples_ADwin_Gold
> (standard installation).
0000 0000h
FFFF FFFFh
7FFF FFFFh
8000 0000h
4000 0000h
3FFF FFFFh
BFFF FFFFh
C000 0000h
-1,073,741,824
-1,073,741,825
1,073,741,823 1,073,741,824
2,147,483,647
-2,147,483,648
0
-1
inside:
counter value
(binary)
outside:
ADbasic
value