{,not} easy things

<-- home

Projects: Z80-based Single Board Computer with size of a credit card

Z80 Card

Introduction to the series and the project

I always wanted to publish things that I make and share the efforts, notes and effects of my work, so this series will be start of moving things out from folders on my disk to Github repositories.

I neglected habits I made long time ago regarding using version control so most of published projects will be a one-and-only commit kind of repository. Maybe that will change this year, maybe.

When I first stumbled upon Z80-MBC project I thought What a clever idea! I never had a chance to use any old microcomputers like ZX Spectrum because my journey with computers started with a PC, but I always wanted to see how it was like to use the old software like CP/M or Microsoft Basic on real hardware. Back then, I didn’t have enough experience do make this project (or to be more precise, debug it if anything goes wrong) so I bookmarked it. When the second, much more polished version, Z80-MBC2 was published out, I was too busy with other stuff to look into the details and to try to build it myself. Finally, couple years later I decided to make one. Nowadays I prefer SMD components, as they are really easy to swap and, in case of sizes like 0805, really easy to solder. I looked into this project again and found out that Zilog still produces Z80 processors! They also have LQFP variant so I thought it may bee a good idea to recreate whole Z80-MBC2 project to use only SMD components. The more I looked into project notes and the schematic, the more improvements I wanted to make.

So I grabbed all needed files from project page and got to work.

Quick rundown on Z80-MBC2 project

Contrary to other computers with Z80, this one uses additional MCU to do almost all work that was always carried by a bunch of 74xx chips, GALs, PALs, CPLDs or other programmable logic. The MCU in this case is ATMega32 and it manages memory and peripheral access, generates clock for Z80 and communicates with all external peripherals like SD Card or Real-Time Clock. That way, only 4 chips(Z80, ATMega32, SRAM and 74HC00) are enough to build an entire computer - pretty neat! The firmware that controls it is called IOS (Input/Output System) and is written in Arduino with MightyCore as Middleware/Board Definition for Arduino IDE.

What improvements are there comparing to MBC2?

The most important one is integration - all supported expansions are neatly integrated into PCB. USB port has USB to UART converter, in this case CH343G that’s fairly new, but works even without dedicated drivers thanks to USB-CDC mode. By redesigning level shifters for SD Card SPI, ATMega can always be reprogrammed by UART bootloader, and with use of CH343G and RST circuity, it works out of the box. MCP23017 in SOIC version is also there as useful GPIO expansion. There is even RTC with built-in battery and charging circuity!

Challenges of this project

I had given myself simple requirements: Components should be SMD type and the cost shouldn’t be over-the-top. As I didn’t have any space constrains, I made the stupid decision to go with dimensions of ID-1 card (the same dimensions as credit cards used since I can remember) and made myself suffer trying to route this with only two layers. Fortunately, at 8MHz signal integrity is not that big of an issue and decoupling seems to be more that enough. But no chance getting this thing to pass any EMC/EMI tests, not with that 8MHz clock line routed with no reference planes or ground plane all over the place, barely stitched together. But hey, it can be produced on cheap!

New things I tried this time:

I: Using autorouting to help iterating on placement of the components

I wanted to try out TopoR for quite some time now. The idea to use it to route the signals I care about and see where autorouter will try to sneak the signals seems pretty useful. I have no confidence to use built-in auto-placement or full auto-route, but using is as a pre-check tool to see if current placement is suitable or not? Why not! This type of workflow worked quite OK - I was able to decide on orientation and position of main ICs quite quickly and go to manual routing from there.

II: Teardrops and rounded tracks

Another nice addition to toolset that I haven’t used with any complicated board before. And to my surprise, the effects are really nice. There are caveats: Addon for rounding tracks from Mitxela will break design rules and the operation it not reversible, so rounding has to be the last operation to make on PCB. What is more, all tracks have to be routed in more relaxed way to accompany for this operation, just to avoid DRC errors after rounding.

When I was testing board I found small mistake (mixed SDA and SCL for the RTC chip) and had to fix it with tracks already rounded, so in my opinion it’s only good if you always have up-to-date copy of PCB file before rounding and stick to the workflow, otherwise it will bite you!

Regarding teardrops: that’s another story. Even using external plugin for KiCad 6, it was really easy to add and remove them at any time, and now with this functionality integrated into KiCad 7 it’s the same, with more options. Teardrops adhered to DRC by being copper pours and worked on any shape. The important thing there is to make sure that track connected to via or pad is always routed to it, not only touching the copper because without this teardrop won’t generate.

III: KiCad 7

Though the first revision was made using version 6, I fixed couple of thing with newest stable release of KiCad. I’m a big fan of this software, it’s a joy to use - all functions are simple to understand, UI is really great and library conventions and the way the whole set of programs (EESchema, PCBnew) works is straightforward. While I don’t think it fully viable alternative to paid ECADs like Altium Designer now, it 2-3 years time it will be able to replace it in most applications. KiCad 7 bridged a lot of gaps to those professional tools.

Experimenting with the board

Well, I was exited to see that author of Z80-MBC2 managed to run FUZIX, but sadly, it was only a demo. I couldn’t get it to work, and debugging where the kernel i built fails to load seems like a challenge for future me. But other software like CP/M worked. Documentation and demos are available on author’s site and many other places on the internet. I was happy to see them working, especially demos written in BASIC - I could not imagine using this today being used to all the fancy IDEs with code completion and syntax highlighting. But it is fun, considering you can find some old books used to tech BASIC and try out code from it. I know, BASIC can be run even in web browser now, but having dedicated machine for it is way more fun.

Upon connecting and holding USER button, following (or similar, depending on version) message will appear:

Z80-MBC2 - A040618
IOS - I/O Subsystem - S220718-R120519_DEVEL4

IOS: Z80 clock set at 4MHz
IOS: Found RTC DS3231 Module (04/03/23 20:11:54)
IOS: RTC DS3231 temperature sensor: 18C
IOS: Found GPE Option
IOS: CP/M Autoexec is OFF
IOS: Current Disk Set 3 (UCSD Pascal)
IOS: Loading boot program (FUZIX.BIN)...

Z80-MBC2 - A040618
IOS - I/O Subsystem - S220718-R120519_DEVEL4                                    
IOS: Z80 clock set at 4MHz                                                      
IOS: Found RTC DS3231 Module (04/03/23 20:12:00)                                
IOS: RTC DS3231 temperature sensor: 18C                                         
IOS: Found GPE Option                                                           
IOS: CP/M Autoexec is OFF                                                       
IOS: Select boot mode or system parameters:                                     
 0: No change (3)                                                               
 1: Basic                                                                       
 2: Forth                                                                       
 3: Load OS from Disk Set 3 (UCSD Pascal)                                       
 4: Autoboot                                                                    
 5: iLoad                                                                       
 6: Change Z80 clock speed (->8MHz)                                             
 7: Toggle CP/M Autoexec (->ON)                                                 
 8: Change Disk Set 3 (UCSD Pascal)                                             
 9: Change RTC time/date                                                        
Enter your choice >

I really like this kid of interface, it reminds me of test mode present in old measurement equipment.

Pain of UART overflows

While ATMega32 can be quite fast with 16MHz clock, running all memory management for the Z80 hinders it’s ability to process input from UART. If you want to paste the program to BASIC prompt, you will be welcomed with missing characters or whole sections of data. The problem quite well known for embedded systems - without good implementation of UART FIFO and system capable of processing the data, overflows are bound to happen. But there is a remedy - if you just add delay between each character that you are sending, it should give MCU enough time to process it and free up the buffer for next byte. The option can be called differently between programs, for minicom it’s called Character TX Delay and for GNU screen, slowpaste is the keyword to look for. It was frustrating to look for this option in documentation for both programs, fortunately describing the problem and looking on StackExchange gave the answer I was looking for.

OK, but what if the fun with BASIC and CP/M is over?

Then the whole project can be an excellent test bed for any C functions that I would want to keep as portable as possible. There are emulators, but when running C programs on real hardware is so easy, I see no harm in doing so, especially when you can also blink an LED or two to get yourself a physical feedback.

Where I can grab the files?

Here! Not a lot of documentation, but most of questions are already answered in Z80-MBC2 forum posts somewhere on the internet.