Silicon ChipMax’s Cool Beans - April 2022 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Subscriptions: PE Subscription
  4. Subscriptions: PICOLOG
  5. Publisher's Letter
  6. Feature: Go eco, get ethical! by Mark Nelson
  7. Feature: The Fox Report by Barry Fox
  8. Feature: Net Work by Alan Winstanley
  9. Back Issues: Digital FX Unit by John Clarke
  10. Project: 64-KEY MIDI MATRIX by Tim Blythman
  11. Project: Digital FX Unit by John Clarke
  12. Feature: P955H PIC Training Circuit by Peter Brunning
  13. Project: High-current Battery Balancer by Duraid Madina
  14. Feature: Circuit Surgery by Ian Bell
  15. Feature: Flowcode Graphical Programming by Martin Whitlock
  16. Feature: AUDIO OUT by Jake Rothman
  17. Feature: Max’s Cool Beans by Max the Magnifi cent
  18. Feature: Make it with Micromite by Phil Boyce
  19. PCB Order Form
  20. Advertising Index

This is only a preview of the April 2022 issue of Practical Electronics.

You can view 0 of the 72 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)
Max’s Cool Beans By Max the Magnificent Flashing LEDs and drooling engineers – Part 26 A few days ago, as I pen these For the purposes of those discussions, we focused on a single-pole, single-throw (SPST) switch and we discussed two software solutions that can be used to debounce (clean up) the signal coming from the switch. The first of these solutions involved the use of a cunning counter; the second employed a sumptuous shift register. Personally, I find the topic of switches in general, and debouncing them in particular, to be extremely interesting and thought-provoking. There’s always something new to learn. For example, what exactly is the definition of a switch? Well, in its simplest terms, we might describe a switch as being an electrical component that can ‘make’ or ‘break’ an electrical circuit (which explains the ‘make’ and ‘break’ nomenclature we’ve been using), thereby interrupting the electrical current or diverting it from one conductor to another. Something else in an electrical engineer’s argot that can confuse beginners are the terms ‘poles’ and ‘throws’. In the context of switches, the number of poles defines the number of distinct circuits a switch can control. Thus, a switch with only one pole (‘single pole’) can control only one circuit; a switch with two poles (‘double pole’) can control two separate circuits; and so on. Meanwhile, the term ‘throws’ defines the number of contacts You turn me on (and off) to which each of the switch’s poles can One of the topics on which we touched be connected. Thus, if a switch has only in my previous column (PE, March 2022) one throw (‘single throw’), then each of its was switch bounce. That is, when you poles can be connected to only one conclose (make) or open (break) a switch like tact; if a switch has two throws (‘double a pushbutton switch or a toggle switch, throw’), then each of its poles can be rather than providing a clean transition connected to two contacts; and so forth. between logic 0 and logic 1 values, it can When it comes to things like pushbutbounce back and forth anywhere up to ton switches and toggle switches, we 100+ times before settling into its new state. tend to think of the throws as being the fixed contacts and Mak e Break V DD 1 the poles as being the NO moving contacts; that 0 NO is, the poles are the Break Mak e 1 CO M contacts that are conNC NC nected to the moving 0 parts of the switch. First 0 on NO First 0 on NC In turn, this leads us to consider the difference between the Fig.1. Single-pole, double-throw (SPDT) switch. words, I was watching a classic movie on TV with my wife (Gina the Gorgeous) and my son (Joseph the Commonsense Challenged). The film’s title, which is on the tip of my whatsit, was something like Departed with Flatulence (I’ll remember the real name and post it at the end of this article). There comes a point about two hours in when our starving heroine finds a turnip in a field, scarfs it down in a very unladylike manner, has an upset tummy, and then holds the remains of the turnip up to the heavens while proclaiming, ‘I swear to God that I’ll never be hungry again!’ At this point there’s a crescendo of music and an ‘Intermission’ sign appears on the screen, just like it did when this movie was first presented in cinemas. ‘Well, that was the worst ending to a film ever’, said Joseph, who – it turned out – was blissfully unaware as to the meaning of the word ‘Intermission’. You should have seen his face when I reassured him that we had only just reached the halfway point and we still had the same amount of film to go. I found myself talking to a hole in the air where a boy had been. I was most impressed. I had no idea he could bounce out of a room so fast. And, speaking of bouncing… 62 terms ‘contacts’ and ‘terminals’. The way I think about this is that the contacts are internal to the switch, while the terminals are the equivalents to which you connect your wires outside the switch, and that each contact will be connected to one or more terminals. Double the fun Let’s up the ante a little by turning our attention to consider a single-pole, double-throw (SPDT) switch (Fig.1). In this case, the pole is usually referred to as being the ‘common’ terminal, and may therefore be annotated as COM. One of the throws will be described as being ‘normally open’ (NO), while the other will be characterised as being ‘normally closed’ (NC). These terms are based on the state of the terminals when the switch is in its inactive/off state (whatever that means). Just to increase the fun and frivolity (if that’s even possible), the SPDT switches most of us tend to use in our everyday lives, and the ones on which we are focusing here, are classed as ‘break-beforemake’ (BBM). This means that when the switch is deactivated or activated, the pole contact is disconnected from its current throw contact before being connected to its new throw contact. There are also ‘make-before-break’ (MBB) counterparts in which the new connection is made before the old connection is broken, but we tend to save those switches for special occasions. The interesting thing to note about a BBM SPDT is that – due to its physical construction – the contact being broken will always have finished bouncing some time before the contact that is being made commences to bounce. This nugget of knowledge makes it extremely easy to implement a simple and robust software debounce solution. Let’s assume that the switch commences in its inactive state with NO = 1 and NC = 0, as illustrated in Fig.1. In this case, all we have to do is look for the first time we see NO = 0 and NC = 1, which tells us that the NC contact has finished bouncing and the NO contact is just starting to transition (in reality, we can just look for the first time NO = 0). Similarly, once the switch Practical Electronics | April | 2022 a b SB y a b y (a) NAND Gate 0 0 1 1 0 1 0 1 1 1 1 0 & & Q SB RB Q g1 g2 RB & Q B 0* 0 1 1 0* 1 0 1 n+ Q Bn+ 1* 1 0 1* 0 1 Q n Q Bn * Illegal state (b) SR L atch Fig.2. NAND gate and SR latch. is in its active state with NO = 0 and NC = 1, all we have to do is look for the first time we see NO = 1 and NC = 0, which tells us that the NO contact has finished bouncing and the NC contact is just starting to transition (in reality, we can just look for the first time NC = 0). For reasons that will soon become apparent, the important thing to observe here is that there are only ever three combinations of 0s and 1s on NO and NC: 10, 11, and 01. That is, we never see the 00 case. Also, the switch may bounce back and forth between the 10 and 11 states, and it may bounce between the 11 and 01 states, but it will never bounce between the 10 and 01 states. Another way to look at this is that the 11 state acts as a sort of buffer zone between the 10 and 01 states. Thus, if we ignore any bounces, the main state transitions will be: 10 -> 11 -> 01 -> 11 -> 10 -> ... and so on. Handy hardware It’s worth reminding ourselves that we didn’t use to care about switch bounce – most people didn’t even know it existed – prior to our creating high-speed electronic systems. Even today, when we turn a light on in the front room, for example, any bouncing takes place far too quickly for us to perceive it. It was only when we started to build devices like computers that switch bounce reared its ugly head. In the golden age of mainframe computers circa the 1960s, the combination of SPDT switches and the software debounce solution discussed above formed one of the crème de la crème solutions used to address switch bounce. The only problem with this approach was that each switch required two of the computer’s input pins. This was a pain when you remember that switches were one of the main ways to communicate with a mainframe computer, so there could be hundreds of the little scamps. One way to tackle this was to employ some handy hardware in the form of two 2-input NAND gates (Fig.2a) used to form an SR (‘Set-Reset’) latch (Fig.2b). With regard to the ‘n’ and ‘n+’ annotations in our truth table, we are using ‘n+’ Practical Electronics | April | 2022 to represent our new state (ie, the state at time ‘now + 1’), while ‘n’ represents the current state (ie, the state at time ‘now’). Don’t worry, this will make more sense in a moment. An SR latch employs feedback (that is, feeding its outputs back as inputs) to remember its previous state. This type of circuit is one of the simplest forms of memory elements we can make. Unfortunately, even though our implementation uses only two 2-input NAND gates, wrapping our brains around how it works can be tortuously tricky for those who are new to this sort of thing. On the other hand, once we have wrapped our brains around the workings of the SR latch, it makes understanding other circuits of this ilk much, much easier, so let’s take a deep breath and ponder things step-by-step. Let’s start with the fact that a 0 on any of a NAND gate’s inputs causes a 1 on its output. It’s only when all of the NAND gate’s inputs are 1 that its output will be 0. The next point to note is that, in the case of our implementation of the SR latch, the SB (‘set’) and RB (‘reset’) inputs are active-low; that is, they are active when they are in a 0 state. This explains why we’ve used the ‘B’ suffix meaning ‘bar’ because an alternative way to write these signal names would be as S and R characters, each with a horizontal line (also referred to as a ‘bar’) over the top. Now let’s assume that we’ve just powered our circuit up and that both SB and RB are in their inactive 1 states, which I’ve indicated in red (Fig.3a). In this case, for reasons that will become clear momentarily, we currently have no idea as to the values on the Q and QB outputs, which I’ve represented in orange and as ‘X’ in the figure. In Fig.3b we place the SB input in its active 0 state. This actually triggers a series of actions as follows. First, since SB is 0, the output of the upper NAND gate, which is connected to the Q output, will be driven to a logic 1. Next, since the Q output feeds back to the lower NAND gate, this means that both of the inputs to the lower NAND gate are now 1. In turn, this means that the output from the lower NAND gate, which is connected to the QB output, will be driven to 0. The really important thing to note here is that the QB output feeds back to the upper NAND gate, which means that both of this gate’s inputs are now 0. The reason this is so important becomes apparent in Fig.3c when we return the SB input to its inactive 1 state. The fact that QB is 0 ensures that Q is 1, and the fact that both Q and RB are 1 ensures that QB stays at 0, at which point we could return to the start of this sentence. In Fig.3d we place the RB input in its active 0 state. Once again, this triggers a series of actions as follows. First, since RB is 0, the output of the lower NAND gate, which is connected to the QB output, will be driven to a logic 1. Next, since the QB output feeds back to the upper NAND gate, this means that both of the inputs to the upper NAND gate are now 1. In turn, this means that the output from the upper NAND gate, which is connected to the Q output, will be driven to 0. In this case, the fact that the Q output feeds back to the lower NAND gate means that both of this gate’s inputs are now 0. Thus, when we return input RB to its 1 state (Fig.3e), the fact that Q is 0 ensures that QB is 1, and the fact that both QB and SB are 1 ensures that Q stays at 0. All of this explains why we show the state in which both SB and RB are 0 as being illegal in the truth table for the RS latch (Fig.2b). We can certainly place both of these inputs in their active 0 states, which will cause both the Q and QB outputs to be driven to 1 (remember any 0 on the input to a NAND gate will result in a 1 on its output). Furthermore, there won’t be any issues if we return SB to its inactive state and then wait awhile before we return RB to its inactive state, or vice versa. The problem arises if we return both SB and RB to their inactive states simultaneously. In this case, much like tossing a spinning coin into the air, the Q and QB outputs can end up toggling back and forth until the latch eventually, and randomly, settles one way or the other. Alternatively, the Q and QB outputs may end up at an intermediate voltage level, which could cause all sorts of nasty things to happen. SB = 1 = X Q (a) Q B= X RB = 1 SB = 0 = 1 Q (b) Q B= 0 RB = 1 SB = 1 = 1 Q (c) Q B= 0 RB = 1 SB = 1 = 0 Q (d) Q B= 1 RB = 0 SB = 1 Q = 0 (e) RB = 1 Q B= 1 Fig.3. Different states of an SR latch. 63 NO (SB) NO (SB) Q NO (SB) Q NO (SB) Q (a) (b) (c) (d) NC (RB) NC (RB) NC (RB) NC (RB) NO (SB) Q NO (SB) Q NO (SB) Q NO (SB) (e) (f) (g) (h ) NC (RB) NC (RB) NC (RB) NC (RB) Q Q Fig.4. Using an SR latch to debounce an SPDT switch. Tra-la! This is where we bring everything together. Let’s suppose that we connect the NO and NC outputs from our SPDT toggle switch to the SB and RB inputs of our SR latch, respectively (Fig.4). As part of this, we’ll remove the QB output from the latch and keep only the Q output, which is what we will eventually connect to the input of our computer. Earlier, we noted that, as seen in Fig.1, the switch’s NO and NC outputs are never both 0 at the same time. In turn, this means we never encounter the RS latch’s illegal state as seen in Fig.2b (it’s almost as though we had a plan). Once again, let’s assume that the switch commences in its inactive state with NO (SB) = 1 and NC (RB) = 0, as illustrated in Fig.1 and Fig.4a. Based on our earlier discussions, we know that the 0 on NC causes a 0 on Q. When we start to activate our switch (turn it on), the first thing that will happen is that the NC signal will change from 0 to 1 (Fig.4b), but this will have no effect on the output Q. Furthermore, it doesn’t matter if the NC signal bounces back and forth between 0 (Fig.4a) and 1 (Fig.4b) because Q will remain at 0. Eventually, the NC signal will finish bouncing, leaving the switch as shown in Fig.4b, after which the NO signal will start bouncing. It’s only when the NO signal first transitions to 0 that the Q terminal will transition to 1 (Fig.4c), which will cause the output from the lower NAND gate to transition to 0. Even if the NO signal bounces back to 1 (Fig.4d), the Q output will remain at 1. Eventually, the NO signal will finish bouncing, leaving the state of the switch as shown in Fig.4c. The switch is now in its active state with NO = 0, NC = 1, and Q = 1 (Fig.4e). When we start to deactivate our switch Fig.5. The extra-tiny Ultrasonic TouchPoint Z sensor from Ultrasense. 64 (turn it off), the first thing that will happen is that the NO signal will change from 0 to 1 (Fig.4f), but this will have no effect on the output Q. In this case, it doesn’t matter if the NO signal bounces back and forth between 0 (Fig.4e) and 1 (Fig.4f) because Q will remain at 1. Eventually, the NO signal will finish bouncing. It’s only when the NC signal first transitions to 0 that the output from the lower NAND gate will be driven to 1, which will result in the Q terminal being driven to 0 (Fig.4g). Even if the NC signal bounces back to 1 (Fig.4h), the Q output will remain at 0. Eventually, the NC signal will finish bouncing, leaving the state of the switch as shown in Fig.4g. It’s only when you stop to think about it that you realise that this hardware implementation debounces the signal from the switch in exactly the same way as the software solution we discussed earlier. Tra-la! A little bit of history As we noted earlier, ‘mainframe computers circa the 1960s might boast hundreds of switches. We also made mention of the fact that SPDT switches – especially when combined with SR latches – formed the ‘crème de la crème switch debounce solution’. Why didn’t the designers of these ‘big iron’ machines omit the SR latches, use cheaper SPST switches, and debounce the signals in software? One reason was that these computers were already ferociously expensive – in the US, for example, it could cost thousands of dollars a month just to rent one of these machines, or around a million dollars to buy one – so price was not an issue with respect to splashing out the cash for a few hundred switches. On the other hand, even though 1960s mainframes were physically large, they were computationally challenged by today’s standards, with limited memory and clock cycles. Consider the IBM System/360 Model 30, for example. Introduced in 1964, this behemoth was equipped with only 8 to 64KB of memory and could perform only 34,500 instructions per second. Not surprisingly, no one wanted to waste their precious memory or clock cycles debouncing switches. When the use of microprocessor-based personal computers started to explode circa the late-1970s and early 1980s, there were a lot of people with hardware design experience, but relatively few experienced software developers. Furthermore, what software developers there were rarely understood the problem of switch debounce, so it was left to the hardware folks to sort things out. Since money was a consideration with these machines, designers often employed cheap-and-cheerful SPST switches coupled with resistor-capacitor (RC) delay circuits, which we discussed in an earlier Cool Beans column (PE, April 2019). As microprocessor-based computers grew in capacity and performance, coupled with the exponential growth in microcontroller-based embedded systems, more and more people learned to program, and it became increasingly common to debounce switches in software. Even today, however, some people prefer to use hardware debounce techniques. Welcome to the 21st Century On the one hand... I love traditional pushbutton and toggle switches. For example, I’m currently watching the neo-noir science fiction TV series Cowboy Bebop on Netflix – not the original Japanese anime version, but rather the 2021 live action remake (https://imdb.to/35psfDC). Although this is set in the year 2171, the technology has a strong steampunk aesthetic that really tickles my fancy, as it were. For example, our heroes – Jet Black and Spike Spiegel – spend a lot of time flying around in their spaceship, the Bebop, whose control panels are unrestrainedly festooned with a cornucopia of vintage toggle switches. On the other hand... when you come to think about it, if you look around at all of the amazing electronic systems that surround us, don’t you sometimes think to yourself, ‘Pushbutton and toggle switches are so 20th Century!’ I mean to say, pushbutton and toggle switches of the type with which we are familiar originally appeared on the scene circa 1880 and 1916, respectively. In turn, this means that we are controlling our uber-cool cunning contraptions using devices developed 140+ years ago (in the case of pushbutton switches) and 125+ years ago (in the case of toggle switches). Even worse, we are using devices whose capricious characteristics – including the fact that they bounce like deranged ping pong balls – demand that we expend an inordinate amount of time and effort making them behave the way we want them to in the first place. Isn’t it perhaps time that we started to indulge ourselves with a technology that’s a tad more Jetson-esque, as it were? ‘But what is the alternative?’ I hear you cry. Well, I’m glad you asked, because I was Practical Electronics | April | 2022 www.poscope.com/epe Fig.6. Truly a switch for the 21st Century recently chatting to the guys and gals at a company called Ultrasense Systems (see: https://bit.ly/3APS37B). These little rascals have developed a teeny-tiny ultrasonic sensor called the TouchPoint Z, which makes a grain of rice look large by comparison (Fig.5). This sensor can be mounted behind, or embedded in, a control surface of any practical thickness, because its ultrasonic signal can penetrate hard plastic up to 5mm thick and stainless steel up to 2mm thick. Now, there are other ultrasonic sensors around, so what makes this one different. Well, in addition to the ultrasonic transceiver, it also features four tiny piezo strain gauges that allow it to detect deformations as small as 100nm in the surrounding material. But wait, there’s more, because it also includes a microcontroller that allows it to communicate with a host system using 2-wire I2C or UART interfaces. And, just to add a great big dollop of whipped cream on top of the metaphorical cake, the latest generation also boasts a neural touch engine (NTE). By supporting native machine learning (ML), the NTE can be taught to differentiate between intended vs. accidental touches (Fig.6). It probably goes without saying that the one thing this little beauty doesn’t give us is any form of switch bounce. I was reading an article on Consumer Reports about Tesla’s weird and wonderful rectangular steering yoke with which they’ve replaced the traditional round steering wheel (https://bit.ly/32R8fsF). V DD NO CO M NC Fig.7. Why, the LEDs are over here! This yoke features a collection of capacitive sensors. I think the current state of play on the report card is ‘Could do better!’ For example, one driver noted ‘I accidentally washed the windshield and honked the horn at innocent roadgoers while making turns.’ Suffice to say, this wouldn’t be a problem if they were using ultrasonic sensors from Ultrasense (just wait until Elon reads this column). But where are the flashing LEDs? I fear that, having seen its title Flashing LEDs and drooling engineers, newcomers to this column may be saying to themselves, ‘But where are the flashing LEDs?’. Well, wandering off into the weeds as is my wont, I might note that – in addition to innovative spelling, punctuation and grammatical constructions – technical manuals originating from different countries can have very different styles. Manuals originating in Israel, for example, often have a substantial Shakespearean sense of wordplay, along the lines of, ‘But where are the LEDs?’ you ask,’ closely followed by, ‘Why, the LEDs are over here!’ If we were to take our original SPDT switch-based circuit (Fig.1) and add two LEDs (Fig.7) such that the red and green LEDs are connected to the switch’s NO and NC terminals, respectively, then the green LED will be illuminated when the switch is in its inactive/off position, while the red LED will light up when the switch is in its active/on position. If you imagine toggling the switch back and forth as fast as you can, then you can also imagine me saying, ‘Why, the flashing LEDs are over here!’ You’re welcome. - PWM - Encoders - LCD - Analog inputs - Compact PLC - up to 256 - up to 32 microsteps microsteps - 50 V / 6 A - 30 V / 2.5 A - USB configuration - Isolated PoScope Mega1+ PoScope Mega50 All is revealed I remember now. The title of the movie mentioned at the start of this column was – drum roll – Gone with the Wind. 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 Practical Electronics | April | 2022 - USB - Ethernet - Web server - Modbus - CNC (Mach3/4) - IO - up to 50MS/s - resolution up to 12bit - Lowest power consumption - Smallest and lightest - 7 in 1: Oscilloscope, FFT, X/Y, Recorder, Logic Analyzer, Protocol decoder, Signal generator 65