Saturday, 10 October 2020

6502 Computer Adventures: Part 2

 

Previously I connected up the 6502, now it was time to get the CPU to actually do something so I connected some LEDs to a couple of the address bus (pins 9- 13). I powered both circuits using a couple of AA batteries, success the LEDs started to blink randomly. 











W65C02 Pinout












Enough of the randomness I actually wanted the CPU to do something.  I hardwired the data bus so the CPU would be forced to run the same instruction over and over,  the NOP or No operation instruction was a good choice.   This does nothing for 2 clock cycles, usually used to time a delay or fill patches in a program.



I connected 16 LEDs to the address bus so I could monitor what it was doing.   The NOP instruction equates to EA in Hex or 11101010 in Binary. I hardwired the data bus (pins 26 - 33) starting at pin 26, I connected them via 1K resistors like this.

Pin Data Bus Connection
26 D7 +5v (1)
27 D6 +5v (1)
28 D5 +5v (1)
29 D4 0V (0)
30 D3 +5v (1)
31 D2 0V (0)
32 D1 +5v (1)
33 D0 0V (0)


Updated breadboard with the NOP / 11101010 hardwired to the 8 data pins









So I had basically made some blinkenlights, exciting times.  Watching the LEDs connected to the address bus count in a binary was quite therapeutic. 

Arduino Mega monitoring the address and data buses















In the first part of Ben Eater's 6502 videos he connected up a Arduino Mega to the address and data buses and wrote a little Arduino sketch to monitor these.   

Sunday, 4 October 2020

6502 Computer Adventures: Part 1

Inspired by the brilliant Ben Eater videos about building a 6502 computer, I’d thought I would have a go.   

I have a bit of a soft spot for the 6502, having learned 6502 assembler on the Emma II 6502 trainer board  when I was at college.  The board is made by L.J Electronics Ltd.  More info can be found here.

Emma II 











Continuing with the the 6502 trainer board theme, I have an EPE 6502 Micro Lab. The Micro Lab was an Everyday Practical Electronics Magazine project for the Teach-In '93 magazine series during 1993.  The Micro Lab hardware was designed by Keith Dye BEng (Tech) AMIEE and the Micro Lab Monitor software was written by Geoff MacDonald BSc (Hons) AMIEE.

Micro Lab











Micro Lab Technical Specifications

Hardware
Microprocessor6502 8 bit
Clock speed1 MHz
Power5V DC
SRAM32KB with battery backup
EPROM32KB
Analogue Input0-2.5V accurate to 0.01V
Analogue Output0-2.5V accurate to 0.01V
Displays
 
 
16 x 2 LCD with variable contrast
7 segment LED
8 data LEDs
Keyboard
 
 
20 keys, interrupt driven
8 DIP switch data inputs
Reset switch
I/O Ports
 
 
 
 
65C22 VIA providing:
  • 16 individually programmable I/O ports
  • 4 control lines
  • serial output
  • hardware pulse counting

  • Anyway I digress...

    Clock Module

    I built the clock module first, this is based on Ben Eater's clock but I only built the first part of his circuit. It uses the classic 555 timer configured in astable mode to provide the clock pulse.  The clock is adjustable-speed (from less than 1Hz to a few hundred Hz).  All computers require a clock pulse, this triggers the processor to perform each instruction.  

















    The CPU


    I'm using a modern version of the MOS 6502 which is made by WDC. The 6502 was used in many classic computers including the Atari 2600, Apple II, Nintendo Entertainment System, Commodore 64, Commodore VIC20 and the BBC Micro.

     






    WDC’s updated W65C02S version of the legendary MOS 6502 has new opcodes and various improvements on the original. The “C” means CMOS, “S” static – unlike the dynamic original, registers are maintained without the need for a continuous clock. This means the CPU can be clocked extremely slowly or even stopped without any loss of data.

    W65C02










    Connecting up the CPU


    W65C02 pinout














    • Pin 21 to ground and 5V to pin 8 will power the 6502.
    • Pins 2, 4 and 6 are tied high through 3.3K pull-up resistors as does pin 38, Set Overflow(SOB) and pin 36, Bus Enable(BE)
































    To get things going the CPU requires a low signal on pin 40, reset. This simply means connecting the pin briefly to ground. A push button should do, although ideally the button would be properly debounced.  I have built a debounce circuit based on a 74HC14 which debounces the reset button and gives a clean reset signal.














    Finally the clock signal input on pin 37.   With the data and address bus unconnected, it does absolutely nothing!