Saturday, June 13, 2020

0000 0000 0011 0011

CD4020 Counting Guy (sort of...)


In an earlier blog I used a shift register and an ATTiny13a to count using LEDs as a visual output, but there might be times when you want a non-programmed IC to do the same thing. Enter the strange and eventually usable CD4020B 14-bit Binary Counter/Divider.

I say "eventually usable" because it has an interesting design twist, and as well I totes messed up the wiring to the LEDs (twice) in the first instance.

Let's look at the design twist first. When I was trying to see how I could hook up the LEDs so that they count in binary (e.g. 8 LEDs to count from 0-255), I was surprised to learn that two of the so-called "outputs" are inside the chip (!) and so despite a lot of well meaning gif makers on the internet showing how this chip works, I got this strange counting pattern where the first LED flickered away merrily with seemingly no relation to the second LED (see video for explanation). 

The data sheet reveals the truth as it leaves the Q2 and Q3 "outputs" off in the following pinout diagram.


I wanted to see how these "missing" outputs affected the light show, so I set up a roughly 1Hz output from a 555 timer and also a reset button to start the "counter".


The 1Hz input proved too fast for my old eyes to follow, so I hooked up the reset button to the clock input and then manually clicked and recorded each input and output. The result was a rather tedious spreadsheet which does however show the following timing.
Note that the coloured columns are an educated guess at the "inside" outputs. The timing chart is confirmed when I go back to the 1Hz clock and then time from when the reset button is hit to when the Q6 output flips. So the chip is working and not full of tiny socks (long story).

So whilst this is all fine if you want to use the chip as a timer (e.g. to turn on something after 1 hour), it is a bit tougher to use it to "count" in binary as the missing outputs throw the LED activated count out.

The obvious answer was to simply not use Q1, Q2 and Q3 and start the counter at zero by hooking up the first LED to Q4 with an increase in the clock signal frequency to compensate. Here it is diagrammatically with 25 indicated in binary. Note the wacky relationship between pins and outputs - someone at the factory is having a laugh!

Pin 15Pin 14Pin 12Pin 13Pin 6Pin 4Pin 5Pin 7
 Q11  Q10  Q9  Q8  Q7  Q6  Q5  Q4
0 0 0 1 1 0 0 1

I also originally, for some strange reason, wired up the CD020 to output to the LEDs from left to right, even though I wanted a "normal" binary counter which for me is right to left. I rewired the rat's nest and then worked out later that a much smarter me would have just turned the breadboard around 180 degrees!

The final issue to be addressed was my ridiculous original wiring of the SMD-to-DIP adapter which had a comical line of 470Ω resistors down it's spine. The result of this nonsense of course is an effective row of parallel resistors as shown in the following picture which blinded me with the lowered overall resistance (300Ω).


Noob mistake = damn bright LEDs

Not only did I re-wire it in a sane manner, but I also increased the resistance on both the adapter (1k) and the breadboard (3k3) in the final version to reduce the chance of burnt out retinas.

So the binary counter as originally desired was finally possible with:
  1. Omission of Q1, Q2 and Q3 from the counter
  2. Re-wiring LEDs left to right
  3. Changing resistors to be series not parallel
  4. Increasing resistance to sensible levels







No comments:

Post a Comment