Best way to get multiple clock speeds... - Page 1
Forum section: electronics / projects

author: alank2
author_rank: Super Contributor
timestamp: May 11, 2018, 05:59:46 pm
content: I am working on a Z80 vintage type project and I want to have multiple clock speeds. An AVR will also be present, but it will be clocked at 14.7456M for clean serial port baud rate reasons. I will use 3 pins to control the clock speed so 8 speeds, but 1 is dedicated for the AVR to manually clock it, so that leaves me 7 more speeds. I wanted to pick speeds that the Z80 commonly ran with, and at the same time allow for maximum speed (20MHz). Speeds that come to mind are 20, 16, 12, 10, 8, 6, 5, 4, 2.5, 2, 1 MHz, but I can't think of an easy way to be able to do them all. The best way I've come up with is using a 74HC151 to select the 1 out of 8 clocks, and then use both sides of a 74hc393 counter to split two oscillators, one 20MHz and one 16MHz. That would give me:20, 10, 5, 2.5, 1.25and16, 8, 4, 2, 1where I could tap 20, 16, 10, 8, 4, 2, and 1 as my seven speeds.This would involve 2 oscillators, a 74HC393, and a 74HC151. Is there a better way to do it?

author: maginnovision
author_rank: Super Contributor
timestamp: May 11, 2018, 06:08:58 pm
content: A programmable pll might be a better choice for board space but possibly worse for cost. Be wary of all components being fast enough to keep up though and that you have a power supply that can supply the current as well.

author: AndyC_772
author_rank: Super Contributor
timestamp: May 11, 2018, 06:23:36 pm
content: I'd look at something like a Cypress CY22393F. Chips like this are designed to do exactly the sort of thing you're after.They're not "vintage", of course, but only you know whether or not that matters.

author: nuno
author_rank: Frequent Contributor
timestamp: May 11, 2018, 07:59:40 pm
content: I think ZX Spectrum used ~3.54MHz

author: alank2
author_rank: Super Contributor
timestamp: May 11, 2018, 09:31:36 pm
content: That is quite an IC. I need 5V though, but I don't care if the IC is vintage. Any other ideas or thoughts?

author: David Hess
author_rank: Super Contributor
timestamp: May 11, 2018, 11:36:27 pm
content: Usually the problem is switching clocks without violating the clock specifications.

author: C
author_rank: Super Contributor
timestamp: May 12, 2018, 12:11:42 am
content: I see this as most likely a waste of time.I could seefull speed, slow for idiot lights & single step.Max speed Z80 wants a square wave for signal. You get this by using the output of a FF. This can also prevent timing glitches on speed change.If you want fancy then look at TTL delay lines as timing source for the clock.This lets you have async clock source.You could have different times for clock high vs clock low.The taps on the delay line lets you create many different delays easily.C

author: alank2
author_rank: Super Contributor
timestamp: May 12, 2018, 12:42:23 am
content: I think I can switch the clock between speeds safely when it is in BUSREQ or WAIT mode. We'll see once I test it. I am surprised there isn't a SPI clock generator that multiplies/divides one oscillator into other speeds! The first IC looked pretty impressive, but only 3.3V and more complicated than needed!

author: C
author_rank: Super Contributor
timestamp: May 12, 2018, 01:06:09 am
content: The Z80 is still using the clock during DMA & Wait.Undefined is still undefined.You need to switch clocks such that min time for clock level is valid.Two clock sources makes this hard when clock sources are not locked and keep changing phase ratio.A test that shows it works can fail as the two clocks change.

author: Nitrousoxide
author_rank: Regular Contributor
timestamp: May 12, 2018, 01:55:45 am
content: You could possibly use a single higher frequency oscillator and then use a set of flip-flops to progressively divide the clock by 2, then by using a MUX you can tap off the desired clock. For example, a CD40175B and a DG441 could do the trick.Or alternatively, you can use a counter. Just when the counter reaches the last value/overflows, you can load in a specific value to give you the desired period.

author: alank2
author_rank: Super Contributor
timestamp: May 12, 2018, 03:22:46 am
content: That is exactly what I am doing / planning on doing now. I was just wondering if there was a more efficient less parts way to do it.

author: David Hess
author_rank: Super Contributor
timestamp: May 12, 2018, 03:49:29 pm
content: This article at EDNdiscusses the problem and some solutions. The article below shows what I have done in the past to switch between multiple clocks. The synchronous clocks are generated, a ripple counter works as shown but a synchronous counter might be needed if there are a lot of stages or the clock rate is high, and then "reclocked" using a flip-flop and the fastest clock so the output clock is always aligned with the fastest clock. That gets you down to the divider, multiplexer, flip-flop, and gate so perhaps 4 or 5 packages.Weird, I'm not sure why the PDF attachment failed.Here is a link to it also.

author: alank2
author_rank: Super Contributor
timestamp: May 12, 2018, 05:24:49 pm
content: Can you repost the pdf David, it is 0kb and can't open for me. Thanks!

author: alank2
author_rank: Super Contributor
timestamp: May 12, 2018, 05:29:35 pm
content: That is a great article, but I wonder if it is necessary to prevent the tiny clock glitch in this example. If the Z80 is in WAIT or BUSREQ mode, it is just watching clocks going by until either of these two signals de-asserts, so a glitch should not cause any trouble. The only Z80 I plan on using is fully static and you can even stop the clock without any trouble.

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 12, 2018, 06:19:59 pm
content: I don't know what kind of freq. accuracy you're after, but you could take a look at the LTC6903. You won't get the kind of accuracy you can get with a crystal-based oscillator, but it's very flexible.http://www.analog.com/en/products/clock-and-timing/silicon-oscillators/ltc6903.html

author: alank2
author_rank: Super Contributor
timestamp: May 12, 2018, 07:08:33 pm
content: That is interesting. I'm not so sure accuracy is huge though I'd prefer more than less. Are there more accurate versions?

author: C
author_rank: Super Contributor
timestamp: May 12, 2018, 08:06:05 pm
content: Until you know all the factors that effect each part of the logic inside a logic device, using it outside of specifications is just a guess that it will work. Your testing could show it works, but one of the many factors changing can make it fail. Did your test include all the many factors that can change?Is it a good computer when it fails 1 time in a million or billion clock cycles?Digital logic has an analog foundation.Just because some logic works when you have two outputs driving a signal, does that say that it will always work? Well known that added stress can cause parts to fail sooner.Do you want to add the added fun of trying to find why it failed in the future?If the specifications do not mater then your 20mhz Z80 would run at 100mhz.Two reasons for an accurate clock.1. To keep timing margins on attached circuit with in limits.2. To know how long a sequence of instructions will take. In the days of the Z80 many computer designs & min cost, put limits on max and min clock speeds.I repeat, I see very little benefit with many clock speeds.You might change the speed to match what is attached to get max computing power.You might change the speed to allow better use of idiot lights on signals.You might single step or slow to help debug.For Z80 the WAIT input is standard way to adjust speed to attached circuit. Z80 clock is a second way.If a Z80 & attached circuit will function with some timing margin at speed X, what is the benefit of using anything less?C

author: alank2
author_rank: Super Contributor
timestamp: May 12, 2018, 08:35:36 pm
content: It is for a retro/vintage Z80 CP/M project so I may want to run old software slow, which is the reason for the multiple speeds.

author: jimmc
author_rank: Frequent Contributor
timestamp: May 12, 2018, 08:56:57 pm
content: If you've have spare capacity on the AVR to control it (I2C), how about a Si5351https://www.silabs.com/documents/public/data-sheets/Si5351-B.pdfand choose any clock speed between a few kHz and >100MHz.It will need a level shifter on the outputs. Breakout boards are available cheaply on ebay etc.Jim

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 12, 2018, 10:45:55 pm
content: Quote from: alank2 on May 12, 2018, 07:08:33 pmUnfortunately not. There are more sophisticated clock generators, but clearly overkill for your needs and expensive.It has 0.5% initial accuracy and 1.1% max over the whole range according to the datasheet. I think it would fit the requirements of a vintage computer. 1.1% max error is fine for serial asynchronous communication for instance. It may be more problematic for video generation maybe? Although some vintage computers didn't use actual crystals for their main oscillator but ceramic resonators (much cheaper), which have the same range of accuracy than the IC I mentioned. (see:https://en.wikipedia.org/wiki/Ceramic_resonator)If you still prefer a crystal-based oscillator, the 74LS294 seems interesting:http://www.ti.com/product/sn74ls294It doesn't seem to be available in HC series though, and is hard to find except at TI? But worth a look for vintage stuff.

author: alank2
author_rank: Super Contributor
timestamp: May 12, 2018, 11:56:17 pm
content: That si5351 is interesting. Do they have a SPI version of that?I also need a 14.7456M oscillator for the AVR, I could use the si535 to produce both the Z80 clock and the AVR clock as long as I have a 3.3-5V translation for each of them.

author: alank2
author_rank: Super Contributor
timestamp: May 13, 2018, 02:53:01 pm
content: I've been playing around with the ClockBuilder for the si5351, it is pretty impressive what it does for its price and a 25 MHz crystal. I wish I could get it to produce the 14.7456 MHz I need for the AVR too, but it sounds like unless you can't get them easily custom programmed.

author: jimmc
author_rank: Frequent Contributor
timestamp: May 13, 2018, 03:39:48 pm
content: The Si5351 clock outputs are 8mA into 50ohm ie 400mV pk so some form of line receiver might be the way to go to get to 5V.The ebay breakout boards have level shifters for the inputs and a 3.3V regulator.Maybe a second small AVR (running on its internal oscillator) dedicated to programming the Si5351.Jim

author: alank2
author_rank: Super Contributor
timestamp: May 13, 2018, 10:51:14 pm
content: I'm already going to be using a sn74ahct1g125dbvr for another 3.3->5 conversion so I might just move to the quad version.I noticed that the Si5351 talks about different drive strengths. With a high impedance input, should it have a near vcc type output?

author: bson
author_rank: Unknown
timestamp: May 14, 2018, 03:41:55 am
content: If you don't mind replacing the vintage RS-232 port with USB and using a CP2102N, then you could run the serial port at one of the supported data rates more easily generated, such as 125kbps. That's just a 4MHz clock divided by 32. Because, let's face it, that RS-232 port is going to have a USB adapter attached to it anyway...

author: alank2
author_rank: Super Contributor
timestamp: May 14, 2018, 03:56:58 am
content: I'm going to run all the serial through the AVR - it has 4 ports and that is one of the reasons it will have a uart friendly oscillator (14.7456MHz).