The Most Powerful Debugging Tool Ever – The LED

Originally Posted June 2011 : Paul J Clarke CEng MIET

There was a time when debugging was not easy. In this blog I want to share some of the stuff I used to do to debug code and hardware – the hard way. So going back to when I started out in the 80’s there were few fancy debugging tools and the ones that were around were expensive.

There was a time when debugging was not easy. In this blog I want to share some of the stuff I used to do to debug code and hardware – the hard way.

So going back to when I started out in the 1980s there were few fancy debugging tools, and the ones that were around were expensive. In my first job we used Z80 processors, which was good because I’d used them when playing around with my ZX81 and ZX-Spectrum. Getting a board to work the first time was not easy. Current micros can be loaded with code, but a processor needs RAM, ROM etc. to get you started.

Once the first board was made, I’d put some basic code in to just loop. To test if it was working, I would disconnect the clock and run it from a 555 timer at about 3Hz. Yup that’s right, very slow! I would have LEDs hanging off the Data Bus and Address Line. In fact, I had a header that would fit between the CPU and the board. This way I could see the lines of code running. After that I would progress to getting an I/O line working, slowly adding more and more code, testing each part of the board bit by bit.

Over time, we got a working CPU board that would run code and address RAM and ROM correctly. It was not a massive task to test and develop, but it was important to get right early on. After this and getting an I/O port working, you get to the point where we are today with current micros and can have a blinking LED – the first universal debugging tool!

Many of my designs still have a place for a LED on an I/O pin. This is normally used as a heart beat indicator. That is, every time the code loops around, you toggle the LED and are able to see that the board and micro is still running.

The blinking LED is, however, a very important debugging tool that I think people forget about today even with modern circuit debugging tools. Consider this: The faster your LED blinks, the quicker your code is looping! Now hook this to an oscilloscope and you can monitor your loop time for the micro and detect when big step changes happen during events.

Another use of our Blinky LED is for interrupts. Turn the LED on when entering an interrupt and off again when you exit. From a visual point of view the more your LED is on, the longer you are spending inside your interrupt code resulting in less time running normal functions. On a scope you can monitor what percentage of time your code is spent inside the interrupt code and if external events affect it. All this from an I/O pin output!

After the LED, we used to hook up a Display or a UART for serial communication to a PC. This then allowed for visual monitoring of values inside the chip and software. Today this can be done with in-circuit debugging tools connected directly to dedicated code or hardware in the chip. At one point in time I even designed my own in-circuit debugging tool for a Z80 CPU that allowed single stepping of code. However, I still feel that by far, the most useful debugging tool is a single I/O pin and a blinking LED.

Previous
Previous

Making My Own PCBs

Next
Next

The Dyslexic Engineer