Binary Counter — Logic Analyzer

Build an LED Binary Counter & Improve The Code — ArduSeries #88

J3
Jungletronics
3 min readDec 20, 2019

--

Hi, Let’s make an 8-bit counter with Arduino and use it to study this Logic Analyzer 24 Mhz8CH:)

Fig 1. An 8 channels Logic Analyzer from China :/ How it works?

To see how it works let’s bring some codes for discussion: Counters!

[TODO: COUNTING GIFS CIRCUIT WORKING GOES HERE]

Let’s initialize with some of the easiest counter codes there is to learn, then put some science and experience on it, for finally, use that cheap Logic Analyzer (24 MHz 8 Channels) and see how it works:)

Fig 2. First, prepare your Breadboard for all this lab: 8x LEDs, 8 x 220 Ohms Resistors, Arduino and jumpers:)

After building a breadboard, here is the first program (please see this video from Paul McWhorter):

The purpose is to test the hardware (There are any LEDs burned?)

The First Code — Testing The Hardware

Fig 4. The purpose of this code is to test the hardware; all 4 LEDs will be turned on

As you know there are many approaches to coding the 4-bit counter in Arduino; here I present what is probably the most obvious code ever. Let’s make the real 4-bit counter (brute force approach):

The Second Code — 4-bit Counter

Fig 5. This code counts from zero until 15 (4-bit counter); it consumes 1528 bytes (4% of program storage space) and Global variables use 9 bytes (0%) of dynamic memory:)

Let’s make some improvements on the previous code; the magic number turns out to be variable for easy maintenance:)

The Third Code — 4-bit Counter Improved

Fig 6. This is improved by writing the number to the variable: maintenance is much easier:) it consumes 1660 bytes (5% of program storage space) and Global variables use 9 bytes (0%) of dynamic memory:)

The brute force approach is not applicable for counters greater than 4 bits; for 8-bit we will need to have 255 blocks to cope with all LED’s states :/

Now let’s make some real code:

The Forth Code —Sophisticated 4-bit Counter

Fig 7. This code is extensible; it consumes just 976 bytes (3% of program storage space) and Global variables use 18 bytes (1%) of dynamic memory:)

If you want to understand the code above, please consider watching this video:

Now the last code is for the 8-bit counter:)

The Fifth Code — Sophisticated 8-bit Counter

Fig 8. This code is extensible; it consumes just 982 bytes (3% of program storage space) and Global variables use 26 bytes (1%) of dynamic memory:)

Now let’s read at least 4 channels with Logic Analyzer (24 MHz 8 Channels).

Run the second code (_88_logicCounter_PaulMcWhorter_4bits_02.ino) and see this graph running Saleae Logic Analyzer Software.

Fig 9. 4-bit Binary Counter displayed in 4 channels; the initial duty is .5s, and the next is .5s/2 and so forth…

Now run the last code — 8-bit counter () and you should see 8 channels, but unfortunately, I did not make my Chinese & cheap clone Logic Analyzer 24 Mhz8CH work for all channels: only 6 worked (and I do not discover why…may you help me?)

Fig 10. 4-bit Binary Counter displayed in 6 channels; see that channel 2 (70ms) is equal channel 1 * 2 which is 35 * 2 = 70 ms; so channel 3 is channel 2 * 2 = 140ms and so forth…

And that’s all.

Thanks for reading.

Have a comment? Do you know how to configure all 8 channels of this device? Please let me know below…

Bye!

Download All Files For This Project

Related Post

PIC 18 I2C — External EEPROM Interfacing external EEPROM with PIC Microcontroller — I2C — Episode # 01

Credits & References

Arduino Tutorial 6: Build an LED Binary Counter by Paul McWhorter

http://fritzing.org/projects/arduino-8-bit-binary-led-counter

<Edited: Feb 2024 — Minor text fix and link>

--

--

J3
Jungletronics

Hi, Guys o/ I am J3! I am just a hobby-dev, playing around with Python, Django, Ruby, Rails, Lego, Arduino, Raspy, PIC, AI… Welcome! Join us!