Diamond Power Products MM-48-AT User Manual

Page 43

Advertising
background image

Diamond-MM-48-AT User Manual V1.01

Page 43

Reading a counter

a. Latch the counter:

Counter 0

Counter 1

outp(base+15,0x40); outp(base+15,0xC0);

b. Read the data:

The value is returned in 3 bytes, low, middle, and high (2 bytes for counter 1)

Counter 0

Counter 1

low=inp(base+12); low=inp(base+12);
middle=inp(base+13); high=inp(base+13);
high=inp(base+14);

c. Assemble the bytes into the complete counter value:

Counter 0

Counter 1

val = high * 2^16 + middle * 2^8 + low;

val = high * 2^8 + low;

Enabling the counter gate

Counter 0

Counter 1

outp(base+15,0x10); outp(base+15,0x90);

The counter will run only when the gate input is high.

Disabling the counter gate

Counter 0

Counter 1

outp(base+15,0x20); outp(base+15,0xA0);

The counter will run continuously.

Clearing a counter

Clearing a counter is done when you want to restart an operation. Normally you only clear a
counter after you have stopped (disabled) and read the counter. If you clear a counter while it
is still enabled, it will continue to count incoming pulses, so its value may not stay at zero.

a. Stop (disable) the counter:

Counter 0

Counter 1

outp(base+15,0x08); outp(base+15,0x88);

b. Read the data (optional). See “Reading a counter” above.

c. Clear the counter:

Counter 0

Counter 1

outp(base+15,0x01); outp(base+15,0x81);

Advertising