Thursday 20 April 2023

6502 : BEN2 : LCD

Intro

A blinking LED is a big step forward in terms of my soldering and making a more permanent, more reliable board.  However we have only progressed as far as part 2 in the Ben Eater 6502 video tutorials.

Assembly

Whereas Ben uses VASM assembler I use CA65 which has better capabilities for me.  BEN2 has the capability to download machine code from a sketch running on the attached Arduino Mega without the need to remove the ROM for programming.  This is the main difference / enhancement from the original Ben circuit.

This was a procedure I developed for previous boards, there are a number of steps to achieve this:

  1. Write a program using Notepad++ on Windows
  2. Compile and link the program using CA65/LD65 into machine code
  3. Convert machine code to a C source file containing the data in an array.
    I wrote a little C utility program to do this
  4. Build the sketch containing the data and download to the mega.
  5. Run the mega sketch which transfers data to the AT28C256 ROM
  6. Reset the 6502 and run the program
Steps 4 and 5 can be run from a Windows command line using a utility arduino-cli.  This enables us to incorporate all the compilation and download steps into a single batch file with suitable checks to highlight any errors.  It make for an easy development cycle, which is very helpful because my programming isn't very good.

Another helpful tool to assist with program debugging is an enhancement to the monitor sketch which outputs address and data bus information.  As each instruction is read in I check the instruction code and show the mnemonic on the Arduino serial monitor.  As we know how many cycles each instruction takes we can highlight each mnemonic as it is executed.

Clock Speed

Previous Ben boards I have built have failed when a full 1MHz clock is used.  Initially, using the Ben Eater clock we can single step through a program and then adjust the clock speed when the clock is running automatically.  However the maximum speed for the Ben clock is about 500Hz so running the clock 2000 times faster at 1MHz is quite different.
To help resolve the problem I built a small breadboard with the 1MHz oscillator on.  It has two binary decoders.  The first provides outputs 500KHz, 250kHz,...., 4KHz and the second one which was set up to provide outputs from 16KHz to 4Hz.
Once a program is working with the Ben clock at 500Hz I can scale it up in increments to 1MHz to check that it still works.

I followed this approach with the LED blink program.  Each flash of the LED takes about 20 cycles so the LED flashes at about 25Hz when the Ben Eater clock is running quickly and this is about the fastest speed that you can clearly see the LED flashing.
In order to test the 1MHz oscillator I needed to slow down the blinking process.  I did this by putting a delay in the blink program using X register to loop counting down to 0 which introduces a delay of 5 cycles per iteration and about 1000 cycles in toal.  It causes the LED to blink very slowly.  I could then increase the oscillator clock speed.  The completed blink-slow program slows blinking further using an outer loop with the Y register and I successfully ran the program at 1MHz.



This represents another major step forward for me as I haven't been able to run programs reliably at full-speed or have the capability to change the clock speed over its entire range.

LCD

LEDs become very boring very quickly.  Following the same route as Ben's original video 4 I connected the HD44780 LCD to the VIA I/O interface and used the test program to check it was working.  This wasn't difficult as I have run the program on the previous hardware.  We now have a working output device.  On the photo you can see a separate breadboard for the LCD just about see Hello, World! on the display.

Initially I used the Ben Eater clock running slowly to test the LCD and saw the characters displayed one by one.  Once I was happy it was working I used the oscillator at increasing speeds until it was running at full speed.  I also tidied up the oscillator to make it easy to run it at speeds from 0.1Hz to 1 MHz easily. I just attach the white clock wire to a colour coded breadboard wire.



No comments:

Post a Comment