74HC390: Ripple Counter is Counting Rubbish - Page 1
Forum section: electronics / beginners

author: Darkwing
author_rank: Contributor
timestamp: May 01, 2019, 08:53:57 pm
content: Hi folks!I'm currently experimenting with aCD74HC390 Ripple Counter. I want to use it to simply divide a pulse signal. Here's the breadboard:It seemed an easy task at first, but I found out that it is not so ...Why do I get this from the outputs:When the datasheet says, that I should get this:It's messed up completly.The QAstage does invert (?!) my signal, instead of dividing it by 2!The following stages QBand QCare not even close to a recognizable pattern.What could be wrong?Is it somehow necessary to "stabilize" the IC, that it can work correctly? I already found out, that a 0.1µF cap across VCCand GND does a little good to the signal quality.Can someone give a hint?Thanks in advance!EDIT: You can jump rightto this message, to see more pictures and a solution.

author: sarahMCML
author_rank: Regular Contributor
timestamp: May 01, 2019, 11:32:43 pm
content: Hi,Your layout looks fine, but you may have a bad connection somewhere. The most likely reason though is because the other section of the counter has its inputs left in an undefined state. Try tying the two A side clocks and its reset to 0V, and it should eliminate any spurious interference from that side.Regards,Sarah.

author: schmitt trigger
author_rank: Super Contributor
timestamp: May 02, 2019, 03:23:04 am
content: HC logic is very fast. Sub microsecond noise pulses, completely invisible at your ultra-slow timebase, can cause spurious clocking.It has happened to me.

author: EEVblog
author_rank: Unknown
timestamp: May 02, 2019, 04:20:08 am
content: HC has a maximum input slew rate, so make sure your inputs are nice and fast edges.EDIT: Yep, your clock pulse is coming from an opto-coupler, that will be a creating a slow positive edge. Try reducing your pullup resistor value for starters.

author: floobydust
author_rank: Super Contributor
timestamp: May 02, 2019, 04:59:49 am
content: I never leave unused 'HC logic inputs floating, like pin 1,2,4.

author: EEVblog
author_rank: Unknown
timestamp: May 02, 2019, 06:52:13 am
content: I just shot a video on this question, editing now...

author: vk6zgo
author_rank: Super Contributor
timestamp: May 02, 2019, 12:02:08 pm
content: You could use a 4017 "Johnson Counter" instead, if you just want to divide by 10.Looking at the spec sheet it says for rise & fall times: "unlimited".I used one 30+ years ago in a project with an opto coupler, but on reflection, the opto was not clocking the 4017 direct.That function was performed by a 555 in astable mode, which was, in turn, triggered on by the output of the opto coupler which was used to isolate the local power supply from the telephone line power.When the device received a call, it would turn on the opto, starting the 555.Ultimately, the whole shebang controlled an audio generator, which would perform a frequency response test of Broadcast programme lines on demand for staff at a remote site.

author: Darkwing
author_rank: Contributor
timestamp: May 02, 2019, 12:24:33 pm
content: Wow, Dave, that's so amazing! I'm glad that I finally was able to contribute to the EEVBlog with my stupid questions.I will follow up on this, presumably next week and I'll post results and my findings.For now, quick info: the Fall Time of my signal is 396ns in average [274ns - 524ns]. So that alone seems problematic, very very slow.Will keep you updated!Thanks so far!

author: EEVblog
author_rank: Unknown
timestamp: May 02, 2019, 10:53:57 pm
content: Quote from: Darkwing on May 02, 2019, 12:24:33 pmQuestions like these certainly are not stupid, they are the opposite, as you can see they actually lead to a lot of real engineering questions and things to consider and look at. There are even more than I put in this video.This is why I hope people's projects fail, because you learn so much when you have to debug it.

author: trophosphere
author_rank: Frequent Contributor
timestamp: May 03, 2019, 04:36:57 am
content: Quote from: Henry Petroski

author: wilfred
author_rank: Super Contributor
timestamp: May 03, 2019, 05:44:36 am
content: Quote from: Darkwing on May 02, 2019, 12:24:33 pmNot only was the question not stupid you asked it very well. If more people took a leaf from your book forum questions would get better answers.Putting in a bit of effort to describe the problem really makes people feel their effort helping will be worth it.

author: Brumby
author_rank: Unknown
timestamp: May 03, 2019, 09:21:21 am
content: I'll add my voice to the "not a stupid question" chorus!In fact, some of the most stupid questions are the ones thatdidn'tget asked.Quote from: wilfred on May 03, 2019, 05:44:36 amVery true. It demonstrates the question (and the person putting it) are fair dinkum.

author: LateLesley
author_rank: Frequent Contributor
timestamp: May 03, 2019, 10:21:06 am
content: i'll add to the "not a stupid question" crowd. I was once told, "The only stupid question, is one you already know the answer to."As for the problem, I wonder if we are actually seeing intended behaviour?If we follow the sequence :-Q3Q2Q1Q00 - 0 0 0 01 - 0 0 0 12 - 0 0 1 03 - 0 0 1 14 - 0 1 0 05 - 0 1 0 16 - 0 1 1 07 - 0 1 1 18 - 1 0 0 09 - 1 0 0 110 - this is where it resets to 0, as it''s a decade counter.So as you can see Q1Q2and Q3won't divide into perfect square waves, as there times when they are off for longer. like Q1for 8,9,0,1 it will be off, giving a longer gap in the waveform. The same applies to Q2, it's off for 6 counts, but on for 4. So I would actually count out each step, and see if you are seeing intended behaviour for that chip.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: May 03, 2019, 10:35:10 am
content: The rabbit hole goes deep...http://www.ti.com/lit/an/sdya009c/sdya009c.pdfSection 5 has a nice table of the different families wrt rise times and how mixing them can ruin your day.And there is always more than one way to skin a cat... Either a counter with a Schmitt input trigger input or....... an opto with an inbuilt Schmitt trigger output e.g. H11L1M or NTE3090 ?When is DaveCadCon? I'll buy a ticket. Nice to see FUNdament Friday's are back. Great video.

author: EEVblog
author_rank: Unknown
timestamp: May 03, 2019, 10:41:58 am
content: Quote from: LateLesley on May 03, 2019, 10:21:06 amBut we aren't seeing that on the scope. It is supposed to be exactly like the timing diagram.

author: MrAl
author_rank: Super Contributor
timestamp: May 03, 2019, 12:03:31 pm
content: Hello there,The output from an opto coupler has very slow rise and fall times unless it is made specifically for digital logic.As the output ramps up during the rise time, it eventually gets close to the threshold voltage of the logic gate input and then the always present noise can go above and below the threshold voltage several times before the ramp finally gets high enough to overcome the noise completely and then provide a stable logic state. Before it gets past the noise it can clock a counter several times or just a few times just on that one rising or falling edge alone, and that will mean we will see a varying response from the counter chip which means we get garbage out.This is a very common problem even for circuits that dont use opto couplers. Many types of signals are slow rising and falling and so they need to be cleaned up before presented to any type of logical counter. Typically we see a Schmitt Trigger gate being used for this purpose. These kinds of gates have a wider threshold region which means the noise gets lost in between the upper and lower threshold voltage levels. This means we get a nice clean digital signal out of the gate which means the clock input to the counter gets a nice clean signal. After that everything works as expected.Alternately you could look for an opto coupler that has a digital output that is made for the digital logic family you are using.

author: MikeMike
author_rank: Newbie
timestamp: May 03, 2019, 05:39:33 pm
content: Noticed that the optocoupler data sheet says "A 0.1μF bypass capacitor must be connected between pins 8 and 5" (aka Vcc and GND). Doesn't appear to be one on the breadboard.﻿ Adding one might help.

author: donmr
author_rank: Regular Contributor
timestamp: May 03, 2019, 06:00:50 pm
content: Reducing the pullup will speed up the rising edge, but it will alsoslowdown the falling edge! A schmidt trigger is the right answer.Dave also didn't address the series 270 ohm resistor. You don't want that.

author: Peabody
author_rank: Super Contributor
timestamp: May 04, 2019, 01:22:29 am
content: The thing to do is to leave the HC390 circuit exactly as it is, but drive the input from a good, fast signal, and see if it still misbehaves. Well, that's what I would do.

author: Darkwing
author_rank: Contributor
timestamp: May 09, 2019, 04:55:23 am
content: Alrighty then, I have news!I read all of your comments, first of all: thanks!I sat on the breadboard again and: I made it work.But step by step.Here is whatthe status quowas: I captured (with 500ms persistence time) the signal from theHCPL3700optocoupler (1) and the first counting pulse (2) it triggered in theCD74HC390counter … and as you can see: this is garbage. Wild jumps on the logic level, no wonder that the counter produced such a weird looking pattern. The rising edge is somehow ringing, maybe that's why sometimes it was interpreted as an additional falling edge by the counter IC.Here is a capture of the rising edge – this was with 2,2kΩ as a pull-up on the optocoupler and 220Ω as a "pin protection" on the counter:And here is the falling edge of that signal:I then triedsome other optocouplers:6N138andILD620GB– with an even more terrible Fall Time.6N138:ILD620GB:I discarded that and switched back to theHCPL3700. And I was able toclean up my signal.I simply used 100k as a pull-up and connected the optocoupler's output directly to the clock input of the counter. So I use a much higher value now as a pull-up, not a lower one. I don't know why I used the 220Ω resistor as a pin protection in the first place. Guess I had this in my mind from some Arduino tutorials ("Protect your pins! Never connect something directly to the pins or the current will destroy it!" Stuff like that ...).I also decoupled the optocoupler now on pins 5 and 8 with a 0.1µF capacitor like the datasheet suggested. It made a liiiiittle difference, but not much. I also grounded the unused pins of the CD74HC390 counter. It made no noticable difference.And now the signal looks like this – the rising edge:And the falling edge:Much more clean! But it did not want to work. Still counting rubbish.So I decided that it is now time for some zeriouzz Schmitt action! For this, I first moved the optocoupler on the breadboard a little bit away from the counter IC, to make some space for a Schmitt trigger IC. But before installing it, I measured my optocoupler's signal again: lo and behold!, it was even better and now the counter triggered correctly! My pulse signal is divided by 10:(My scope is of course not a 5-channel one – I photoshopped that for you.)This is what you would expect it would look like – but I couldn't believe this. So I switched back and forth and back and forth the position of the optocoupler on the breadboard. Sometimes it seemed to work, sometimes there were some small glitches on the scope, but after all the dividing was correct. So I can only assume, that a mixture of signal quality and bad connnections on the breadboard or the fact alone that I use a breadboard is all part of the problem. I have no clear explanation for this behavior, but I wouldn't trust this arrangement.Soback to the Schmitt!I tried two different Schmitt triggers: theSN74HC14Nand theCD40106BE:SN74HC14N – Fall Time ≈12ns:CD40106BE – Fall Time ≈27ns, but cleaner signal:Side quest:Why is it that with the SN74HC14N (a CMOS device) the signal is faster but more jittered? With the CD40106BE (also a CMOS device), for me it's fast enough, I have clean levels and edges and it works very reliable so far. This means:I'm happyand we solved the problem.So here it is: my little optocoupled, Schmitt-triggered, AC pulse divider:With it I'm dividing the 50Hz mains frequency (Europe) to a 1Hz signal. The LED flashes every second. This was the goal for this project.I hope this was insightful for someone, especially for the beginners who don't own a scope yet, to better understand and see "the inner workings" of all this stuff in more detail. I remember, back in the days, when I was scopeless, I would have wished for some real world pictures and explanations like this.You're welcome to add, comment, suggest and recommend to this learning project.Thanks y'all!

author: Brumby
author_rank: Unknown
timestamp: May 09, 2019, 05:40:45 am
content: Congratulations on success - and having learned some important lessons along the way (I picked up a couple of things.)One point:Quote from: Darkwing on May 09, 2019, 04:55:23 amOnly ground the unused INPUT pins. Grounding outputs could cause you other problems. Input pins are looking for a signal, so grounding these makes that signal stable and known. Output pins aren't looking for anything. Their level is set by the function of the chip. Best leave the chip to set these - leave them disconnected.QuoteQuite often this is the case, but it is good practice. One day you might have a circuit that is susceptible and if you don't ground unused inputs, you might be chasing your tail for a while until you remember this advice.

author: schratterulrich
author_rank: Regular Contributor
timestamp: May 09, 2019, 07:18:21 am
content: To your side question:The faster the signal, the more important the correct probing technique becomes.If you use a ground lead with your probe you can try to roll it up. If the signal changes even a little, you have found the problem.

author: mikerj
author_rank: Super Contributor
timestamp: May 09, 2019, 07:41:36 am
content: Quote from: schratterulrich on May 09, 2019, 07:18:21 amAnd also the more important supply decoupling and a solid low impedance ground becomes. This is why fast logic devices and breadboards are a bad mix.

author: schmitt trigger
author_rank: Super Contributor
timestamp: May 09, 2019, 04:11:13 pm
content: Good job!A good reason for beginners to use CD40xx logic is because it is very forgiving. Specially if your clock frequencies are below 1 Mhz.Now you know.

author: rstofer
author_rank: Super Contributor
timestamp: May 09, 2019, 04:52:44 pm
content: Quote from: Brumby on May 09, 2019, 05:40:45 amIt might be fair to say that some input pins need to be held high. Grounding wouldn't work well.Nevertheless, every input needs to be a some defined voltage within the specified range of either logic 1 or logic 0.I don't prefer to tie inputs directly to Vcc - in the bad old days of TTL, this was considered poor practice and a resistor was almost always used to tie signals high. OTOH, a solid ground, as appropriate, was good practice. Page 2 bottom left paragraphhttp://alt.ife.tugraz.at/datashts/nsc/f6732.pdf

author: Brumby
author_rank: Unknown
timestamp: May 09, 2019, 05:17:32 pm
content: Fair point.High or low ... just don't leave unused inputs floating. But leave the outputs alone.

author: amyk
author_rank: Super Contributor
timestamp: May 10, 2019, 02:34:31 am
content: The oscillation on the optocoupler in the original circuit is interesting, does anyone have a good intuitive explanation? Ringing usually happens only at the edge, but here there's not much of an edge at all and the signal oscillates all the way up. Perhaps it's a combination of high source impedance and inductance?Quote from: Darkwing on May 09, 2019, 04:55:23 amLet's use the correct precise technical term here - "jitter" refers to cycle-by-cycle variance in the period of a periodic signal, whereas what you're seeing is more accurately described as "ringing".Why does the faster edge cause more ringing? A simple analogy can help explain. Remember that every element in a circuit, including the wires and breadboard, contain a combination of inductance, capacitance, and resistance. The capacitance and inductance act mechanically like a weight on a spring; imagine holding one end of a spring, and a weight hanging from the other end. If you move your hand slowly up or down, the weight will just follow the movement. If you move your hand quickly, the spring will stretch more, and then the weight will oscillate up and down several times before settling in its new position. The quicker you move your hand, the more the weight will oscillate.You can already see the effects of parasitics here, but at much higher frequencies (RF, microwave) they become so significant thatthey are effectively the only way to design a circuit!