Page 1 of 2
Flexible clock circuit
Posted: Sat Nov 23, 2019 10:58 am
by joanlluch
Hi All,
I'm aware this is not a 6502 specific question but I thought I could get good answers from here.
I am looking for a clock circuit that would allow me to select clock frequencies in a wide range including step by step operations. Ideally, I would want it to be able to work in 3 possible modes. (1) Full speed, possibly driven by a crystal oscillator. (2) Adjustable slow speed, in the range of almost zero to just few Hz, which I guess can be achieved with a 555 based circuit. (3) Step mode, where single pulsations of a push button will make the clock cycles.
I have found some easy designs on the internet (most of them based on the Ben Eater series nowadays), but all of them seem to overlook the possible bad effects of switching modes while in operation. For example, when the clock is switched from step mode to low speed mode, it is desirable that the circuit waits for the next clock edge before continuing with the selected frequency period. Also switching from slow speed to full speed modes should be seamless.
Thanks in advance for any pointers.
John
Re: Flexible clock circuit
Posted: Sat Nov 23, 2019 5:49 pm
by Drass
Hi Joan,
I had to put together something like that to test the C74-6502. The clock circuit featured STOP/START, FAST/SLOW and STEP modes. The original circuit didn’t quite work, but I managed to patch it. Here’s a link to the relevant post on the thread.
viewtopic.php?f=4&t=3493&start=225#p54027
Hope that helps.
Re: Flexible clock circuit
Posted: Sat Nov 23, 2019 5:54 pm
by GARTHWILSON
I see Drass posted while I was writing. I'll keep going anyway.
I would recommend against using the 555, as its output rise and fall time are much too slow (100ns!) to meet the 65C02's requirements (if you were using a current-production '02). I don't have a full do-everything circuit for you, but I would base it on at least 74HC, if not 74AC, Schmitt-trigger logic. My 6502 primer's
clock-generation page shows a single-cycler clock-generation circuit about 3/4 of the way down the page, and there are links there to related forum topics. See especially
viewtopic.php?p=10619#p10619 where I show a variable-frequency oscillator I use. In
viewtopic.php?p=378#p378, I tell of a couple of programmable oscillators from Dallas Semiconductor. (That was 16 years ago, so I'm sure they have improved ones by now.)
For clock stretching without glitches, see this experiment I did 21 years ago. (Don't use 4000-series logic though. I only used it because it's really slow, and I wanted it slow enough that if there were any runt pulses, they would show up on my 20MHz analog 'scope.)
Re: Flexible clock circuit
Posted: Sat Nov 23, 2019 6:09 pm
by Drass
Hi Garth,
The single-pulse circuit I used is taken from your clock generation page (although I mentioned it was yours, I failed to include
a link in the schematic

).
I also used your VFO circuit when
building my own, so I can vouch for it.

Re: Flexible clock circuit
Posted: Mon Nov 25, 2019 2:30 pm
by joanlluch
Hi Joan,
I had to put together something like that to test the C74-6502. The clock circuit featured STOP/START, FAST/SLOW and STEP modes. The original circuit didn’t quite work, but I managed to patch it. Here’s a link to the relevant post on the thread.
viewtopic.php?f=4&t=3493&start=225#p54027
Hope that helps.
Yes, this helps. Ultimately I realised that what I really wanted is a
clock switching circuit with two independent clock sources, so googling the right words I found this on the internet:
https://www.eetimes.com/document.asp?doc_id=1202359.
I figured out that I could combine that with the ideas on your circuit, and I came up with this logisim simulation:
There are two clock input sources and a manual tick button:
- The fast clock source will be a crystal oscillator.
- I want the slow source to be variable along the few Hz range (maybe up to 10 Hz or so), so I think the 555 timer circuit described in the "digital computer electronics" book should do it.
The circuit seems to work fine on logisim although the clock exchange takes some time because it does not happen until both sources have completed its own cycle. That's not a major issue for me though. The circuit uses quite a number of ics but I assume it can't be simplified given the specs.
Joan
Re: Flexible clock circuit
Posted: Mon Nov 25, 2019 2:46 pm
by joanlluch
I see Drass posted while I was writing. I'll keep going anyway.
I would recommend against using the 555, as its output rise and fall time are much too slow (100ns!) to meet the 65C02's requirements (if you were using a current-production '02).
Thanks for the tip. I only aim for
very slow clock rates (in the range of just a few Hz) for the 555 based source. I think that if I connect the output of the 555 to a flip-flop I will get a perfect square wave with proper edges and half the frequency, no?. A Ben Eater video on youtube shows an even simpler approach that seems to work. He just directly connects the 555 output to a few logic gates he uses for switching purposes, and then uses the output of that gates to clock a 6502. Is there something inherently wrong with that?
Thanks
Joan
Re: Flexible clock circuit
Posted: Mon Nov 25, 2019 3:03 pm
by BigEd
(Just possibly worth picking gates with Schmidt inputs, if the input is slow, and you really don't want glitches.)
Re: Flexible clock circuit
Posted: Mon Nov 25, 2019 6:27 pm
by GARTHWILSON
Thanks for the tip. I only aim for very slow clock rates (in the range of just a few Hz) for the 555 based source. I think that if I connect the output of the 555 to a flip-flop I will get a perfect square wave with proper edges and half the frequency, no?. A Ben Eater video on youtube shows an even simpler approach that seems to work. He just directly connects the 555 output to a few logic gates he uses for switching purposes, and then uses the output of that gates to clock a 6502. Is there something inherently wrong with that?
As Ed says, a Schmitt-trigger input will go a long ways. I'm not sure it would totally eliminate the possibility of noise picked up from heavy ringing on another part of the circuit causing unwanted pulses between intended phase-2 edges though; and these pulses' speed may be too fast for the processor to handle, and cause a crash. We like Ben's enthusiasm; but he has a number of practices that could cause (and sometimes
have caused) problems for others in their circuits. (There's one right now in the "6502 Homebrew Hardware and Programming" facebook group, where Ben's reset with only an RxC isn't working for the OP, even though it's on a PCB.) When this is the case, the "It works for me" argument may only prove that the failure rate is not 100%. That's not very useful information. Fortunately the actual performance of various ICs is better than the specs guarantee, but again, we can't depend on non-guaranteed behavior unless we do enough testing to get a good feel for how much margin we're leaving. In the case of a gate with a Schmitt-trigger input, the specs may guarantee a certain amount of hysteresis, but there will probably be a little more. How much? Are we operating so close to the edge that a change in temperature, or the moving of a couple of wires, will make it stop working?
So we have to find a balance between, on the one hand, overburdening the beginner with excessive and complicated implementation details, and on the other hand, ignoring those and letting him build something that takes months to debug and he finally gives up. The goal of course is to maximize the success rate.
Re: Flexible clock circuit
Posted: Tue Nov 26, 2019 2:11 am
by BigDumbDinosaur
- I want the slow source to be variable along the few Hz range (maybe up to 10 Hz or so), so I think the 555 timer circuit described in the "digital computer electronics" book should do it.
A problem with using a 555 timer, as previously mentioned, is the output transition time is much too slow for the 65C02. Also, you need to try for 50/50 symmetry, which is hard to attain from a relaxation oscillator.
Something I use in some of my designs that require a slow but stable symmetric "tick" is a comparator oscillator, such as the below illustration.

- Comparator Oscillator Illustration
This particular application is a model railroad grade crossing signal flasher, with the comparator oscillator cycling the signal lights at the rate of 1 Hz. The circuit has near-perfect symmetry and is relatively insensitive to Vcc.
The circuit works because the input transition threshold of a comparator is extremely narrow, at most a few millivolts. Hence the oscillation frequency is a function of the R-C time constant of R5 and the C4/C5 combination. R5 is both charge and discharge path for the capacitors, which means symmetry is as good as that of the comparator "crossover" characteristics. The ratio between R4 and R5 is not critical, so you could use a pot in place of R5 to create a low-speed variable clock.
The comparator’s output is an open collector, so it has to be pulled up to Vcc—anything from 1K to 4.7K is usually sufficient. Open collector outputs are somewhat on the slow side, relatively speaking, with a high-to-low transition typically around 1 µS. A Schmidt trigger, such as a 74AC14, should be used to condition the oscillator’s output so as to satisfy the 65C02’s Ø2 clock requirements.
Re: Flexible clock circuit
Posted: Tue Nov 26, 2019 8:04 am
by BigEd
... you need to try for 50/50 symmetry, which is hard to attain from a relaxation oscillator.
Hmm, the only reason to aim for 50/50 is when you're running at full speed, and you need both clock phases to be as short as practical. At any slower speed all that matters is that each phase is within spec - has at least some minimum length.
Re: Flexible clock circuit
Posted: Tue Nov 26, 2019 2:31 pm
by Dr Jefyll
Agree with Ed (above).
And, as for 555 or a discrete circuit, it occurs to me that 74HC221 or '123 would be much better choices, given that they belong to the 74xx family. And, a quick check shows their output rise/fall spec (22 ns, assuming a 50 pF load) is roughly equal to that of an 'HC14 Schmitt Trigger, suggesting the latter will not be required or helpful for conditioning the output.
But even the 'HC14 isn't clearly within spec for driving a 65xx clock input. The 'HC specs don't tell us what the figure is for loads less than 50 pF.
-- Jeff
Re: Flexible clock circuit
Posted: Tue Nov 26, 2019 8:02 pm
by Agumander
Would something like the 74HC40103 work to clock a 65xx? That'd get you 8 bits of digital control over your clock speed, and you wouldn't have to mess with capacitances/resistances or carefully twiddle a pot.
Re: Flexible clock circuit
Posted: Tue Nov 26, 2019 8:06 pm
by joanlluch
Hi Jeff,
I am not going to drive a 6502 with it, but a home made cpu, but I suppose this should make little difference. (The build thread describing the architecture and software tools I implemented is this:
http://anycpu.org/forum/viewtopic.php?f=23&t=583)
The only purpose of such ultra low frequency mode is having visible blinking lights on the front panel showing registers and control line values. I though a 555 configured as a astable multivibrator with a potentiometer, followed by a J-K flip flop to obtain proper edges and 50% duty cycle, would do it just fine, as I do not need any frequency accuracy for that. I can also insert a Schmidt trigger buffer before the J-K as suggested.
Please can you point me to a circuit schematic that would do a 50-50 square signal with continuously adjustable frequencies in the range of a few Hz (such as from 0.25Hz to 10Hz) using one of the ics you suggest?
Thanks.
Re: Flexible clock circuit
Posted: Tue Nov 26, 2019 10:16 pm
by GaBuZoMeu
I apologies I haven't read all of this thread, just jumping in
If i would need such a low frequency oscillator I would use a CMOS (hex) schmitt trigger inverter (40106 or 4584) with a large resistor or trim pot (2.5 or 5 M) wired from output to input and an (tantal) elco e.g. 47uF/10V or more.
To obtain lower frequencies (and square waves) a 4024 (2^7) or 4040 (2^12) binary counter could be used.
If you need fast rise/fall times a 74HC4040 should work as well.
Re: Flexible clock circuit
Posted: Tue Nov 26, 2019 11:06 pm
by GARTHWILSON
I would use a CMOS (hex) schmitt trigger inverter (40106 or 4584) with a large resistor or trim pot (2.5 or 5 M) wired from output to input and an (tantal) elco e.g. 47uF/10V or more.
74xC14 (74HC14, 74AC14, etc., but not 74C14) would be the 74-series equivalent, with much faster rise and fall times.
I was going to post links to NSC (later Fairchild) ap. notes, but when ON Semi took over Fairchild, they wiped them out. I've been able to get them to re-post some of them, and now I just sent another email asking for these two, which I have old links to on my 6502 primer's
clock-generation page and just realized I still need updated links to:
HCMOS crystal oscillators (AN-340) and
CMOS oscillators (AN-118)
I have them on paper but unfortunately not in electronic form to attach here. I plan to update this (as well as the links on my website) when I hear back from ON Semi.