Wednesday 11 September 2013

Commodore PET Project Part 2 - Screen and Keyboard

This is an old post, preserved for reference.
The products and services mentioned within are no longer available.

Following on from Part 1 of my Commodore PET Project, which looked at the history of this particular Commodore Pet 4032, the question is 'What are you going to do with it now?'. Well, I expect the biggest problem is going to be driving the display, so I concentrated on that first. The Arduino 80x25 TV out library I recently published was a starting point, but that was designed to output standard PAL / NTSC video signals. That is vertical sync of 50 or 60 Hz, and a horizontal sync of 15.625 KHz. The dot clock (the rate the pixels are sent out) is around 16MHz.
The PET needs separate horizontal and vertical sync pulese. I tried various methods to generate this, from simple RC filters to TTL counters, however, whatever I feed to the PET monitor, it wouldn't display it. Checking the output from a working pet, it appears to be more like 50Hz and 20KHz, and the pulses were considerable longer. The VSync was 50Hz (20mS) with a 720uS pulse, and HSync was 20KHz (50uS) with a 14.6uS pulse  I've updated the video processor code to run on an ATMega664. This gave me some additional I/O to allow H sync and V sync to be generated separately, and allowed me to increase the dot clock to 20MHz. This allows the system to use 1000 clock pulses per line (1000 clocks at 20MHz = 50uS = 20KHz). Allowing 292 pulses to generate the 14.6uS sync pulse (to match the original pet), and 640 pulses for 80 characters leaves 68 pulses at the end (3.4uS).
The video output is generated from a 74LS165 shift register, as before. This time, I'm using a Leonardo to drive the video processor, although it will be an 238P in the final build. I then tweaked the lengths of the sync pulses to match those generated by a real PET and now the display is working fine.
It seemed only right to use the Commodore Pet bootup text demo to test it. Here it is with an 8032-SK for comparison (yes, I know I forgot the space before the memory free line). The 8032-SK has the same 12" monitor and probably the same universal pet board as the 4032 would originally have had.
Next came the keyboard. It's an 8x10 matrix, and I have used many similar keyboards in my USB Keyboards, so it was just a case of adapting that code.
Rather than have lots of wires, I used two I2C I/O expanders (an MCP23008 and an MCP23016) on a small board at the keyboard end, so just needed 4 wires (VCC, SCK, SDA, GND) to connect from the board to the video processor chip and the interface microcontroller. So keyboard and monitor working. I/O handled via I2C, display handled by the display processor.
The first test was to simply send the key presses from the keyboard, suitably remapped, to the display. So for the first time in many years, pressing a key on the pet keyboard display the appropriate character on the pet screen.
Next, I tried Tiny BASIC, as I had in the previous tests of the 80x25 text out testing, and it was a basic computer, albeit with 1K free memory. Now, it was possible to type in a program an run it, again for the first time in many years.
To make it more powerful, the Arduino becomes just an I/O processor, taking key presses in and sending them over the serial port, and reading back the serial port to display it on the screen. Add a MAX232 and you've got an RS232 serial terminal - I'll be doing that later.

Add something more powerful and you've got a usable computer. In the next article, I'll be doing just that.

Update: This PET has now been fully restored