Use of diodes in digital circuits

Thread Starter

Robyn

Joined May 1, 2013
31
Hi everyone,

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 ;)counter.png
 
Last edited:

Alec_t

Joined Sep 17, 2013
15,103
counter circuits usually feature diodes on their outputs.
Not in the case of CMOS logic, as far a I know. The CD4022 has standard CMOS push-pull outputs, not diodes.
Btw, your caps have no way of charging up, in the absence of a current path. Even if they did, their charge current is limited only by the internal resistance of the Q outputs and the ESR of the caps.
 

sarahMCML

Joined May 11, 2019
695
Your CKEN, pin 13 needs to be at 0V to enable the counter, which will run at 3.3 volts perfectly well, by the way. What is the purpose of the capacitors on the outputs of the counter, and where are their negative ends going to connect (hopefully NOT 0V)?
 

Thread Starter

Robyn

Joined May 1, 2013
31
Not in the case of CMOS logic, as far a I know. The CD4022 has standard CMOS push-pull outputs, not diodes.
Btw, your caps have no way of charging up, in the absence of a current path.
Sorry I didn't mean on chip diodes. I meant in circuit such as this one: counter_tuto.png
from this tutorial.

I've also watched another tutorial on youtube using diodes in such a keyboard matrix (but without a counter) to supposedly avoid "cross talk" between switches on the same column or row. But I don't really understand what sort of path the current would take without them to generate that cross-talk...
Regarding the caps, this diagram is the unfinished state of the circuit, the way it was when I tested the counter and fried the Teensy. They will eventually have a return path to an input pin on the MCU.
Even if they did, their charge current is limited only by the internal resistance of the Q outputs and the ESR of the caps.
Thanks, yes of course! They need some resistor friends!

Your CKEN, pin 13 needs to be at 0V to enable the counter, which will run at 3.3 volts perfectly well, by the way.
Silly me about that clock enable... Duly noted. Regarding 3.3V the datasheet mention 3V as an absolute minimum so I was worried but I'll go with your suggestion thank you.
What is the purpose of the capacitors on the outputs of the counter, and where are their negative ends going to connect (hopefully NOT 0V)?
The purpose of the caps is to debounce the switches (which are little tactile ones). The negative ends will merge into one and go back to the surviving Teensy. I assume that connecting them to ground would just let tons of current flow through the gates of the 4022 and fry them right?

Neither of you mentioned the death of the MCU. Am I right in thinking that my dodgy circuit may have charged me with static electricity was I was probing around? I'm sure I didn't short anything with the probe. That's one thing breadboards are good for, they keep you from slipping around :)
 
Last edited:

MrChips

Joined Oct 2, 2009
34,628
I think your circuit has nothing to do with the "failure" of the Teensy.

I would remove your circuit for now and focus on getting the Teensy working or reprogrammed again.
 

Thread Starter

Robyn

Joined May 1, 2013
31
I think your circuit has nothing to do with the "failure" of the Teensy.

I would remove your circuit for now and focus on getting the Teensy working or reprogrammed again.
I guess that makes me feel better! I have another one, I bought 1 like over 10 years ago so I will upload my code to the survivor but that only takes a minute :) After that I need to get back to the switch matrix and I wanna be sure I don't kill my only one left. The dead one is proper dead. Even if I identified the failed components I don't have the practice or gear to solder that size SMD...
 

MrChips

Joined Oct 2, 2009
34,628
As others have already pointed out, there are somethings wrong with your circuit.

Tell us what you are trying to do and we will advise accordingly.
 

Thread Starter

Robyn

Joined May 1, 2013
31
As others have already pointed out, there are somethings wrong with your circuit.

Tell us what you are trying to do and we will advise accordingly.
I like to think I'm not one of these annoying people who provide vague posts but in case I wasn't clear here is a summary:

- Multiplex switches to save pins on my MCU (testing with 4 but there will eventually be more)
- Debounce said switches with caps
- Not fry my remaining MCU / understand what happened to the other one

Here is a diagram of the next circuit based on everyone's posts so far:
counter_corr.png
 

MrChips

Joined Oct 2, 2009
34,628
You don't need the capacitors. You can do debouncing in software.
Make R5 two or three times lower than the others. Put the switches in parallel with the resistors.
 

Irving

Joined Jan 30, 2016
4,996
The circuit you show in post #8 has several flaws:
1. you have no idea where the counter is so when you register a switch closure you still don't know which switch is closed. You need to reset the 4022 before you start scanning.
2. When a switch is closed, Rx + R5 form a voltage divider so the input to the Teensy is approx VDD/2 which is neither a 1 (>0.7VDD) or a 0 ((<0.3VDD) so your results will be inconsistent. You don't need R1 - R4, or make them 1k
3. ,You don't need capacitors; debounce in software

Here's how to extend to a 4x4 with only 1 input... can expand to 8 x 4 with only 4 more diodes (+ switches of course) or 8 x 8 with another 4066.

1749392009902.png
 
Last edited:

Thread Starter

Robyn

Joined May 1, 2013
31
Thanks you two! I have some questions before I go ahead with it:

Debouncing:
- The Teensy is going to juggle a lot more that those switches (force sensitive resistors that need a lot of preprocessing, OLED display, generating MIDI data for another MCU which will generate audio...). That's why I'd like to debounce in hardware. Is there a very strong reason not to use the caps?
- If I was to use the caps, @MrChips you say to put the resistors in parallel with the switches but then they won't limit current to the caps. What am I not understanding?

Resistors:
- I understand the issue of the voltage divider. Well spotted It seems to me that the two of you are recommending the opposite solution to each other. Am I right in thinking that @MrChips you are considering an active low and @Irving an active high?

Reset:
- No question. I guess I thought the counter always started at the first output on power on and I could just keep count of my clock but I was wrong :)
 

Irving

Joined Jan 30, 2016
4,996
The Teensy is going to juggle a lot more that those switches (force sensitive resistors that need a lot of preprocessing, OLED display, generating MIDI data for another MCU which will generate audio...)
De-bouncing in software using an interrupt driven task and a timer need not take much overhead. If you're trying to do everything in a big loop, then that's the wrong approach. Also consider you may be asking too much of a Teensy. Consider a faster processor, eg ESP32-S3 2 cores at 240MHz.

The caps will limit the speed at which you can scan and still recognise one keypress after another... it's just the wrong approach.

Resistors:
- I understand the issue of the voltage divider. Well spotted It seems to me that the two of you are recommending the opposite solution to each other. Am I right in thinking that @MrChips you are considering an active low and @Irving an active high?
I can't say what MrC was thinking, but your circuit is, by definition, active high, therefore the upper resistor must be << than the lower for the circuit to work.

- No question. I guess I thought the counter always started at the first output on power on and I could just keep count of my clock
Maybe, but its prone to error...

If you want to offload the key matrix processing, as I did on another project, here's a suggestion: I used a ATtiny84 as a keyboard input processor (and its 1 chip rather than 3 or more...)

1749400380779.png
 
Last edited:

Thread Starter

Robyn

Joined May 1, 2013
31
Thank you @Irving. I really appreciate a point by point in-depth answer like this.

I've been careful to implement non-blocking processes so far so I'll see if the Teensy gets overwhelmed I can upgrade. Its all a learning experience!

I do have a few bare ATMega328's which I can use in place of the ATtiny. It's a bit overpowered but I doubt I'll use them up in my lifetime (I'm normally a carpenter) and I can always offload more to it if the Teensy struggles.

Thanks again to everyone who chimed in!
 

crutschow

Joined Mar 14, 2008
38,320
As a side-note, it's not good practice to put a capacitor directly across switch contacts without a small series resistor to limit the current, otherwise the capacitor can act as a small spot-welder and burn the contacts.
 

MrChips

Joined Oct 2, 2009
34,628
You don't need capacitors. Debouncing in software does not take time if you do it properly.
If you want to limit the current from the output, you can put a resistor in series.
@Irving and I are not in contradiction. It depends on where you place the switch and if the normal voltage is below or above the switching threshold. The key is, you have to move away from the mid-point, Vcc/2.
 
Top