Scorpio News |
April–June 1987 – Volume 1. Issue 2. |
| Page 11 of 51 |
|---|
| D4 = 1 – | In timer mode, positive edge starts timer. In counter mode, positive edge decrements counter. |
| D4 = 0 – | In timer mode, negative edge starts timer. In counter mode, negative edge decrements counter. |
| D3 = 1 – | is defined in timer mode only. Timer starts immediately (well, almost) |
| D3 = 0 – | defined in timer mode only. Timer starts after time constant has been
loaded. |
| D2 = 1 – | Time constant word is next word to be written to this channel. |
| D2 = 0 – | No tine constant will follow (use the existing one) |
| D1 = 1 – | Reset channel. Channel stops counting or timing. |
| D1 = 0 – | Continue current operation. |
| D0 – | Always 1 for control byte. |
To disable a CTC channel from causing an interrupt, the code is simple. Just write a 01H to the appropriate channel. Like the other Z80 chips, it is necessary to disable the system interrupts in case an interrupt occurs while the disable instruction is being assimilated by the I/O chip. The code is only slightly more complex than above:
LD A, 01h DI ; Disable CPU interrupts OUT (CTCn),A ; Disable CTC channel EI ; re-enable CPU interrupts
A channel may not begin operations in any mode unless a valid time constant byte has been written into the Time Constant Register. This byte is expected on the next write to the channel in question following the write of the channel control byte, provided the channel control byte had bit 2 set (= 1). If this time constant byte is 0 it is interpreted as 256. If a new time constant byte written to a channel already in operation, the new time constant byte is only reloaded at the next count down to zero.
The major difference between Counter mode and Timer mode is that Counter mode
uses the external clock or pulse provided on the CLK/
Now for a worked example. In the case of a standard MAP CPU, we wish to set up the CTC as follows:
| CTC0 | is to drive SIO channel A to receive/ |
| CTC1 | is to drive SIO channel B to receive/ |
| CTC2 | is not used |
| CTC3 | is to receive the strobe from the keyboard, and to interrupt on each key |
Rather than give a full listing of code, I will use the method set out in [5] for I/O port initialization, with comments beside the relevant bytes to explain how they are arrived at. These initialization tables are set out like this:
| Page 11 of 51 |
|---|