Orwell IO daughter board.

February 8th, 2015

Recently I was in the UK for Christmas and New Years. One of the trips I did was to Bletchley Park which is where the codebreakers in WW2 cracked the Enigma code. Bletchley has a working version of Turing’s Bombe machine which is used to work out the possible settings for the Enigma decoder. Next door to Bletchley is the National Museum of Computing which contains a working reconstruction of Colossus, one of the first true computers. Seeing all these Enigma machines and Bombes and computers has inspired me to finish off my Orwell machine. If you are any kind of computer geek and in the UK you absolutely have to go visit Bletchley Park. It’s well worth it!

To make Orwell into a full, useful computer I needed to add a few more things. Mainly some extra IO capability. I decided I wanted a joyport with an analog stick as well as more general purpose IO. One fo the main reasons for this is for when I get up to reviewing the Usborne computer books that talk about hardware interfacing. Ultimately I want to reconstruct the robot from the “Practical things to do with a microcomputer” book. That will be recreating a science fair project I made back when I was about 14. For some reason I have three copies of this book – I went a little mad trying to get them all!

The easiest way to do IO is with more 6522 VIAs. I got two more of them and decided to use one as the joyport and the other as the general purpose port. To make the joyport work I added two ADC 0804 analog to digital converters. These ADC can be controlled and read from a micro controller directly but I took a shortcut. I run each ADC in free running mode and feed the 8 bit out (well 7 as I will explain later) of the ADC continuously  into one of the VIAs 8 bit ports set up as an input. I did this because it made the code much simpler than trying to read and write the ADCs every time I wanted to make a reading. It would take a little fiddly assembly code to do this and I wasn’t sure I could successfully add it into the Orwell BASIC. It would also mean having to provide new commands to read the ports.

Instead of needing fancy code and commands all I do now is let the ADCs free run as fast as they can and when I want to read the value I PEEK at the VIAs ports to get the value. Simple!

There is one little bit of code needed to set this up. To start the ADCs free running you need to pull certain pins on them low momentarily. I achieved this buy connecting these pins to CA2 on the joyport VIA. In the rest routine I set this to be an output, momentarily pull it low then set it to an input again (which make it high again). I pull it low before asking the Cold/Warm start question and set it to input after the user has made their selection so I have a good long low reset pulse.

With one ADC on port A and one on port B of the VIA I can read two analogue values and hence can attach a simple analogue stick.

Now how to do buttons? I was hoping to use the peripheral control pins somehow but that proved tricky. They work using interrupts so again the code would be fiddly to handle it. I did think about using a couple of pins on the other VIA but I really wanted to leave all the pins on that free as general purpose IO pins. Again I took a shortcut! The ADCs have quite a bit of jitter. That is if you continuously read the value coming from them you’ll notice it jumps about a bit by a small amount. So for a any 8 bit number (from 0..255) you might see a value that’s changing by +/- 1 or 2 each reading. I decided because of the jitter I was never going to get a highly stable reading with the bottom bits jumping about. For a simple joystick you don’t actually need it to be hugely accurate. So I thought what if I drop the least significant bit and use that input on the VIA to monitor the buttons instead.

It’s a definite hack but I works surprisingly well. Instead of feeding all 8 bits from the ADC into the VIA I drop the bottom bit. Instead that input is wired to a 10k resistor to pull it up. The button then connects to that bit and pulls it down when the button is pressed. Since I have two ADCs I can have two buttons.

In practice what this does is this: When you PEEK at the VIAs ports you get a 0..255 value returned. But since the bottom bit is missing it will either be an odd number when the button isn’t pressed or an even number when it is. So you are still getting a full 0..255 range but you’ve lost a bit of accuracy.

To check if the button is pressed in the BASIC code you get the reading with a PEEK then simply AND it with 1. If the answer is 1 the button isn’t pressed. If the answer is 0 the button is pressed. The logic is backwards to how you think because the button is physically pulling the pin low when pressed. The reversed logic is easy to deal with in software. I had to use AND because MS Basic doesn’t have a MOD function.

You can convert the 0..255 odd or even values into a 0..127 range with continuous values by dividing the value by two and dropping the fraction.

To read the joyport (returns 0..255 odd or even values depending on button state):
X = PEEK (17409) ;Axis 1 (port a on the VIA)
B = X AND 1 ;Check lowest bit
IF B = 0 THEN … ;0 = button pressed 1 = button not pressed

To read the joyport (returning a 0..127 continuous range):
X = PEEK (17409) ;Axis 1 (port a on the VIA)
X1 = INT(X/2) ;Convert to a 1..127 value with no gaps

For a simple 8 bit machine this seems to work very well!

The second VIA is wired as a straight general purpose IO port with both ports a and b broken out to provide 16 bits that can be independently made inputs or output and then set and read at will. I also broke out the four peripheral signals, CA1, CA2, CB1, CB2 but I am not sure they will be much use for the kinds of things I will use Orwell for. Because I am running BASIC there is no easy way to handle interrupts. I would need to write general purpose handlers in the ASM code and I don’t think it’s a complication I need at the moment.

One other thing I added since I had board space was a 555 timer based power on reset circuit copied exactly from Jeff Tranter’s blog. He used it on an Apple Replica 1 which is another simple 6502 machine. This circuit works very well and removed the need to manually hit the reset button after turning the machine on (although you still need the manual reset when you do something silly in the code).

I did all this on a breadboard to start with to make sure it all worked.


Since it worked I made my usual strip board version with the bird nest wiring from hell.

IMG_3083_1 IMG_3084_1

The reason I can get away with such masses of wiring is Orwell isn’t running particularly fast, only at 1mHz so you don’t start having to worry about wire lengths. Given it works on a breadboard with wires all over the show I know it will work on strip board too. The advantage of all those loops is if you need to add wires or move things around you usually have enough length to do so. This became important after I made a slight cock up in making the board.

The two board are mounted on an aluminium chassis but back to back. To connect the two boards I am using ribbon cables. I spent a lot of time working out how to attach the connectors to the cables to make sure physically things would plug together. The IDC connectors I used are keyed so you need to get this right. In my mind the connectors on each board would have identical pin layouts. In my mind I was thinking there are two board, laid in line so the ribbon is a simple straight connection. So I built the daughter board like that, with the IDC pins the same as on the CPU board. Unfortunately I am running the boards back to back which means the pin connections on the cable are effectively reversed! So after building it I realised my mistake then had to reverse all the pin connections on the daughter board. Luckily that wasn’t difficult to do.

It’s a bit tricky to get your head around (well I found it so hence the cockup!) but the pictures will help.

IMG_3086_1 IMG_3090_1

IMG_3093_1 IMG_3095_1

I added mounting brackets to the existing aluminum base plate so all the hardware can be mounted in a chassis soon. One mount needs a slot cut in it to run the ribbons through. The whole thing is compact but with some cooling space and all the delicate birdsnest wires are protected.


I haven’t yet wired up the cables to connect the ports to appropriate D type connectors. I will use a DE9 for the serial output (male) and a DA15 for the joyport (male) and a DB25 for the general purpose IO port. These connectors will go on the back of the chassis. I am still thinking about the main box to put all this in. I am thinking steel with wooden ends (ok that’s a bit 70s rather than 80s) with the steel painted crackle black (inspired by my car instrument panel and the finish on Enigma machines).

Everything has been tested with jumpered wires though. The analogue inputs work great and the push button hack seems to work well too. It’s certainly all easily workable in BASIC too. With the IO port LEDs it easy to write little programs to read a pot and light up LEDs. Or to produce different sounds as you turn the pot. Or to plot points on the screen. I only have one pot so will get hold of a small joystick module or, even better, a proper 80s style stick of the kind that used to be used on radio control transmitters. These are really hard to find these days. Dick Smiths used to have them. That was in about 1983 though! Luckily my friend Mike has found one at his place.

Another small change was I made the default text size 40 characters rather than 80 as it looks a lot better on the small LCD screens. On a proper HD tellie 80 columns looks great but these small screens just don’t have the resolution.

I’ve basically spent most of a long weekend working on this and it’s been so much fun. I feel the same enthusiasm for this as I did when I got my first computer when I was 10. Only know I understand exactly how and why everything works. Even so just being able to twiddle a pot and push a button and have that light up LEDs or draw things on screen or make silly noises is a real thrill. Another small thing I did was measure the current consumption. Orwells seems to draw between 400mA to 450mA mainly depending on how many LEDs are on. They are very bright and thats with a 220R resistor in series with each. That small LCD screen is drawing 200mA (at 12 volts). I am not sure what I will do for Orwell. I think I will use a regulator and a bridge on the input so polarity isn’t an issue and it can be run off the same 12 volt supply as the screen. I have a small regulator board now but the heatsink is a little small so it gets quite hot.

Here is a small film showing it working.

As I mentioned Bletchley Park inspired me. I would very much like to create a simulator of the Turing Bombe machine on Orwell if possible. I still need to work out exactly how it works though! A first step however will be making an Enigma simulator as I need that to encode and decode messages. I think that will be a great little project to run on Orwell especially as the results can be checked independently online with other Enigma emulators that can be found.

io board cpu_board

These are just here so I have them somewhere safe!


One Response to “Orwell IO daughter board.”

  1. jeffjjj Says:

    Hi could you make two of these for me?