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!


    Friday, 1 May 2020

    Computer Controlled Robots


    Well I seemed to have a built another Commodore VIC20 controlled robot.  Some inspiration came from the classic 1980s Usborne How to Make Computer-Controlled Robots book.


    You Will Need:

    Initial Testing:

    I started off by connecting the Maker Drive to the user port on my Commodore VIC20 to see if I could control it by using some simple BASIC POKE commands, this worked well so I purchased a CamJam Edukit 3 Robotics kit.

    Maker Drive Features:
    • Dual channel, Bi-directional control motor driver
    • Support motor voltage from 2.5V to 9.5VDC
    • Maximum current up to 1.0A continuous and 1.5A peak (<5 seconds)
    • 5V Output (200mA) to power the controller.
    • Inputs compatible with 1.8V, 3.3V and 5V logic (Arduino, Raspberry Pi, etc).

    Connection Diagram











    Maker Drive:  Motor Driver




    Maker Drive connected to a userport adapter and small DC motor

    Taking the Maker Drive for a spin


























































    Building the Robot:

    Some time later the CamJam Edukit 3 arrived, in the kit are all the parts you need to build a robot.  I decided to use the box it came in as the chassis as suggested in the instructions which can be found here.

    Kit contents

















    I followed the instructions and soon had some motors stuck in the bottom if the box, I made a hole to pass the wires through. I also mounted the supplied line following sensor to the bottom of the box.










































    Having successfully mounted motors etc, I needed some way of connecting the userport to the Maker Drive board so I made up a little board with an IDC connector and a pin header to plug the Maker Drive into.

















































    I then connected the robot to the user port on my VIC20 via a interface board I made for the VIC20 controlled tank I built a while back.  With all the wiring in place, I tested the motors to make sure they worked correctly. 

    Motor Test Coding:




















    Memory location 37138, known as the data direction register (DDR), determines which of the eight user port data lines are inputs and which are outputs.

    Memory location 37136 is the address of the user port.


    Connector Pins
    L
    K
    J
    H
    F
    E
    D
    C
    User port data lines
    PB 7
    PB 6
    PB 5
    PB 4
    PB 3
    PB 2
    PB 1
    PB 0
    Maker Drive Inputs




    M2B
    M2A
    M1B
    M1A
    Decimal value
    128
    64
    32
    16
    8
    4
    2
    1

    Some example code:

    By typing in different decimal numbers, this turns on the relevant user port data line which will make the motor go forwards or backwards. POKE 37136,0  turns off the motor.

    POKE 37138, 255   # This sets the user port data lines as outputs
    
    10 POKE 37136, 0
    20 PRINT "TRY A NUMBER"
    30 INPUT X:POKE 37136,X
    40 GET A$:IF A$="" THEN GOTO 40
    50 GOTO 10