22.3 Command Sequences

Diamond Systems provides free Universal Driver software to control the counter/timers on Helios. The information in this section is intended as a guide for programmers writing their own code, instead of using the driver, and to give a better understanding of the counter/timer operation.

The counter/timer registers are located at page 0, base+1 through base+15. Be sure to select the correct page by writing to the PG1-0 bits in base+1.

Load and Enable a Counter

9. Write the data to the counter.

For counter 0, three bytes are required to load a 24-bit value. For counter 1, two bytes are needed for a 16-bit value. The value is an unsigned integer. Break the load value into 3 bytes: low, middle, and high, (Two bytes for Counter 1) and write the bytes to the data registers in any sequence.

Counter 0

Counter 1

outp(base+12,low);

outp(base+12,low);

outp(base+13,middle);

outp(base+13,high);

outp(base+14,high);

10. Load the counter

outp(base+15,0x02); outp(base+15,0x82);

11. Enable the counter gate if desired.

The gating may be enabled or disabled at any time. When gating is disabled, the counter counts all incoming edges. When gating is enabled, if the gate is high the counter counts all incoming edges and, if the gate is low, the counter ignores incoming clock edges.

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

12. Enable the counter.

A counter may be enabled or disabled at any time. If disabled, the counter ignores incoming clock edges.

outp(base+15,0x04); outp(base+15,0x84);

Read a Counter

1. Latch the counter.

Counter 0

Counter 1

outp(base+15,0x40);

outp(base+15,0xC0);

2. Read the data.

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

low=inp(base+12); low=inp(base+12);

middle=inp(base+13); high=inp(base+13);

high=inp(base+14);

3. Assemble the bytes into the complete counter value.

val = high65536 + middle256 + low; val = high * 256 + low;

Disable the Counter Gate

Disabling the counter gate, as shown below, causes the counter to run continuously.

Counter 0:

Counter 1:

outp(base+15,0x20);

outp(base+15,0xA0);

Clear a Counter

Clear a counter to restart an operation. Normally, a counter is only cleared after stopping (disabling) and reading the counter. If you clear a counter while it is enabled, it continues to count incoming pulses so the counter value may not remain at zero.

1.Stop (disable) the counter.

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

2. Read the data (optional)

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

low=inp(base+12); low=inp(base+12);

middle=inp(base+13); high=inp(base+13);

high=inp(base+14);

3. Clear the counter.

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

Last updated