beautypg.com

Reading accumulated counts, Writing to counters, Rollovers – Sensoray 425 User Manual

Page 10

background image

Sensoray Model 425 Instruction Manual

Page 8

Counter Data Format

Although the counters are physically organized as
24-bits wide, counter data are represented in a 32-bit
two’s-complement format.

When reading a counter, the most-significant byte of
the returned 32-bit value is generated by sign-
extending the most-significant bit of the physical 24-
bit counter.

When writing to a counter, the most-significant byte
of the specified 32-bit value is ignored and the least-
significant 24-bits are loaded into the physical
counter. Note that the most-significant bit of the 24-
bit value is treated as a sign bit.

Reading Accumulated Counts

Because of the asynchronous relationship between
counters and the ISAbus, counters may not be
directly read by the host. Instead, counters must first
be synchronously copied to the Holding register,
which in turn may be asynchronously read by the
host.

To copy a counter to the Holding register, issue a
Latch command by writing the following value to the
Counter control port:

After executing the Latch command, counter data
may be read from the two-word Holding register:

The low and high words may be read from the
Holding register in any order. Data are held in the
Holding register until the next Latch command.

Note: it is not required for the host to read either or
both words from the Holding Register after issuing a
Latch command. Consequently, in applications that
require only 16-bit data, it is permissible to read only
the low word from the Holding Register.

Writing to Counters

Counters may be preloaded with any 24-bit value. In
order to preload a counter, the desired data value
must first be written to the Preload Register, then
synchronously transferred to the target counter.

To preload a counter, first write the desired data
value to the Preload Register:

Next, synchronously transfer the Preload register to
the target counter by writing a Load Counts
command to the Counter control port:

After executing the Load Counts command, the
designated counter will begin counting from the
value contained in the Preload Register.

Note: the Preload Register changes only when
written to by the host. If your application uses a
constant preload value, the Preload Register need be
loaded only one time.

Rollovers

Encoder counters physically increment from FFFFFF
to 000000 when counting up, and decrement from
000000 to FFFFFF when counting down. These state
transitions are called “rollovers.”

Counter Control Port (base + 16, write only) : Latch Counts

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

0

0

0

0

0

0

0

0

0

1

0

A1

A0

0

0

0

0

A

1

and A

0

specify which counter

is to be transferred to the holding
register:

A

1

A

0

Encoder

00

Channel 0

01

Channel 1

10

Channel 2

11

Not Valid

Holding Register Low Word (base + 18, read only)

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

0

D15 D14 D13 D12 D11 D10

D9

D8

D7

D6

D5

D4

D3

D2

D1

D0

Holding Register High Word (base + 20, read only)

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

0

D23 D23 D23 D23 D23 D23 D23 D23 D23 D22 D21 D20 D19 D18 D17 D16

Preload Register Low Word (base +18, write only)

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

0

D15 D14 D13 D12 D11 D10

D9

D8

D7

D6

D5

D4

D3

D2

D1

D0

Preload Register High Word (base + 20, write only)

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

0

x

x

x

x

x

x

x

x

D23 D22 D21 D20 D19 D18 D17 D16

Counter Control Port (base + 16, write only) : Load Counts

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

0

0

0

0

0

0

0

0

0

0

1

A1

A0

0

0

0

0

A

1

and A

0

specify which counter

will receive a copy of the Preload
Register:

A

1

A

0

Encoder

00

Channel 0

01

Channel 1

10

Channel 2

11

Not Valid