Saturday, 28 March 2015

Arduino based Pet Disk Clone

Since it's Arduino Day, here is a project a built up a while ago. There is an Arduino UNO under that lot.
I've restored a number of Commodore Pet computers recently (amongst them a 8032 and a 4032), and I've been working on various IEEE-488 devices to plug into them.
It seems every time I mention the Pet, someone suggests I should get a Pet Disk. This is a small board which plugs into the IEEE-4888 port and emulates a floppy disk drive using the files on the SD card. The full details are on the Pet Disk website. I have tried a few times to get one of these, but have not been able to. The project appears to be in the public domain, so all credit to BitFixer, the original author.
I've been thinking about building my own Pet disk drive replacement for a while. In order to get going, I thought I'd start by seeing if I could recreate the Pet Disk as a sort of proof of principle. The hardware details are on the Pet Disk website, it is basically an ATmega8 (and later an ATmega168), and an SD card.
So here is my version, it's an Arduino UNO and an Adafruit micro SD card breakout board. The UNO uses the ATmega328P, similar enough for this purpose, just with more available memory and program space. The original schematic used diode clamping to convert from the 5V of the microcontroller to the 3.3V required for the SD card. Here, the circuitry to do the level shifting with a 4050 rather than diodes is on the Adafruit microSD breakout board.
Power comes from the cassette port on the Pet - the USB socket on the Pet Disk is for power only. The rest is connections to the IEEE-488 port of the Pet. I made up a reusable cable as I'm planning to develop this further.
I followed the same pinouts as the Pet Disk, so I could initially re-use the existing firmware. Here is a table of the various connections.
IEEE-488 Pin
IEEE-488 Signal
ATmega328P pin
Arduino pin
1
DIO1
PB0
8
2
DIO2
PB1
9
3
DIO3
PD2
2
4
DIO4
PD3
3
5
EOI
PC4
A4
6
DAV
PC2
A2
7
NRFD
PC3
A3
8
NDAC
PC1
A1
9
IFC
-
-
10
SRQ
-
-
11
ATN
PC0
A0
12
GND
GND
GND
13
DIO5
PD4
4
14
DIO6
PD5
5
15
DIO7
PD6
6
16
DIO8
PD7
7
17
REN
-
-
18
GND
GND
GND
19
GND
GND
GND
20
GND
GND
GND
21
GND
GND
GND
22
GND
GND
GND
23
GND
GND
GND
24
GND
GND
GND
The SD card connections are shown here. On the original circuit, /CS, DI and SCLK pins have diode clamps to limit the voltage to 3.3V. Power is fed via a diode / resistor dropper. Here I'm using a breakout board which includes the level shifter, so connections are direct.
SD Card pin
SD Card Signal
ATmega328P pin
Arduino pin
Micro SD board pin
1
/CS
PB2
10
7
2
DI
PB3
11
6
3
VSS
GND
GND
3
4
VDD
-
-
1
5
SCLK
PB5
13
4
6
VSS
GND
GND
3
7
DO
PB4
12
5
With that all plugged together, the firmware is loaded via ICSP with a USBtiny ISP. It could probably be rewritten in the Arduino environment, but for the moment I'm using the original firmware.
The Petdisk firmware uses address 9. It should be possible to change this via jumper, but I think there is some problem with that.
Directory listings seems to work nicely. as does loading and listing.
With that working, I can start working on my version. I did some brief testing with a Netduino. This is an Arduino alternative, running the .net micro framework on an Arm processor, I had several left over from a training course I gave last year to a group of software deveoplers who wanted to get into hardware, but preferred to stay with the familiarity of C#. This already had a microSD card built in, and filing system support as part of the .net micro framework. I swapped over the wires and wrote a simple version in C#.
The Netduino is useful for things like IoT devices, you can write a webserver in half a page of code, and for simple I/O such as reading sensors and driving LCD displays. However, it wasn't going to work here as it's I/O was just not fast enough to meet the timing specifications of the bus. So, yes, the 168 MHz Arm Cortex-M4 with code in C# and the .net micro framework couldn't go fast enough for the 1MHz 6502.
So back to the Arduino for the moment. I've written alternative firmware which does basically the same thing as the Petdisk firmware, again as a proof of principal. My aim is something slightly different, rather than the SD card, I have a pair of two megabyte flash chips. The idea being to write what is basically an 8250 emulator. This is a dual floppy drive for the Pet, so the flash devices will be the two floppy drives. That's currently a work in progress. I'm also thinking of getting it to work via USB, so the disk images inside can be accessed via openCBM apps, like the xum1541 style devices I previously built for IEC and IEEE-4888.
In the mean time, I've designed a PCB for the Pet Disk clone, using the smaller surface mount version of the ATmega328P, and going for a 3.3V regulator and 4050 level converter and a microSD slot on the board. Just waiting for those board to come back now. I've kept the original pin out again, so the traces aren't as neat as I'd like.
I normally go for the neatest layout on the board if it's not important which I/O pin is used, so my USB keyboard boards are usually a neat fan out of all the pins, and minimal use of vias.

Update: The PCB version is now complete: http://blog.tynemouthsoftware.co.uk/2015/04/petdisk-clone.html

Update 2: I've now designed a cut down version of petSD running NODISKEMU firmware, in a similar form factor, this is pet microSD.