Diodes in counter circuits (and a dead Teensy)

mrfry

Member
Hi crew!

Yesterday I breadboarded a little test circuit to multiplex a bunch of switches using two 4022 counter. The idea was to have a Teensy 3.1 (3.3V logic, 5V tolerant on the digital pins) to generate a clock for the counters so I started with one counter and 4 switches just for a proof of concept.
I thought it would be ok to see if the teensy was driving the counter properly before hooking the switches back to the Teensy inputs but I guess some sort of ESD event happened because of floating pins and maybe capacitors. My EE knowledge is pretty basic...
Anyway I was probing around with a pocket scope and at some point the clock went away. I went to short the Programmer pin to try and "reboot" by reuploading my code and I'm pretty sure the LED on the Teensy went out *just* before I thouched the pins which makes me think ESD. Attached is a schematic of the test setup. The unconnected pins were actually unconnected.

Now I'd like to understand what happened so it doesn't happen again. I realised after the facts that counter circuits usually feature diodes on their outputs. I've watched a lot of Ben Eater's breadboard computer videos and I've never seen any diodes in his circuits. Is it a counters only thing? Why? I've tried to search for "diodes in digital circuits" but all the results I get are generic pages about what diodes are which I already know.

Thanks for reading this, feel free to tell me off for being careless but please don't be mean :)

Edit: the diagram is the unfinished state of the circuit such as it was when all hell broke loose. The switches / caps were eventually supposed to connect back to a common pin on the Teensy.
 

Attachments

  • counter.png
    counter.png
    54.3 KB · Views: 75
Last edited:
Hello. Welcome to the world of Teensy. Sorry to hear your first experiment didn't go so well. I hope I can shed some light on what I see as possible issues.

In the schematic, the negative side of the capacitors are not connected to a reference voltage. The reference could be Ground, a voltage such as 5V or 3.3V, and ideally thru a resistor. Since we don't know the capacitor value, it's hard to recommend a resistor value. So, the schematic as shown, would do nothing.

On the other hand, if the negative side of capacitor is connected directly to Ground, this would be a bad scenario. The switch, when operated, would short the counter output pin directly to Ground. The counter device might now be damaged in ways that we can't predict. It's also possible that if counter device is damaged and powered from 5V, this 5V could be presented to its clock pin. This could be bad news for Teensy depending on which Teensy pin was used (might not be 5V tolerant). A resistor should be inserted between counter Q output pin and switch.

Assuming counter device is deriving it's power from Teensy Vin or 3.3V pin, another possibility is the 3.3V regulator is damaged. Or, the fuse on Teensy could be blown (it's not known if Teensy uses a fuse or a PTC as a fuse in schematic). If it's a PTC, then after all power has been removed and the PTC cools down, chances are it's still good.

Not clear why you shorted Program pin when you could press the Program button.

Since you have a pocket scope, measure the Teensy 3.3V pin to see if any voltage appears there. A volt meter (DVM) would be more ideal for this measurement. I'm assuming the pocket scope is battery powered. If scope is powered from a USB charger, this could be a problem where Ground of scope is not same as Ground of Teensy. We really need to know how everything is powered.

To answer your question about diodes connected to counters, do a Google search on the keywords: Diode Logic. There, you'll find several images of how diodes are connected to form logic gates such as AND, OR, NOR, etc. When used with a counter, let's say you wanted to know when the counter reached the count of 5. That would be the ANDing of Q0 AND Q2. Let's say you wanted to know when counter reached 70 (decimal, not hex), that wound be the ANDing of Q6 AND Q2 AND Q1. You include more diodes in the circuit to include more bits in the equation.

An example of reading several switches, potentiometers, can be found in the PJRC MIDI page.
PJRC MIDI
Scroll down the page to see the schematic. Although a different Teensy is shown operating at 5V, everything would still work at 3.3V. And there are plenty of other methods to read switches.

So, lots of guess's. Would need more details from you of actual pins used, how things are powered, maybe upload a photo of the hardware with all connections.
 

Heya Bill, thanks for taking the time to explain things in detail. It's quite rare and I really appreciate it. I took a while to respond because I wanted to do my homework and be clearer this time. I've underlined what I'd like you to comment on to save you time scrolling up and down. This is a long post so I'm starting with a:

TLDR
Despite being a muppet for testing an unfinished circuit I've gone through everything carefully and I don't think any of the failure modes you've described apply. Mostly because as you've pointed out, there was some missing / confusing info in my original post. The Teensy may have already been on its way out from previous abuse. That "solves" my first reason for posting, the second being the diode question which I think is still a question (see in the diode section at the end of the post).

IN DETAILS:

Dodgy schematic

I wasn't very clear on my original post but the schematic is the unfinished circuit as it was when testing whether the Teensy was correctly driving the counter. I guess it is silly to test an unfinished circuit but I assumed a HIGH would show up on the Q outputs when looking with the scope as it does have a ref to ground. I did intend for these switch / cap pairs to go back to a common pin on the Teensy with a pull down resistor to read their state.

But indeed, I did overlook putting resistors in series with the caps to limit the charging current. They are .33uF (tantalum).
Another thing I later learnt is that I need the Teensy to control the reset pin on the counter to start multiplexing from a known state.
- I also got told by someone else to just do away with the caps and debounce in software as the capacitors may interfere with the multiplexing. What do you think?
- I need individual resistors on the charging side of the caps but I can have a single pull down on the discharging side right?


Power
This is my power setup

Code:
      ,---- Teensy3.1
      |
USB --|---- 3.3V reg ---- OLED
      |
      '---- 4022

I'm taking 5V from an AC -> USB adapter which is going to the Teensy3.1 (I realise writing this that I hadn't cut the trace on the dead Teensy to separate VUSB from 5V in but I have on my remaining one. Maybe that's also a cause of failure as I think it was connected to both my laptop USB and supply USB when shit hit the fan). The 5V for the counter was coming from the USB adapter as well. I also have a 3.3V regulator on a board for other devices such as my OLED screen. I did not want to use power from the Teensy itself as I know its 3.3V regulator is quite limited (150mA I believe). Here is a photo of the setup:

IMG_20250610_123508.jpg

Teensy / counter forensics
I've tested the Teensy's pins with my (battery powered) scope. 5 and 3.3 both show up on their respective pins but all the other pins are dead. Like not even a solid ground, the signal is slightly noisy. I've tried the 15s programmer switch thing to get back to a blink sketch but no luck and when connected to a computer it just won't show up (in dmesg, in /dev/tty or the arduino IDE). I think the actual processor is gone. I've had it for a very long time, pulling it out every few years to start a project I'd never finish and store it again. The programmer switch actually got broken from careless storage which is why I had to solder some pins that I could short to put it in program mode. Because I've proved myself to be quite unskilled I am posting a picture so you see that at least I can (de)solder... Anyway, I guess it's served years of learning process and I just need to get over it.

Edit: I've re-breadboarded the counter circuit to test it with a manual trigger and leds on the outputs and it works perfectly fine.

IMG_20250610_123526.jpg

Diodes
So I think you've just explained how one decodes a undecoded counter output and I am grateful and excited about it! But I was talking about something much more basic on an already decoded output such as this (which is basically the circuit I'm aiming for without the debouncing caps and with a 4017 instead of 22):

counter_tuto.png

Sorry this is quite dense in information. I won't hold it against you if you give up on me, I've already learnt a lot from reading your previous response and troubleshooting everything. Gonna read that PJRC MIDI page you shared now. Thank you!
 
Last edited:
Hello again. Thanks for supplying the extra info. That helps a lot! I'll try to answer your questions.

Yes you can remove the capacitors connected across the switches and then debounce the switches in software. There are numerous reasons why capacitors can be connected across switches, but in your application they're not necessary. Capacitors do take time to charge and discharge and this can lead to other problems associated with digital inputs. This is why you'll see devices such as 74HC14/74HCT14 being used when capacitors are connected to inputs. It's just not a good idea.

I'm not sure I follow your second question.
Yes, individual resistors are needed from Q output to each switch/capacitor pair. This resistor is performing both the charging and discharging of the capacitor. The negative side of the capacitor would go to Ground. The capacitor positive side would go to individual Teensy pins. If you're suggesting the capacitor negative side would go thru a resistor to Ground, I don't see how that would do anything. That resistor would simply add to the capacitor charge/discharge time. I'd need to see a drawing of what you intend to connect.

Connecting a wall pluggable 5V USB power supply to Teensy while Teensy is connected to PC via USB is not recommended. These wall plug USB power supplies come in too many electrically misbehaved flavours. Some people are lucky with them while others are not. Even is you cut Teensy bottom trace and cut the PC 5V inside USB cable from PC, you still have a potential hazard waiting to happen as soon as you attach the wall mount 5V supply. Those 2 Ground references are not guaranteed to be at the same level. Best to avoid this situation.

BTW, you might try the software recovery procedure with the wall mount 5V USB power supply. It's possible you blew out the PC USB port. Maybe plug a mouse into PC to see if that USB port is functional.

When you short Program pin to Ground, and you wait, do you ever see a quick flash of the red LED? The quick flash indicates when to remove the short. You have to watch carefully for this flash. Once you see the flash, you only have a few seconds to remove the short. See post #12 from PaulS. Granted, the description is for Teensy 4.x, hopefully similar enough for Teensy 3.1.
Teensy Restore

The next problem you face involves having 2 separate power supplies. Teensy does not appreciate voltage appearing on its pins unless Teensy is powered up first. So if you switch ON the external power supply before powering up Teensy, the result is most likely a damaged Teensy.

Ahhhh, switch detection using a row/column matrix. This is just one (of many) topology to use when you have very few pins available and too many switches. In this schematic, the diodes are used to isolate groups of switches. Without the diodes, pressing S1 while simultaneously pressing S5, would cause a short circuit between Q0 and Q2, potentially damaging the chip when Q0 is HI and Q5 is LOW, and visa-versa. So, think of these as isolating diodes.
If you Google "keypad matrix diodes" or "keyboard matrix diodes", you'll find lots of online info.

You might want to look at Teensy pcb to see if any other parts are missing and/or look for solder cracks. I'd even go as far as pressing down on processor chip, boot loader chip, to see if there's any life there. Solder cracks are pretty hard to spot.
 
Apologies @BillFM for the slow response, been very busy with work and not Teensying very much but...

It's alive!

I'm not too sure when or how. If it's the fuse it took a very long time to reset. But I'm very happy to back to a pair of Teensies :)

Seeing as you also recommend not to use caps I'm not gonna ask you more about it. I know there is something I still don't quite understand but that's for another time. I'm just gonna wire a classic switch matrix and debounce in software. At least now I understand why the diodes are there so I'll my initial hurdles are solved. The key takeaway for me is that the diodes are not there because of the counter, it's the switch matrix that requires them (hence my initial question and research was misguided; ah "unknown unknowns"!).

It sounds like despite my best efforts to be cautious (cutting the trace, not sourcing 3.3 from the Teensy...) I've been lucky with the power supply situation. Glad you mentioned it, it will probably save me headaches further down the line. I'm thinking of implementing a Teensy controlled switch in the setup() function to turn on the rest of the "peripherals". Either with transistor(s) or a relay once I've figured out power usage of said peripherals.

Thank you very much for your help. I've enjoyed the pace of it. A slow, detailed one to one exchange works way better for me that x people throwing (sometimes contradicting) "solutions" at you without explaining anything which is what happened on the other forum.
 
Good to hear you have the Teensy working again.

Feel free to post questions or project updates. There's always something new to learn. It keeps the forum interesting and fresh with idea's.
 
Back
Top