Silicon ChipMax’s Cool Beans - September 2024 SILICON CHIP
  1. Contents
  2. Publisher's Letter: Hello from the other side of the planet
  3. Feature: Techno Talk - I don’t want to be a Norbert... by Max the Magnificent
  4. Feature: The Fox Report by Barry Fox
  5. Feature: Net Work by Alan Winstanley
  6. Subscriptions
  7. Project: Build Your Own Calibrated Microphones by Phil Prosser
  8. Feature: Using Electronic Modules – 1.3-inch monochrome OLED by Jim Rowe
  9. Project: Modern PIC Programming Adaptor by Nicholas Vinen
  10. Feature: Circuit Surgery by Ian Bell
  11. Back Issues
  12. Feature: Audio Out by Jake Rothman
  13. Feature: Max’s Cool Beans by Max the Magnificent
  14. Project: Salad Bowl Speakers by Phil Prosser
  15. Feature: Teach-In 2024 – Learn electronics with the ESP32 by Mike Tooley
  16. Back Issues
  17. PartShop
  18. Market Centre
  19. Advertising Index
  20. Back Issues

This is only a preview of the September 2024 issue of Practical Electronics.

You can view 0 of the 80 pages in the full issue.

Articles in this series:
  • (November 2020)
  • Techno Talk (December 2020)
  • Techno Talk (January 2021)
  • Techno Talk (February 2021)
  • Techno Talk (March 2021)
  • Techno Talk (April 2021)
  • Techno Talk (May 2021)
  • Techno Talk (June 2021)
  • Techno Talk (July 2021)
  • Techno Talk (August 2021)
  • Techno Talk (September 2021)
  • Techno Talk (October 2021)
  • Techno Talk (November 2021)
  • Techno Talk (December 2021)
  • Communing with nature (January 2022)
  • Should we be worried? (February 2022)
  • How resilient is your lifeline? (March 2022)
  • Go eco, get ethical! (April 2022)
  • From nano to bio (May 2022)
  • Positivity follows the gloom (June 2022)
  • Mixed menu (July 2022)
  • Time for a total rethink? (August 2022)
  • What’s in a name? (September 2022)
  • Forget leaves on the line! (October 2022)
  • Giant Boost for Batteries (December 2022)
  • Raudive Voices Revisited (January 2023)
  • A thousand words (February 2023)
  • It’s handover time (March 2023)
  • AI, Robots, Horticulture and Agriculture (April 2023)
  • Prophecy can be perplexing (May 2023)
  • Technology comes in different shapes and sizes (June 2023)
  • AI and robots – what could possibly go wrong? (July 2023)
  • How long until we’re all out of work? (August 2023)
  • We both have truths, are mine the same as yours? (September 2023)
  • Holy Spheres, Batman! (October 2023)
  • Where’s my pneumatic car? (November 2023)
  • Good grief! (December 2023)
  • Cheeky chiplets (January 2024)
  • Cheeky chiplets (February 2024)
  • The Wibbly-Wobbly World of Quantum (March 2024)
  • Techno Talk - Wait! What? Really? (April 2024)
  • Techno Talk - One step closer to a dystopian abyss? (May 2024)
  • Techno Talk - Program that! (June 2024)
  • Techno Talk (July 2024)
  • Techno Talk - That makes so much sense! (August 2024)
  • Techno Talk - I don’t want to be a Norbert... (September 2024)
  • Techno Talk - Sticking the landing (October 2024)
  • Techno Talk (November 2024)
  • Techno Talk (December 2024)
  • Techno Talk (January 2025)
  • Techno Talk (February 2025)
  • Techno Talk (March 2025)
  • Techno Talk (April 2025)
  • Techno Talk (May 2025)
  • Techno Talk (June 2025)
Articles in this series:
  • The Fox Report (July 2024)
  • The Fox Report (September 2024)
  • The Fox Report (October 2024)
  • The Fox Report (November 2024)
  • The Fox Report (December 2024)
  • The Fox Report (January 2025)
  • The Fox Report (February 2025)
  • The Fox Report (March 2025)
  • The Fox Report (April 2025)
  • The Fox Report (May 2025)
Articles in this series:
  • Win a Microchip Explorer 8 Development Kit (April 2024)
  • Net Work (May 2024)
  • Net Work (June 2024)
  • Net Work (July 2024)
  • Net Work (August 2024)
  • Net Work (September 2024)
  • Net Work (October 2024)
  • Net Work (November 2024)
  • Net Work (December 2024)
  • Net Work (January 2025)
  • Net Work (February 2025)
  • Net Work (March 2025)
  • Net Work (April 2025)
Articles in this series:
  • Circuit Surgery (April 2024)
  • STEWART OF READING (April 2024)
  • Circuit Surgery (May 2024)
  • Circuit Surgery (June 2024)
  • Circuit Surgery (July 2024)
  • Circuit Surgery (August 2024)
  • Circuit Surgery (September 2024)
  • Circuit Surgery (October 2024)
  • Circuit Surgery (November 2024)
  • Circuit Surgery (December 2024)
  • Circuit Surgery (January 2025)
  • Circuit Surgery (February 2025)
  • Circuit Surgery (March 2025)
  • Circuit Surgery (April 2025)
  • Circuit Surgery (May 2025)
  • Circuit Surgery (June 2025)
Articles in this series:
  • Audio Out (January 2024)
  • Audio Out (February 2024)
  • AUDIO OUT (April 2024)
  • Audio Out (May 2024)
  • Audio Out (June 2024)
  • Audio Out (July 2024)
  • Audio Out (August 2024)
  • Audio Out (September 2024)
  • Audio Out (October 2024)
  • Audio Out (March 2025)
  • Audio Out (April 2025)
  • Audio Out (May 2025)
  • Audio Out (June 2025)
Articles in this series:
  • Max’s Cool Beans (April 2024)
  • Max’s Cool Beans (May 2024)
  • Max’s Cool Beans (June 2024)
  • Max’s Cool Beans (July 2024)
  • Max’s Cool Beans (August 2024)
  • Max’s Cool Beans (September 2024)
  • Max’s Cool Beans (October 2024)
  • Max’s Cool Beans (November 2024)
  • Max’s Cool Beans (December 2024)
Articles in this series:
  • Teach-In 2024 (April 2024)
  • Teach-In 2024 (May 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (June 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (July 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (August 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (September 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (October 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (November 2024)
Max’s Cool Beans By Max the Magnificent Arduino Bootcamp – Part 21 (common ground & BCD) T his is getting a little embarassing. For the past few columns, I’ve been promising that we were soon going to refresh our minds as to the concept of binary-coded decimal (BCD) and then investigate various deployments of BCD to 7segment decoders in our evolving clock project. Unfortunately, every time we were poised to plunge into the BCD fray, something else popped up to divert our attention. Well, believe it or not, the frabjous day has arrived. We are finally going to dip our toes into the BCD waters. I’m wearing my “I BCD” T-shirt and socks, so it must be true. In just a moment, we will truly turn our transient attentions to BCD, but first… ❤ Up or down? When we started using integrated circuits (ICs) to implement a 2:4 decoder (PE, July 2024), we ran across the problem of what to do with any unused inputs. Specifically, what to do with the four unused NOT (inverter) gates in our SN74LS04 IC. We noted that there’s a faint possibility an unconnected input, which may ‘float’ up or down, could potentially result in its gate undergoing uncontrolled oscillation, which would consume power and generate unwanted noise in the form of electromagnetic interference (EMI). At that time, I mentioned that when logic gates are unused, as in our example, it’s often left to the designer to decide whether to use pull-up or pull-down resistors and what their values should be. Things become more complicated in the case of partially used gates or functions, but that’s a story for another day. I suggested using 10kΩ pull-down resistors, and they would work perfectly well, but I subsequently received an email from Godfrey Manning, who hails from Greater London (amateur radio callsign G4GLM). Godfrey suggested that, in this case, pull-up resistors would have a slight advantage and would therefore be preferred. A cut-down version of Godfrey’s message is as follows: “Dear Max, I’d like to be frank, only my parents insisted on Godfrey. TTL inputs are floating emitters (multiple emitters on the same transistor where a gate has more than one input). Unconnected, they are functionally logic high, although they won’t read as such with a logic probe. To passivate a redundant gate, it’s therefore best to connect the inputs to VCC [+5V in our case], perhaps via a (value non-critical) pull-up resistor. This way, the gate draws minimal current.” Well, even though we are talking about minuscule amounts of current in this Boy Man BB Player example, we are trying to follow best practices, so I’ve amended my circuit accordingly (Fig.1). To be honest, the topic of pull-up and pull-down resistors could consume a complete column in its own right. For our purposes here, however, we can summarize things as follows: 1. For 74 (TTL), 74H (high-speed TTL), 74S (Schottky TTL) and 74LS (lowpower Schottky TTL), use 1-10kΩ pull-ups or (less commonly used) pull-downs. 2. For 74AS (advanced Schottky TTL) and 74ALS (advanced low-power Schottky TTL), use 2-10kΩ pull-ups or (less commonly) pull-downs. 3. For 74F (fast TTL), use 1-4.7kΩ pullups or (less commonly) pull-downs. 4. For 74C (CMOS), 74HC (high-speed CMOS) and 74HCT (high-speed CMOS with TTL-compatible inputs), use 10-100kΩ pull-ups or pull-downs. 5. For CMOS 4000-series, use 10kΩ to 1MΩ pull-ups or pull-downs. And now for the obligatory ‘weasel words’ (remember that eagles may soar, but weasels rarely get sucked into jet engines): “Always consult the data sheets for the specific components you are using.” We are almost ready to hurl ourselves into the topic of BCD, but first… 8' Boy Man BB Player +5v 6' (+5V) VCC 14 13 6Y 12 11 5Y 10 9 4' 4Y 8 2' 0' 1 2 1A 1Y s1 s1 3 4 5 6 7 2Y 3A 3Y GND (0V) -2' s0 s0 -4' (a) No common ground Fig.1: A better option for our unused inputs. 52 (b) Common ground Fig.2: This shows one reason why having a common ground is important (there are others). Practical Electronics | September | 2024 I don’t know about you, but I’m quivering in anticipation, poised to plunge into the invigorating BCD waters, but first… 3V 3V 2 = 10 3.0 6.0 ?.? 3V 3V 3V 3V (a) No common ground (things can only be measured in isolation) 3V 3V 3.0 3V 6.0 3V 3V 3.0 3V 0V 3V 3V 3V 0V 0V (b) Common ground (things can be measured in relation to each other) Fig.3: A common ground allows things to be measured in relation to each other. Finding common ground As part of the debugging exercise in our previous column (PE, August 2024), we created a set of six logic probes on a half-size breadboard. Although I showed the power and ground wires feeding our probe board as coming from our other breadboards, I mentioned that we could use a separate +5V supply if we wished. I also noted that all the breadboards and power supplies must share (be connected to) the same ground. You may have run across something like this before. It’s not unusual to see a project where a 5V Arduino Uno is being used in conjunction with a 12V servo motor controller, for example. In this case, there will typically be two separate power supplies whose grounds are connected. Have you ever wondered why? Well, make yourself comfy and I shall expound, explicate, and elucidate (I can do all three with one hand tied behind my back while chewing gum!). Let’s start with an analogy. Suppose we have a 4-foot (122cm) tall boy, a 6-foot (183cm) tall man and an 8-foot (244cm) tall basketball player, all standing next to each other and all looking in the same direction. Who will be able to see the farthest? If your knee-jerk reaction is to respond, “the basketball player, of course”, then you’ve fallen into my cunning trap. Although I stated that our three characters are standing next to each other, I failed to mention that the boy is perched on a 4-foot tall box, while the basketball player has been plunged into a 4-foot deep hole (Fig.2a). The point is that my question is meaningless unless everyone involved is standing on (ie, measured in relation to) a common ground (Fig.2b). Keeping this analogy in mind, suppose we have a 3V battery on its own Practical Electronics | September | 2024 and another two 3V batteries connected in series to give a 6V source. Without instituting a common ground, things can only be measured in isolation (Fig.3a). By comparison, once a common ground has been established, they can be measured in relation to each other (Fig.3b). Of course, it’s not simply a case of measuring things. Having a common ground is a requirement for circuits involving multiple voltage sources to perform their magic, but we don’t need to discuss this any further here. When you saw the heading, did you think, “Ah, I know this one. Max means that 10 in binary is 2 in decimal”? If so, then (a) I’m impressed that you’ve been paying attention and (b) you’re wrong (I’m afraid I’m being a little tricky today). To remind ourselves about the status of our clock project, we are currently controlling four 7-segment lightemitting diode (LED) displays. Also, we are restricting ourselves to using only 12 of the digital input/output (I/O) pins on our Arduino Uno. Although the Uno has 14 digital I/ Os, numbered 0 to 13, pins 0 and 1 are reserved for communications with the host computer. Ideally, we want to keep as many of these I/Os as possible free to implement additional functionality in the future. Remembering that our 7-segment displays really have eight segments (seven to represent numerical and other characters, plus one for the decimal point), our original circuit employed eight of our Arduino’s pins to drive the displays in parallel (side-by-side). We used the remaining four pins to directly control four transistors, each of which can activate or deactivate its corresponding display (Fig.4a). The idea No connection Connection D3 Ground (0V) D2 D0 D1 Display segments and pin numbers 5 10 9 1 2 4 6 7 DP G F E D C B A 3 3 3 3 C C C C B B E 13 B E 12 B E 11 B E 10 9 8 7 6 5 4 3 2 Arduino pin numbers (a) Original circuit: Controlling transistors directly = no free pins. Fig.4a: The clock display circuit without a decoder needs 12 pins to drive it. 53 s s Display segments and pin numbers 6 7 D3 D2 5 10 9 1 2 4 6 7 D0 D1 B A DP G F E D C B A 3 3 3 3 C C C C B B E B E B E E y3 y2 y1 y0 2:4 2:4 Decoder s1 s0 Free 13 12 3 2 9 8 7 6 5 4 3 2 11 10 Arduino pin numbers (b) Latest circuit: Controlling transistors via 2:4 decoder = two free pins. Fig.4b: Using a 2-to-4 decoder reduces the number of pins required to 10. is to multiplex our displays, having only one active at a time, but switching them on and off so quickly that our eyes and brains are fooled into perceiving them as all being active all the time. Now, cast your mind back to when we decided to employ a 2:4 decoder to control our transistors (PE, July 2024), shown in Fig.4b. We are using two of the Arduino’s digital I/Os to drive the inputs to the decoder. These inputs can be presented with four binary patterns: 00, 01, 10 and 11. Our decoder uses these patterns to place one of its four outputs in its active state (which is logic 1, in our case). The reason for using this decoder is that it frees up two of our digital I/Os. At that time, we noted that if we ever decide we want to drive five to eight displays, we would have to switch to a 3:8 decoder (with three inputs and eight outputs). That would leave us with only one free pin. Similarly, if we needed to drive nine to 16 displays, we would have to employ a 4:16 decoder (with four inputs and sixteen outputs). That would leave us with no free pins. Purely for the sake of an example, suppose we wished to control ten displays. Although using a 4:16 decoder may be better than being poked in the eye with a sharp stick, it still leaves 54 something to be desired. Is there a better way? Well, hold onto your hat because I’m about to blow your socks off (I can’t help myself; I’m infatuated with idioms). I know how to control ten displays using just two pins with only a slight variation on our existing circuit (hence the “2 = 10” heading). I’ll tell you about this technique in a moment, but first… Combinatorial vs sequential Thus far in our experiments, except for the internals of the Arduino itself, we’ve employed only ‘combinatorial logic’. This refers to logic functions constructed using primitive logic gates (NOT, AND, OR, NAND, NOR etc). They produce an output or outputs from the combination of one or more input but have no memory of anything that has gone before. It’s also possible to use primitive gates Inputs Set Data D Clock C S R Reset to create ‘sequential logic’. This refers to logic functions that remember the past. That is, functions that produce an output or outputs with value(s) that depend both on the present values of their input signals and on the sequence of past inputs. For example, a “flip-flop” is a logic function with two stable states (0 and 1) that can be used to store one bit of binary data. There are a variety of different flip-flop implementations. One common type is called a D-type flip-flop. The symbol and truth table for a D-type flip-flop are shown in Fig.5. I know this appears a bit complicated at first glance, but it’s not as bad as you might fear. As always, let’s take things step by step, starting with the fact that this type of function can be created with just a handful of the primitive logic gates we’ve discussed before. The small circles (called ‘bubbles’ or ‘bobbles’) on the symbol indicate active-low inputs (S and R) or outputs (QB). In the case of the outputs, Q is known as the ‘true’ output and QB is known as the ‘complementary’ output. This is because QB has the opposite or complementary logical value to Q. The (n) and (n+) annotations associated with the outputs in the truth table represent time. In this case, (n) indicates ‘now’ or whatever the value is currently, while (n+) indicates ‘now plus’ or what the value is going to become. In this example, our S (Set) and R (Reset) inputs are both active-low (active-high versions are also available). Also, as we will discuss, the truth table tells us these are both asynchronous, which means they aren’t synchronised to (they act independently from) the clock (synchronous versions are also available). Some flip-flips have only an S input, others have only an R input, and some don’t have either. We know the C (Clock) input is edgetriggered because this is indicated by the ‘>’ in the symbol. Furthermore, the lack of a bobble on this input indicates that this is a positive-edge clock (ie, it performs its magic on a 0-to-1 or ‘rising’ transition). If a bobble were present, that would indicate a negative-edge Q Q QB QB Outputs S R C D Q(n+) QB(n+) 0 1 0 1 1 1 1 X X 0 X X 0 X X 1 ↑ 0 1 ↑ 1 1 ↓ X 1 0 ? 0 1 Q(n) 0 1 ? 1 0 QB(n) Mode Set (Q → 1) Reset (Q → 0) Not allowed Load data Load data Memory Fig.5: The configuration of a typical D-type flip-flop with its logic table. Practical Electronics | September | 2024 clock (ie, it would perform its magic on a 1-to-0 or ‘falling’ transition). The ↑ and ↓ characters in the truth table indicate rising (0-to-1) and falling (1-to-0) transitions, respectively. Finally, X characters in the truth table represent ‘don’t care’ values, while ? characters indicate ‘don’t know’ values. Putting all of this together, the first row in this truth table tells us that when we have an active 0 on the S input (and an inactive 1 on the R input), we don’t care what’s on the C or D inputs because the Q output will be set to 1 and the QB output will assume the complementary 0 value. The next row tells us that when we have an active 0 on the R input (and an inactive 1 on the S input), we don’t care what’s on the C or D inputs because the Q output will be reset to 0 and the QB output will assume the complementary 1 value. The next row tells us that it’s illegal for both the S and R inputs to be in their active states at the same time. If this were to occur, we wouldn’t know what values to expect on the Q and QB outputs. Assuming that both S and R are in their inactive 1 states, a ↑ rising edge on the C input will load whatever value is on the D input into the flip-flop causing it to appear on the Q output (and the QB output will assume the complementary value). Subsequently, a 1, 0 or ↓ falling edge on the C input will leave the Q and QB outputs unchanged. Phew, I didn’t realize this was going to take so long to explain. If you wish to learn more about how we use primitive logic gates to construct functions like our D-type flip-flop, then you will find this topic is covered in excruciating exhilarating detail in my book Bebop to the Boolean Boogie (https:// bit.ly/4a6wDDm). Shift over (a) Serial-In Serial-Out (SISO) shift register Serial data in DFF0 DFF1 DFF2 DFF3 D Q D Q D Q D Q Serial data out Clock (b) Serial-In Parallel-Out (SIPO) shift register Serial data in DFF0 DFF1 DFF2 DFF3 D Q D Q D Q D Q Connection No connection Clock Q0 Q1 Q2 Q3 Parallel data out Fig.6: How to create 4-bit SISO (a) and SIPO (b) shift registers using individual flip-flips. rising edge, in this case) causes whatever value is on the data input to be loaded into DFF0. At the same time, whatever value used to be stored in DFF0 will be loaded into DFF1, DFF1’s value into DFF2 and DFF2’s value into DFF3, at which point it will appear as the serial data output. This all works due to the internal delays associated with the flip-flops. These delays mean it takes time for the new value loaded into a flip-flop to propagate to its output. So the next flip-flop in the chain has time to load the old value being presented to its input before that value changes. Pretty nifty, huh? It takes only a slight modification to create a serial-in parallel-out (SIPO) implementation (Fig.6b). It’s also possible to create parallel-in serial-out (PISO) and parallel-in parallel-out (PIPO) shift registers although a PIPO is really just a bunch of D-type flipflops sharing a common clock. Both examples shown in Fig.6 are unidirectional. This means they shift data in only one direction, which we could think of as ‘to the right’ in this case. However, it’s also possible to create bidirectional versions that can shift ‘left’ or ‘right’ as defined by a control signal. We can even create a ‘universal’ shift register that supports bidirectional serial-in serial-out as well as parallel-in and parallel-out if we want to get fancy. Did someone ring? It’s taken us a long time to get here, but we can easily modify a SIPO shift register to create a function called a ring counter. For example, consider a 10-bit ring counter as illustrated in Fig.7. The first thing to note is that the Init (‘initialise’) signal is connected to the S (Set) input on the first flipflop and the R (Reset) inputs on the We can do wonderful things using D-type flip-flops (DFFs). One of the Connection No connection simplest is called a shift register, in which several D-type flip-flops are daisychained together. S Conceptually, the D0 Q0 D1 Q1 D8 Q8 D9 Q9 simplest type of shift DFF0 DFF1 DFF8 DFF9 register is a serialQB0 QB1 QB8 QB9 in serial out (SISO) R R R implementation. Consider a 4-bit SISO Init shift register (Fig.6a). We will omit the S Clock and R inputs to keep things simple. Q0 Q1 Q8 An active edge Fig.7: A 10-bit ring counter implemented using 10 D-type flip-flops. on the clock line (a Practical Electronics | September | 2024 Q9 55 remaining flip-flops. This means that when the Init signal is placed in its active-low state, our ring counter will be loaded with a value of 1000000000. The second thing to note is that the Q output from the last flip-flop is fed back to the D (Data) input to the first flip-flop. This means that once the counter has been initialized, clocking it will result in the 1 value circling around the counter: 0100000000, 0010000000, 0001000000 (and so on), 0000000010, 0000000001 and back to 1000000000 again. Now think back to our clock project. If we had ten 7-segment displays, each equipped with its own transistor, we could control these ten transistors with the outputs from our ring counter, cycling through them one at a time. In a crunchy nutshell, this technique means we can multiplex ten displays using only two of the Arduino’s pins to drive the counter’s Clock and Init signals. In fact, we could control any number using just these two pins by adding or removing flip-flops to/from the chain. There is essentially no limit. One of the downsides to this implementation is that the more displays we add and multiplex in this way, the dimmer they all get because each will receive a smaller ‘slice’ of the ‘time pie’. In the fullness of time (no pun intended for once), we will return to the concept of using shift registers to control our 7-segment displays. However, we will do so in a different manner to the one discussed here; the discussions above primarily serve to provide us with points to ponder for the moment. And now, believe it or not, just when you least expected it, it’s finally time to turn our attention to binarycoded decimal (BCD) – hurrah! Peeling an onion The topic of BCD is a bit like BCD peeling an onion. ? 7 (Random, 7-Segment Why? Well, in adDecoder ASCII, Display dition to its ability 8421, to make our eyes Other) water, there are lots and lots of layers. Many discussions Inside the Location Outside on BCD skim only Arduino to be decided World the outermost layer, but we are made of Fig.9: A high-level view of the decoding process. sterner stuff. Let’s start off by pondering what we mean by ‘binary BCD (SBCD) or Natural BCD (NBCD). This is also known as a ‘weighted coded decimal’ (BCD) in the first place. In its most general sense, this simply code’ because each binary digit has a refers to a class of binary encodings weight associated with it. From mostin which each decimal digit is repre- to least-significant, these weights are sented by a fixed number of binary 23, 22, 21, and 20. Since these weights bits (usually 4 or 8, but other widths equate to 8, 4, 2, and 1, respectively, this is also known as “8421 Encoding” may be employed). or “BCD 8421”. The left-hand column of Fig.8 shows If you wish to delve deeper into BCD, the ten decimal digits we wish to may I be so bold as to recommend encode. Purely for the sake of an example, I reading my Mysteries of the Ancients: generated a set of ten random binary Binary Coded Decimal (BCD) column numbers along with their hexadecimal (https://bit.ly/3XNp3uO). (hex) and decimal (dec) equivalents (Fig.8a). This certainly qualifies as Soft or hard? BCD, although it is probably not very It’s important to understand that BCD can be used for all sorts of things. In useful. First developed in the early 1960s, our case, we wish to take BCD reprethe American Standard Code for Infor- sentations stored inside our Arduino mation Interchange (ASCII) is a format Uno and use them to drive one or more used to store text in a way that most 7-segment displays. Furthermore, the 7-segment displays computers can interpret. ASCII can be used to represent let- we decided to use for our experiments require us to control each of their segters, numbers, punctuation characters, and control codes. The subset of ments individually (it’s also possible ASCII used to represent the decimal to purchase displays equipped with digits also qualifies as a form of BCD internal decoders). For the moment, let’s consider (Fig.8b). Having said all this, as we discussed things at a high level of abstraction. in an earlier column (PE, April 2023), On this basis, irrespective of the the simplest and most intuitive form BCD encoding scheme we decide of BCD is based on using the natural to employ (random, ASCII, 8421 binary counting sequence, which is etc), we know we want to decode why this may be referred to as Simple these values into the 0s and 1s that we need to control the segments on our (a) Random (b) ASCII (c) NBCD / SBCD Decimal displays that form Binary Hex Dec Binary Hex Dec 8 4 2 1 Hex Dec the digits (see Fig.9). The reason we are 1 0 1 0 0 1 1 1 0 0 1 1 0 0 0 0 0 A7 167 30 49 0 0 0 0 0 0 showing a question 1 0 0 0 0 1 1 1 0 0 0 1 1 0 0 0 1 0 0 0 1 0E 14 31 49 1 1 mark for the number 2 0 0 1 0 1 0 0 0 0 1 1 1 0 0 1 1 0 0 1 0 8 7 135 32 50 2 2 of wires feeding the decoder in that figure 3 0 0 1 1 0 0 0 1 0 0 1 1 0 0 1 1 0 0 1 1 13 19 33 51 3 3 is that, as per Fig.8, 4 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 1 0 0 08 8 34 52 4 4 that value depends 5 0 1 0 1 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 F3 243 35 53 5 5 on the BCD encoding scheme we ulti6 0 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 0 AF 175 36 54 6 6 mately decide to use. 7 0 1 1 1 1 0 0 0 0 1 1 0 0 0 1 1 0 1 1 1 8 6 134 37 55 7 7 Note that the reason we are showing only 8 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 1 0 0 0 C6 198 38 56 8 8 seven wires feeding 9 1 0 0 1 0 1 0 1 0 0 0 1 0 0 1 1 1 0 0 1 51 81 39 57 9 9 the 7-segment display is that a traditional Fig.8: Three possible BCD representations (out of many). ASCII and NBCD/SBCD are the most common. 56 Practical Electronics | September | 2024 Computer (eg. Arduino Uno) 8421 BCD value used as pointer BCD Look-up Table Pin mapper 7-Segment Display BCD Decoder (a) BCD to 7-segment display decoder in software 8421 BCD pointer Pin mapper BCD Decoder 7-Segment Display Listing 1: Our software look-up table (LUT). BCD (b) BCD to 7-segment display decoder in hardware Fig.10: Software vs hardware 7-segment decoder implementations. BCD decoder has no knowledge of the display’s decimal point segment. How are we going to create the decoder portion of this puzzle? There are two main options: a software realisation internal to the Arduino (Fig.10a), or a hardware implementation external to the Arduino (Fig.10b). Thus far in our experiments, we’ve been employing a software decoder. Specifically, we’ve been using classic 8421 BCD values as pointers into a look-up table (LUT) containing the 1s and 0s corresponding to the display segments we wish to activate or deactivate, respectively. The look-up table shown in Fig.10a is the DigitSegs[] array we’ve been using in our programs that indicates which segments to light for each digit to display (see Listing 1). The Pin Mapper functional block shown in Fig.10a is where we specify which of the Arduino’s pins we are using to drive our display(s). This is the PinsSegs[] array we’ve been using in our programs (Listing 2). It’s also worth noting that our software solutions made provision to drive the display’s decimal point (DP) segment, although we never got around to actually using that feature. In the case of the hardware implementation depicted in Fig.10b, the 4-bit 8421 BCD values inside the Arduino are directly mapped onto four of the Arduino’s pins. These pins drive a hardware implementation of a BCD to 7-segment decoder, the outputs of which are used to drive the 7-segment display(s), as illustrated in Fig.11. Practical Electronics | September | 2024 Listing 2: Our software pin mapper. Components from Part 1 LEDs (assorted colours) Resistors (assorted values) Solderless breadboard Multicore jumper wires (male-to-male) https://amzn.to/3E7VAQE https://amzn.to/3O4RvBt https://amzn.to/3O2L3e8 https://amzn.to/3O4hnxk Components from Part 2 7-segment display(s) https://amzn.to/3Afm8yu Components from Part 5 Momentary pushbutton switches https://amzn.to/3Tk7Q87 Components from Part 6 Passive piezoelectric buzzer https://amzn.to/3KmxjcX Components for Part 9 SW-18010P vibration switch https://bit.ly/46SfDA4 Components for Part 10 Breadboard mounting trimpots https://bit.ly/3QAuz04 Components for Part 12 Light-Dependent Resistor https://bit.ly/3S2430m Components for Part 13 BC337 NPN Transistor https://bit.ly/40xAgyS Components for Part 14 HC-SR04 Ultrasonic Sensor https://bit.ly/49AMBq4 Components for Part 15 Real-Time Clock (RTC) https://bit.ly/3S9OjHl Components for Part 18 Long tailed (0.1-inch/2.54mm pitch) header pins https://bit.ly/3U1Vp2z Components for Part 19 Prototyping boards Kit of popular SN74LS00 chips Components for Part 20 16V 100µF electrolytic capacitors Ceramic capacitors (assorted values) https://bit.ly/3UMkcZ1 https://bit.ly/3wqgzyv https://bit.ly/44LzpNa https://bit.ly/4bEAUiv Cool bean Max Maxfield (Hawaiian shirt, on the right) is emperor of all he surveys at CliveMaxfield.com – the go-to site for the latest and greatest in technological geekdom. Comments or questions? Email Max at: max<at>CliveMaxfield.com 57 Remember that our first pass at a clock design using four 7-segment displays consumed all 12 of our digital I/Os (Fig.4a). Our next pass involved us creating and deploying a 2:4 decoder (PE, July and August 2024). This solution consumed 10 pins, thereby leaving two free. Ignoring the decimal points, using a hardware BCD decoder will free up four more pins, which means we will be able to drive all four of our displays using only six pins, leaving us with six free. Can we reduce our pin count even further? You betcha, but that will be a topic for a future column. Online resources For the purposes of this series, I’m going to assume that you are already familiar with fundamental concepts like voltage, current and resistance. If not, you might want to start by perusing and pondering a short series of articles I penned on these very topics – see: https://bit.ly/3EguiJh Similarly, I’ll assume you are no stranger to solderless breadboards. Having said this, even if you’ve used these little scamps before, there are some aspects to them that can trap the unwary, so may I suggest you feast your orbs on a column I wrote just for you – see: https://bit.ly/3NZ70uF Last, but not least, you will find a treasure trove of resources at the Arduino.cc website, including example programs and reference documentation. From Arduino Next time If we were feeling adventurous, we could implement our hardware BCD to 7-segment decoder using primitive logic gates in a similar fashion to the way in which we created our 2:4 decoder. However, I’ve decided that my life is adBCD In venturous enough 8 4 2 1 already. 0 0 0 0 So, in our next 7-Segment Display column, we will 0 0 0 1 use a dedicated A BCD to 7-segment A 0 0 1 0 decoder IC to drive B 0 0 1 1 our displays. BCD8 F B As part of this, C 0 1 0 0 BCD4 BCD 8421 we will discover D 0 1 0 1 Decoder and discuss all G BCD2 sorts of interesting E 0 1 1 0 BCD1 things. E C F 0 1 1 1 Until then, as always, I welcome G 1 0 0 0 any comments, D questions or sug1 0 0 1 gestions from our PE Fig.11: A hardware-based BCD 8421 to 7-segment decoder with its truth table. readers. 7-Segment Out ABCDE FG Display 1 1 1 11 1 0 0 0 1 1 00 0 0 1 2 3 4 5 6 7 8 9 1 1 0 11 0 1 1 1 1 10 0 1 0 1 1 00 1 1 1 0 1 10 1 1 1 0 1 11 1 1 1 1 1 00 0 0 1 1 1 11 1 1 1 1 1 10 1 1 STEWART OF READING Fluke/Philips PM3092 Oscilloscope 2+2 Channel 200MHz Delay TB, Autoset etc – £250 LAMBDA GENESYS LAMBDA GENESYS IFR 2025 IFR 2948B IFR 6843 R&S APN62 Agilent 8712ET HP8903A/B HP8757D HP3325A HP3561A HP6032A HP6622A HP6624A HP6632B HP6644A HP6654A HP8341A HP83630A HP83624A HP8484A HP8560E HP8563A HP8566B HP8662A Marconi 2022E Marconi 2024 Marconi 2030 Marconi 2023A 17A King Street, Mortimer, near Reading, RG7 3RS Telephone: 0118 933 1111 Fax: 0118 933 2375 USED ELECTRONIC TEST EQUIPMENT Check website www.stewart-of-reading.co.uk PSU GEN100-15 100V 15A Boxed As New £400 PSU GEN50-30 50V 30A £400 Signal Generator 9kHz – 2.51GHz Opt 04/11 £900 Communication Service Monitor Opts 03/25 Avionics POA Microwave Systems Analyser 10MHz – 20GHz POA Syn Function Generator 1Hz – 260kHz £295 RF Network Analyser 300kHz – 1300MHz POA Audio Analyser £750 – £950 Scaler Network Analyser POA Synthesised Function Generator £195 Dynamic Signal Analyser £650 PSU 0-60V 0-50A 1000W £750 PSU 0-20V 4A Twice or 0-50V 2A Twice £350 PSU 4 Outputs £400 PSU 0-20V 0-5A £195 PSU 0-60V 3.5A £400 PSU 0-60V 0-9A £500 Synthesised Sweep Generator 10MHz – 20GHz £2,000 Synthesised Sweeper 10MHz – 26.5 GHz POA Synthesised Sweeper 2 – 20GHz POA Power Sensor 0.01-18GHz 3nW-10µW £75 Spectrum Analyser Synthesised 30Hz – 2.9GHz £1,750 Spectrum Analyser Synthesised 9kHz – 22GHz £2,250 Spectrum Analsyer 100Hz – 22GHz £1,200 RF Generator 10kHz – 1280MHz £750 Synthesised AM/FM Signal Generator 10kHz – 1.01GHz £325 Synthesised Signal Generator 9kHz – 2.4GHz £800 Synthesised Signal Generator 10kHz – 1.35GHz £750 Signal Generator 9kHz – 1.2GHz £700 HP/Agilent HP 34401A Digital Multimeter 6½ Digit £325 – £375 HP 54600B Oscilloscope Analogue/Digital Dual Trace 100MHz Only £75, with accessories £125 (ALL PRICES PLUS CARRIAGE & VAT) Please check availability before ordering or calling in HP33120A HP53131A HP53131A Audio Precision Datron 4708 Druck DPI 515 Datron 1081 ENI 325LA Keithley 228 Time 9818 Marconi 2305 Modulation Meter £250 Marconi 2440 Counter 20GHz £295 Marconi 2945/A/B Communications Test Set Various Options POA Marconi 2955 Radio Communications Test Set £595 Marconi 2955A Radio Communications Test Set £725 Marconi 2955B Radio Communications Test Set £800 Marconi 6200 Microwave Test Set £1,500 Marconi 6200A Microwave Test Set 10MHz – 20GHz £1,950 Marconi 6200B Microwave Test Set £2,300 Marconi 6960B Power Meter with 6910 sensor £295 Tektronix TDS3052B Oscilloscope 500MHz 2.5GS/s £1,250 Tektronix TDS3032 Oscilloscope 300MHz 2.5GS/s £995 Tektronix TDS3012 Oscilloscope 2 Channel 100MHz 1.25GS/s £450 Tektronix 2430A Oscilloscope Dual Trace 150MHz 100MS/s £350 Tektronix 2465B Oscilloscope 4 Channel 400MHz £600 Farnell AP60/50 PSU 0-60V 0-50A 1kW Switch Mode £300 Farnell XA35/2T PSU 0-35V 0-2A Twice Digital £75 Farnell AP100-90 Power Supply 100V 90A £900 Farnell LF1 Sine/Sq Oscillator 10Hz – 1MHz £45 Racal 1991 Counter/Timer 160MHz 9 Digit £150 Racal 2101 Counter 20GHz LED £295 Racal 9300 True RMS Millivoltmeter 5Hz – 20MHz etc £45 Racal 9300B As 9300 £75 Solartron 7150/PLUS 6½ Digit DMM True RMS IEEE £65/£75 Solatron 1253 Gain Phase Analyser 1mHz – 20kHz £600 Solartron SI 1255 HF Frequency Response Analyser POA Tasakago TM035-2 PSU 0-35V 0-2A 2 Meters £30 Thurlby PL320QMD PSU 0-30V 0-2A Twice £160 – £200 Thurlby TG210 Function Generator 0.002-2MHz TTL etc Kenwood Badged £65 Function Generator 100 microHz – 15MHz Universal Counter 3GHz Boxed unused Universal Counter 225MHz SYS2712 Audio Analyser – in original box Autocal Multifunction Standard Pressure Calibrator/Controller Autocal Standards Multimeter RF Power Amplifier 250kHz – 150MHz 25W 50dB Voltage/Current Source DC Current & Voltage Calibrator £350 £600 £350 POA POA £400 POA POA POA POA Marconi 2955B Radio Communications Test Set – £800