Close

Clock stretching

A project log for STEbus 65C02

65C02, 32K Flash ROM, 64K fast RAM, USB link to PC. Runs BBC BASIC, at up to 14MHz.

KeithKeith 05/27/2022 at 22:290 Comments

There were no STEbus 6502 designs to reverse engineer so I've had to tackle this one from scratch.

Essentially we need to make the synchronous 6502 look more like an asynchronous 68008.

The STEbus data strobe signal (DATSTB*) is asserted (low) when all the address and data lines are valid. There is a 40 ns setup time requirement.

The 6502 clock out signal (E) is asserted (high) when all the address and data lines are valid.

So E can drive DATSTB* through a 40 ns delay and an inverting gate. However, E must not go low until the STEbus slave returns a DATACK* signal. 

Let us begin by considering an oscillator running at twice the 6502 clock rate, driving a simple 74LS74 D-type latch with the D input fed by the /Q output. The Q output will toggle at the 6502 clock rate.

Now we can stretch the clock by adding a delay between the /Q and D pins. A shift register will do the job. With the proviso that it will need clearing to all zeros (or all ones) regularly to avoid invalid states.  The STEbus prototyping board uses an 8-bit shift register with clear, the 74LS164, for cycle stretching. Read the timing explanation to see how it works.

The shift register outputs look like this:

abcdefgh
00000000 when E is low, all cleared.
10000000 when E is high, starts entering shift register
11000000
11100000
11110000
11111000
11111100
11111110
11111111

You can feed any shifted signal, a to d, inverted back to the D input of the 74LS74 flip flop, and stretch the E high time.

The E low time is not stretched. Yes, that does mean the high and low times are going to be different. That is going to look weird to people used to conventional 6502 designs. But it is completely legitimate. They cant touch you for it! You can have any duty cycle you want, though of course it has to be 50:50 at the maximum clock rate.

The E low time will be the minimum for all access cycles. There is no reason why it should not, because the 6502 bus lines are invalid and no other device can do anything. All the 6502 is doing is internal stuff, and it can do that at top speed.

In a realistic system you will have various devices of various speeds. The devices are memory mapped, so the delay has to be selected by the address lines.

As a simple example demonstration of how to do this, consider a 1-of-8 multiplexer between the shift register taps and the inverter feeding the D input of the 74LS74 flip flop. Address lines A15-13 select the shift register output for each of eight 8K spaces. Each 8K space can have a different E high time, or the same, depending on how you wire it.

In practice, memory maps are not so simple and my prototype design uses GAL chips to select the delay. It makes sense to have the delay-selection in the same logic chip as the device-selection.

In my design, there are different fixed delays for ROM (fairly fast), RAM (very fast) and I/O (USB module). For STEbus access, the DATACK* signal is sensed, allowing for a variable delay. 

I have also compromised on the clock speed. The STEbus requires a 16 MHz timing clock, while the 65C02 is rated at 14 MHz. I am running my 65C02 at 8 MHz because this is easily derived from the 16 MHz oscillator and 16 MHz would be overclocking the 65C02. That is something I would try when I have  a printed circuit board but not with vero-wire on protoboard.

Discussions