Sunday 31 January 2021

Ben Eater : 6502

 Ben Eater is a remarkable electronics teacher and the 6502 video series continues to demonstrate the high quality he has brought to previous projects.  I am excited to get started with my new 6502 microprocessor kit.

The 6502 microprocessor comes from a simpler age, its data sheet has only 32 pages and it needs no ancilliary components; it conveniently uses 5V power.  We put the processor on a breadboard and connect a few pins to get started:

  • four inputs used for control purposes are set to high and a reset button which can be set low to reset the processor
  • for a clock input use the Ben Eater clock module; it allows us to run the processor slowly or single step it in the course of setting up and testing our hardware
  • connect a few LEDs to the first 5 address pins
When we apply power and start the clock ticking we see LEDs flashing showing that the processor is doing something, although we dont know what.

An effective way of finding out what is happening is to use an Arduino Mega to monitor the 16 address and 8 data pins.  We also want to check the status of the read/write pin.  A simple sketch, using interrupts reads each pin with the clock ticks and displays address/data values on the serial monitor.
As the data pins will be read at some stage we hardware values 11101010 (0xEA)  using resistors to the data pins.

In conjunction with the manual we see that on reset there is a 7 cycle initiation sequence which reads the reset vector from memory address FFFD and FFFE. Our read operations always return 0xEA so the reset vector read in is an address EAEA and we can see that the processor starts executing a program from that address.   Each instruction read in will also be 0xEA, which was conveniently chosen as it is the NOP instruction.  We can see from the Arduino serial monitor that the processor continuously reads and executes NOP instructions (which each take two cycles) and increments the program counter.


Amazingly without knowing very much at all we have an understanding of where we need to load our programs and we can see the simple NOP program running.  Good progress for our first hour.



Thursday 28 January 2021

DIY Oscilloscope

Occasionally I need to use an oscilloscope to look at a wave form.  They cost about £200 which is quite expensive for something I would only use a couple of times a year.  They are also quite complicated and it is potentially difficult to find the view that you want.

A few years ago I used PC based software which worked in conjunction with a PC sound card to work as an oscilloscope.  The input is taken from signal and ground into the PC jack plug which is + or - 0.7V.  The sound card then provides 16 bit samples at 44,100Hz.  A quick look reveals that these programs are still available, for example Christian Zeitnitz or TorVergata.  A problem with using the PC sound card is that you have to make sure your input does not exceed 0.7V, otherwise you could damage the sound card or PC.

More recently I have seen Arduino based solutions and as soon as you start looking there are loads of them.  The first one I chose to look at is at electronicsforu. A simple sketch runs on an Arduino nano to capture a signal on an ADC (Analog to Digital Converter) pin and send it through the serial interface to the PC.  A simple program pcscope.exe runs on the PC to discover the arduino and display the serial data as a wave form.  This is about as simple as you can get and it works without other components on a 5V circuit and only requires a signal/ground connection to the circuit under test.  I may look at other more sophisticated solutions in due course. The pictures below show a bit of debuggin on my Ben Eater clock module flashing at about 1Hz.  The arduino nano takes its signal from the 555 timer output via the white wire and the PC displays the output wave form.


Of course once you start looking at these free solutions other ideas come up.  Oscilloscope for ipad costs £10 and looks good for audio signals but it is probably not suitable for electronics.  More fun would is a build your own JYE Tech oscilloscope, available from Amazon for £30.  It wouldn't be very accurate but it should do the basics.

A real oscilloscope would be worthwhile if I want to spend any time learning how to use it.  Probes and electronics need to be good quality to get results so spending £200 on something like a Hantek DSO5102P (reviewed by my heros Rui and Sara Santos at RandomNerdsTutorials) would be reasonable. 

 


Monday 25 January 2021

Ben Eater : Clock

 Ben Eater is a wonderful teacher of digital electronics.  As I watch his youtube videos I am always amazed at how clearly and concisely he can explain and demonstrate circuits.  His big project was a set of videos explaining how to build an 8 bit microprocessor up from TTL components which I greatly enjoyed.  More recently he has shown how to make up a system based on the 6502 microprocessor.  Both sets of videos make me itch to follow his instructions to make my own system.  He has been kind enough to make available kits of parts containing everything needed to build his projects so I will do just that.  

Complete 8-bit CPU

It would be amazing to construct the 8-bit uproc but I don't know that I would have many uses for it once finished.  I have very fond memories of the 6502 from my youth, I used it at work around 1980 at British Aerospace and found its assembler language sensible and simple compared to other hardware languages I had to use at the time.  The 6502 was hugely successful and formed the basis of the Apple IIe, the BBC micro, Ataris and many others so I am looking forward to being reacquainted.  One of the many blessings of a daugher-in-law from California is that it makes it easier to purchase Ben Eater kits and get them back to England so I am now the proud possessor of 6502 kit and clock module.



The clock module is the first step of the 8-bit uproc project but is also useful for 6502 testing.  For a processor the actual clock speed will be 1MHz or greater, but when testing the system it is useful to be able to run the clock very slowly (c1Hz) or even single step it.  The 555 timer provides many different functions, it has been sold since 1972 in huge quantities. The Ben Eater clock circuit utilises three 555 chips to build our testing clock and demonstrate how it is configured.

There is a set of 4 videos, the first three going through configuring 555 as an astable, monostable and bistable device and the fourth one adds some simple logic gates so that we can produce a single tick or a regular tick-tock.  Ben describes how to choose ancillary resisters and capacitors to achieve the desired effect, how to connect the circuits and some additions to make the circuit more reliable by "debouncing".






Tuesday 12 January 2021

Arduino MP3 Player : Talking Sums

Back in November I blogged about a tiny board, the size of a microSD card holder, which plays sounds and music.  Although I liked the idea, I ran into big problems using the weird AD4 format required for sound files on the SDcard.  I saw that the DFPlayer mini is newer and supposed to be much better (and cheaper) so I ordered some.  I am pleased to say it is wonderful; sound quality is impressive, Arduino support / compatibility is  fine; it permits lots of storage, has plenty of features and it is very, very cheap. 

For my purposes, spoken word sound files are more interesting than music for which I already have various solutions.  As a proof of concept I will write a simple Arduino calculator sketch which speaks the numbers, operators and result as you type.  This is probably very similar to a number of kiddies electronic toys.



The first steps are to find out how it works and  produce some sound.  The definitive reference is at the DF Robot product page  which includes specs and links to a manual and wiki. The wiki shows a simple setup requiring only 5 connections (VCC, GND, SPK1, SPK2 and IO 1) to play sounds.



 I put a few music tracks by the incomparable Ariane onto a 2GB FAT microSD card as /mp3/0000.mp3, /mp3/0001.mp3,......  I then connected a small speaker and power on a bread board.  When I touched pin 9 (IO 1) to GND music began to play.  Very impressive and pretty good quality!

There was some distortion in the music so I amended it in Audacity normalising it by -6db so that the peak values were reduced  and lowering the sample rate from 320kbps to 192kbps.  Sound quality is now very good, even on the dodgy speaker I am using for testing.  It is also possible to use the DAC outputs (DAC_L, DAC_R), but I didn't try that.


Next we want to connect an Arduino to DFPlayer which uses a serial command interface for full control.  It requires just two pins for serial transmission.  As we still want to use the Arduino RX/TX pins for the Serial Monitor we connect a couple of PWM GPIO pins and use the Arduino SoftwareSerial functions to program them.  




We also download the DFRobotDFPlayerMini library which gives us a set of functions to control the player.  Some articles (e.g. instructibles) use the command interface directly, but it is better and easier to use a library.  The samples provided aren't very exciting but they do show you how the sketch should be set up and the different functions which are available.  I was quickly able to provide a sketch to choose a track and start it playing.

Our objective is a talking calculator.
As the DFPlayer can store thousands of samples, a whole dictionary in fact, it is perfect for spoken instructions or feedback.  I couldn't find a good set of mp3 words on the internet so I set up some of my own.  It was easy to record the digits 0 to 9, and operators plus, minus, equals using a headset and Audacity software.  I recorded them as a single file with short pauses inbetween.  I could then select a snippet and save it as 0000.mp3, 0001.mp3 etc.

A simple function within the sketch speaks whatever you type and then the result.  For my POC I only dealt with single digits, non-negative numbers, addition and subtraction.  The result was very gratifying.

My verdict is that this is a great little tool.  Addition of a chip and a small speaker gives an extra dimension to your Arduino projects which can tell you what to do and describe results to you.