Showing posts with label HowDoesItWork. Show all posts
Showing posts with label HowDoesItWork. Show all posts

Sunday, 3 May 2026

Commodore 4064 Repair - Part 2 - Reverse Engineering the Video Conversion Board

The PET 64 or 4064 is a modified Commodore 64 board inside a PET style case with a PET 12" monitor.

In the previous post, I fixed a few issues with the board and got it working again.

But How Does it Work?

The Commodore 64 produces a composite video output. The board has been modified so it will only produce a monochrome composite video output.

The PET monitor needs a 3 part signal input, horizontal sync, vertical sync and video.

To convert the single input to three outputs, Commodore used a small converter board, part number 2833981. (N.B. the owner asked me not to clean any of the boards to preserve the patina)

I have not found any schematics online, and I wanted to know how this worked, so I reverse engineered it.

One moment please.....

I tried both ways, but found it easier with the front photo flipped.

There are various wire links, so I start off by marking off the 0V and 5V rail connections.

I then went through and traced out the circuit, marking each of the pads I had drawn in blue as I went.

I drew the schematic sort of how the board was laid out, with the input in the middle at the bottom, and the output at the top.

Once that was completed, I rearrange it to make more logical sense.

I then removed the various wire link jumpers and not-fitted parts to clean things up a bit.

There is a lot going on, so I will explain it in sections.

Video

I will start with the simplest circuit, the video output. This should be TTL level digital pulses, with low being black and high being white / green.

The composite video signal comes in containing both sync and video data.

This is taken from the "luma + sync" pin on the VIC II chip, via a ferrite bead FB15. You can see the blob of solder at the end where the wire is soldered on the back of the board.

The diode shifts the level down by approximately 0.6V, which blocks most of the sync signals and just leaves the video.

This is amplified by the transistor as a non-inverting emitter follower and finally the AND gate converts that to a TTL level digital signal.

Zooming in, you can see the analogue video signals before and after the emitter follower (which has unity gain, so they are the same levels) and the clean digital out of the AND gate.

The resultant signal is nice and clean, and I could work out that it was the bottom row of the word "FASTLOAD".

The AND gate is gated by the vertical sync signal (generated elsewhere in the circuit), so that no video is generated during the vertical sync pulse (which would be visible as the electron beam flies back to the top left of the tube.

(the spikes are part of the C64 video output, at the far left of the frame, so not normally visisble)

Sync Separator

Both the horizontal and vertical sync generators share a common part, the sync separator.

This uses the two back to back diodes to clamp the input to cut off the video parts of the signal.

An inverting common-emitter transistor amplifier generates a positive version of the negative going sync pulses on the input.

The top trace shows the video input at the point where the vertical sync is, the last lines at the bottom of the screen are on the left, the first lines at the top are on the right. The C64 outputs a pulse at the start of each line, I think where the chroma burst would be in colour video. It is not visible, but it is useful to see what is going on there.

Composite video has the complicated pattern of half length lines with no video signal. These invert part way through, then return to normal. This is the PAL pattern, the NTSC version is slightly different.

The middle trace shows the clamped version which only contains the sync elements,

The lower trace is the cleaned up, inverted and amplified version used by the the two following circuits.

Vertical Sync

Next, the vertical sync.

The previously generated positive sync signal is buffered by the AND gate and passes though an RC low-pass filter.

Time for the first bit of maths.

The cutoff frequency of the low-pass filter is 1 / 2π R C

With 820Ω and 33nF, that works out as 5882Hz, so anything below about 6KHz will be passed through and anything above that will be filtered out.

This filters out the 15KHz horizontal sync pulses and leave just the 60Hz vertical sync.

The top trace is the sync signal from the AND gate, the middle shows the output of the RC filter which has turned that into a single pulse.

The final trace is the output of the monostable which extended that to create the vertical sync.

The cleaned positive pulse is used to trigger a 74LS221 monostable circuit. This has Schmitt trigger inputs, so the output of the RC circuit can be connected directly to the B input, which triggers on the rising edge.

This generates a clean negative going pulse on it's /Q output, the duration of which is set by the Rext and Cext on the chip.

The formula for the 74LS221 is 0.7 * Rext * Cext

(Actually, I think it is actually the natural log of 2, rather than 0.7, so ln(2) is 0.693147, but most of the datasheets just say 0.7 as you don't need to be that accurate given the tolerance of the parts used.)

The units are seconds, ohms and farads, so there are some pretty small numbers there.

I find it more manageable to keep Rext in ohms, and use a convenient value for the capacitance. Then you use the same multiplier for the time. With Cext in nanofarads, the result will be in nanoseconds, with the input in microfarads, the output will be in microseconds.

In this case, Cext is 0.1µF, and Rext is 10KΩ.

0.7 * 0.1µF * 10,000Ω = 700 µs

700 µs is about the duration you need for the VSync on a PET monitor.

I measured that as 731 µs, which is fair enough as the tolerance of the parts are probably 5% - 10% at best.

That pulse is repeated once every frame of video. You can see all the horizontal sync pulses, one per line, on the top trace. Below is the filtered trigger pulse and finally the VSync output.

Horizontal Sync

I was expecting the horizontal sync circuit would be the same as the vertical sync, just without the RC filter.

Working backwards from the output, it uses the same combination of an AND gate feeding a monostable.

Here, the time is 0.7 * 0.0033 * 8200 = 18.94 µs, the length of the horizontal sync pulse.

If you are paying attention (and if not, why not?) you may have spotted that there were three ICs on the board, and so far we have only used 3 AND gates and 2 halves of the 74LS221. What about the third chip, the 74LS123?

You had to ask, didn't you?

It took me a while to think this one through.

What is happening is the sync pulse is triggering the lower left monostable, with a period of 8 µs, slightly extending the incoming 4.7 µs and then this is ANDed with a mask signal.

The mask initially starts high, so the slightly extended sync pulse is passed through the AND gate and triggers the right hand monostable to generate the HSync pulse.

That also triggers the top left monostable, which sets the mask output low for 35 µs. That effectively masks off the incoming sync pulses and prevents them triggering the output monostable.

At the end of the 35 µs, the output goes high, and the next sync pulses will be passed through.

But why?

The top trace shows the sync input, next is the extended pulse, then the mask, and finally the output HSync pulse.

In normal operation, the mask is not doing anything, the sync pulses from the input only appear every 64 µs, so always get through.

It is only important when it comes to the VSync section. Remember those half lines that make up the VSync pulse? Well that is what this masking circuit is blanking out. You can see the transition in the above screenshot, the last normal line on the left and then the start of the half lines.

This continues until the normal lines start again, so you get a nice clear train of HSync pulses without the extra ones. Neat.

Conclusion

There is a lot going on there to take a composite video input and generate video, HSync and VSync signals for the PET monitor.

But it does a good job of the conversion and the PET monitor picture is clear and stable.

Lots of thought must have gone into that, so as I said in the previous post, I don't think these are the "spare cases and warranty returened boards" they are often dismissed as.

Side note 1

I thought you only had a two channel scope Dave, didn't I see some screenshots with 4 traces on?

Yes, I do, I cheated the third trace using the reference trace (previously saved version of trace 2 when the probe was connected to a different point), and I cheated the forth channel using the external trigger input (which is digital only which is why it looks cleaner than the others - it would be a nice option to be able to enable that on the other signals).

I did capture the same thing with the logic analyser.

But I decided to stick with the 'scope screenshots instead.

Side note 2

I skipped over the calculations for the two pulses from the the 74LS123, as that chip calculates the pulse period differently from the 74LS221, the formula is now:

Why didn't they use another 74LS221? Pass. The 74LS123 is pin retriggerable, so will restart the pulse if it received a second trigger before it finishes. I am not sure that is necessary here, but if it is, why didn't they use two 74LS123s instead?


Adverts

Good news, everyone, Tindie appears to be back. There are still some issues, hopefully those will be resolved soon and I can get back to normal. Three weeks with no income has not been fun.

My store contains all sort of kits, test gear and upgrades for the ZX80, ZX81, Jupiter ACE, and Commodore PET.

If you do want anything from the store and you don't fancy using Tindie, contact me directly using the link at the top of the page and let me know what you want and which country you are in, and I will get you a price if you want to order direct.


Patreon

If you enjoy posts like these, you can support me via Patreon, and get access to advance previews of blog posts (e.g. the next unusual Commodore 64 repair), and exclusive posts (e.g. part 1.5 of this series with the look at using the debugger to dump the ROMs).

You also get progress updates on new projects and other behind the scenes updates, as well as access to my Patreon only Discord server for even more regular updates, and to discuss your own projects.

There is now a free trial on the Patreon, if you want to find out what goes on in there, and I hope you will want to stick around.

Sunday, 5 October 2025

The Wonderful 74HC74

Put your Flip Flops on, let's go for a deep dive.

The 74HC74 (or 74LS74 or 74HCT 74 etc.) is a commonly used part in my designs and many others.

I thought it would be interesting to have a bit of a run through some of the many and varied uses of such a useful chip.

It is a dual D-Type Flip Flop. With two halves, each of which can be

  • A clocked latch
  • A set / reset latch
  • A flip / flip

And various combinations of the above.

It is the combinations which make it such a simple and yet powerful building block.

It was one of these combinations which sparked this piece. I had a great idea at 3AM one morning, but wasn't sure if it would work, and it required a bit of thinking through and tweaking the design to get there.

I thought it might be interesting to go through some of the many and varied uses of the 74HC74 in my designs.

So what is it?

The 7400 series was introduced in the mix 1960s, with the 74LS in the early 1970s and 74HC in the early 1980s.

It blows my mind in a world where technology changes so quickly that essentially the same parts have been in production for nearly 70 years. (yes, I know those are 175s, and yes I know HC isn't the same as LS, that was just the ones I happened to have a picture of)

This 74LS74 dated 1977 is in my Commodore PET 2001.

That's a Motorola version, this was the earliest Texas Instruments one I could find on any of my boards, first week 1980.

Here is one from 2020 (if I read the date code correctly) on a Minstrel 2.

The pinout

The first flip flop uses pins 1-6, the second pins 8-13, with the power on the corners as was usual for 74 series TTL chips (apart from a few oddballs, including the early 5474)

My PCB software lets my draw my own symbols, so these are the ones I use for the 74. I add the symbol to the side of the clock to remind me it operates on the rising edge.

Each half has 4 inputs and 2 outputs, for the moment, lets look at just three of them.

Clock

The clock input is an edge triggered input, things happen on the positive rising edge of the clock signal. Most of these chips seem to be clocked on the positive rising edge.

Data

When that edge happens, it samples the D or data input and copies it to the Q output.

Simple as that.

Q

Q only changes at the point the clock input changes from 0 to 1 (or a few tens of nanoseconds after).

This is useful for things like output ports on 8-bit microprocessor systems. These usually have a timing diagram something like this.

The address and function signals (read / write, memory or IO, etc.) are set usually on one part of the processor clock cycle (not to be confused with the clock on the 74). The data is then setup in the next part, although these are only valid for the later parts of the cycle, specifically at the point where the CPU clock changes.

The decoding logic for an IO port is usually setup so the port is active when the address is matched, so will go low towards the end of the first half of the CPU clock cycle, depending on how long it takes the propagate through the decoding logic.

Most of these circuits do not reference the processor clock itself, but are based on the address changing at the start of the next processor clock cycle. As soon as the address changes, the decoding logic will cause the clock pin of the latch to go back high, and at that point, the 74 will sample the databus and copy that level on the D pin to the output Q pin.

An example of this is the save output on the Minstrel 4th. This latches the value on the D3 bit of the databus when port $FE is written to. The Q output is used to drive the microphone input of the cassette recorder.

The clocked latch can also be useful for cleaning up signals, for example the video output on the Mini PETs and Minstrels and similar computers.

These have a video output which is a combination of the output of a shift register and a separate invert signal. These allow you to get twice as many characters by creating inverted versions of the ones you already have without having to store those in ROM (or RAM).

A problem seen on the output of the ZX80 and PET 2001 on modern monitors are shadow lines at the edge of some characters, caused by the invert signal changing at a slight different time to the character data. So for a brief moment, the invert signal is still set for the previous character, but the shift register output has changed to the next character.

The flip flop can be used here to use the 6.5MHz clock edges to sample the video data signal once per character, so the output can only change once per pixel, so you get a nice neat output with no glitches.

For the PET 2001 version, I fixed that with a single gate 74 surface mount chip mounted in a board which plugs into the socket of the 74LS08 it was driving. (OK, it's called a 74LCV1G175, but it operates just like a single 74 gate)

Frequency divider

Another common use for a flip flop is as a frequency divider. Here we need to bring in another pin

/Q or Q bar

There isn't a neat "Q with a line over it" symbol I can put in the text, so I use /Q. This is simply the inverted version of Q, and is set at the same time, a complimentary pair.

If you wire the /Q output to the D input, then on each rising edge of the clock, Q will be set to the value of the previous /Q output, which is the inverse of the previous value of the Q output, so it toggles.

This can be used to generate exactly half the frequency of the clock input, here generating 3.25MHz from a 6.5MHz input.

It is also a very clean 50:50 mark:space square wave, even if the input is very asymmetric, as the output is toggling on the rising edge, so does not care when the falling edge occurs.

The same sort of thing can also be used for a toggle function. Press a button to turn something on, press it again to turn it off.

The clock in this case is a debounced signal from a push switch.

Here pressing it once sets the /Normal output high and /Turbo low, press again and they change, /Turbo goes low and /Normal goes high and so on.

This circuit also uses the two other pins.

/CLR and /PRE

The remaining two inputs are clear and preset. Unlike the clock, these are level triggered. They normally sit at logic 1, and are active when the input is logic 0.

/CLR or clear is used to clear the output of the flip flop, so any time that pin is 0, the Q output will be fixed at 0, and /Q at 1, no matter what the clock and data inputs are doing, and will stay low until the next clock pulse (or /PRE goes low)

/PRE or preset works in the same way, but presets the Q output to a 1 and /Q to a 0, and again those will stay like that all the time /PRE is low.

In the above circuit, they are used so the microcontroller can force the flip flop into one mode or the other.

It is undefined what happens if both /CLR and /PRE are low, don't do that, it may cause the universe to implode.

/CLR is quite useful to wire to the system /RESET, so that the flip flop will always start in a known state.

For example, the mic output on the Minstrel 4th could have used /CLR to force the output low after reset, but the original Jupiter Ace version didn't, so I didn't.

Shift Register

Another thing you can use a 74 for is to create a shift register. Here in the Minstrel 3 video circuit, I only needed a couple of stages, but by tying the clock inputs together and chaining Q (or /Q) to the next D, you can create a shift register which propagates a signal down the line on each clock pulse.

That is used to generate the back porch signal for the video on the Minstrel 3, driving the /CLR input as sown above to force the video output to be low for the screen borders.

The Minstrel 2 version is a bit more analogue.

The CLR input on the flip flop is driven from an RC circuit which extends the sync pulse to create a back porch for the video signal to set the black level before the white borders start.

That circuit also contains an unusual use of the 74. I needed to buffer the sync signal, but I did not have any spare gates, only half of a 74 flip flop.

I had Sync and /Sync signals, so I was able to use the 74 to recreate a version of Sync by driving the /CLR and /PRE inputs.

That was one of those times where I had to work it through all the possibilities to see if it was OK, as I had not seen it done before.

I've had a great idea....

That brings me to the idea I had a few days ago.

The Minstrel 4th can run at 3.25MHz or 6.5MHz, and this is currently selected by a pair of jumpers.

This isn't an ideal solution as I am sure someone will have tried fitting both jumpers to see if they get 9.75MHz (you don't).

The 6.5MHz used for the video circuitry is buffered by a spare 74HC86 gate and then divided down to get the 3.25MHz clock.

On the Minstrel 4D, there was quite a complicated circuit to select Trubo™ mode (on the first prototype, I managed to spell Turbo wrong, so I still call it Trubo mode).

Here the buffered clock is divided down, and the other half of the flip flop selects which clock is passed through to the output.

The OR gates here only pass through the clock when the control input is low. When /Normal or /Turbo are high, the output of their respective OR gates is always logic 1.

(There, fixed, I don't think anyone noticed)

There isn't space for all of the turbo button circuitry on the Minstrel 4th, so I was trying to think of a way of doing that with a single jumper, but without adding any parts, a 74HC257 would have done the job, but I don't want to add a whole extra chip just for that, likewise the OR / AND mixer circuit above.

I wondered if I could make the half 74HC74 that I had into some sort of configurable divider, to produce 6.5MHz or 3.25MHz.

As it currently works, on every rising edge of the 6.5MHz clock, the /Q output is copied to the Q output, so toggling it.

This gives an output which is half the frequency of the input, so we get the 3.25MHz output.

I was wondering if I could use the /CLR input to set Q low half way though the cycle and then it would always be set high again at the start of the next cycle, maintaining the 6.5MHz output.

I would use a jumper to select if /CLR should be high (for 3.25MHz) or be a short pulse on the falling edge of the 6.5MHz clock (for 6.5MHz).

My first attempt used an RC circuit.

I tried lots of values for the R and C, but I couldn't quite get the short pulse I wanted, although it did appear to work.

I wasn't happy that would be reliable, I need the /CLR signal to be safely high before CLK changes. If the /CLR signal does not rise before the CLK, then it will ignore the clock signal and the output will stay low. At half time, /CLR will force the low output to continue to be low and so on, not changing.

After some pondering, I came up with a plan B, which is to use the spare XOR gate to delay the 6.5MHz clock. The propagation delay of a 74HC86 is 10-20ns, which doesn't sound much of a delay, but consider the period of the 6.5MHz clock is only about 150ns.

The logic analyser is only measuring to 5ns, so that is only two samples.

But that is enough to make it work.

The delayed clock pulse means /CLR will not be active when the Clock rises, so it will always clock in high and at (about) half time, will be forced low.

That allows the single jumper to select 3.25MHz or 6.5MHz.

That all seems to be working nicely, so I will add that to the next revision of the board.

Other notable mentions

I should also give a mention to some of the similar chips, the 175 is a quad version which has a common clock and clear (/MR, master reset), but still has Q and /Q outputs.

The 174 is a hex version, again with common clock and clear, but does not have the /Q outputs

The 273 is an octal version.

The 374 is similar but has an output enable in place of the clear.

And finally, the 574 which is the same as the 374 but with the pins arranged in a more pleasing order.

Conclusion

All in all, a very useful chip that can be used in all sorts of ways. Have I missed out any other ways you can use a 74?

This was a bit out of the ordinary, but I hope you found it interesting.

Would you like to see more like that, following some discussions on the discord, a post on the 555 timer might be interesting?


Adverts

The Minstrel 4th is available form my Tindie store:

I can still ship worldwide and US orders are now tariffs paid.

Currently it looks like Royal Mail to the US is working, and I pay the 10% tariffs as part of the postage to (hopefully) avoid delays and additional costs that customs. The increased postage costs cover this.

I have also built some more Mini PET 40/80 Internal boards, since the Mini PET II is still in development but people keep asking, so here they are.



Patreon

You can support me via Patreon, and get access to advance previews of development logs on new projects like the Mini PET II and Mini VIC and other behind the scenes updates. This also includes access to my Patreon only Discord server for even more regular updates.