Maker Pro
Maker Pro

Question about carryover on 4017

Hello all, playing around with the 4017 for some fun and simple 'board' time :)

While toying with the decade counter, I discovered that the carryover bit triggers on the fifth output and stays lit through the ninth. Sure enough the datasheet confirms the carryout bit goes high as above and low on bits zero through four.
Why?
I thought the purpose of the decade counter was to trigger the carryout bit on the 9th bit going high. Why have it trigger on when bits 4-9 are high? I was assuming that the purpose of the c.o. bit was so that you could cascade and continue counting higher, but I don't see how with the way its set up.
Can someone please explain?
Thanks in advance.
 

hevans1944

Hop - AC8NS
You have the carry output inverted (see Fig 2 - Timing Diagram for CD4017B). The carry output is high for counts 0 through 4, going low on count 5 and staying low during count 9 until the rising edge of the clock sets the counter back to 0. The carry output has to go low sometime before it can "ripple clock" the next counter stage on its low-to-high rising edge. The fact that it goes low when the counter enters state 5 and stays that way through states 6, 7, 8, and 9 is because of the manner in which a Johnson counter (a form of ring counter) propagates a pattern of ones and zeroes around the ring. More information on Johnson counters can be found in this Wikipedia article.

The main advantage of the 5-stage Johnson (ring) counter is that all the flip-flops are clocked synchronously and simultaneously with one clock, allowing much faster operation compared to a ripple counter where the clock must propagate from stage to stage. A side effect is the way the carry output is created.
 
You have the carry output inverted. A side effect is the way the carry output is created.

Sorry, was working from memory of yesterday's experiments!

So the c.o. is a side effect of the architecture?

If you wanted to use this as a decade counter, would you then have to simply watch and trigger on the rising edge between bit 9 and 0?
 

hevans1944

Hop - AC8NS
So the c.o. is a side effect of the architecture?
Yes, and how the flip-flops are connected in a ring to circulate a pattern of ones and zeroes. I haven't verified this, but the pattern is supposed to be a Grey Code, which means on each clock transition only one bit in the pattern changes. Not that you should care: the end-user does not have access to the internal states of the five flip-flops, only their decoded states 0, 1, 2, ... 7, 8, 9 plus the carry output.

If you wanted to use this as a decade counter, would you then have to simply watch and trigger on the rising edge between bit 9 and 0?
It is a decade ring counter, decoded for your pleasure and convenience. Connect the carry output (pin 12) to the clock input (pin 14) of the next decade. You can continue this indefinitely for as many stages as desired. However, with this method the stages are clocked as ripple counters, and you may not want this for long count lengths because the counters are more susceptible to noise. Extra external logic could be used with the clock-inhibit input to disable the extra counters and clock them, in parallel with the input clock to the first decade counter, but only during decade transitions. I don't know that anyone has actually gone to this much trouble to ensure synchronous internal bit transitions across multiple counters, but it is certainly something to consider if there is a long counter chain where the carry output remains in a vulnerable-to-noise low state for extended periods of time. Besides clock skew, which limits the upper counting frequency, susceptibility to noise on a "clock" line with a long cycle time is a big disadvantage of ripple-carry clocking of successive counters.

Imagine, if you will, that you have a very low-level light sensor, a photo-multiplier tube perhaps, that responds to single photon events. You count these events with a string of CD4017B decoded decade counters arranged for ripple-carry clocking. The count accumulates for a specified interval, typically a few seconds to perhaps several hours. The final count is a function of the light intensity you are measuring. What are the chances that during this counting interval a noise pulse will advance one of the more significant digits of the counter? With a good design and layout, perhaps the chances are small. But if it is important to obtain an accurate count over a long period of time, it would be better to disable the more significant counter digits until it is actually necessary for them to change on the next (relatively narrow) clock pulse. There are synchronous counters (both binary and decade) that make it easy to do this.

Another common application for the 4017 is to extend the "walking ones" output to more stages. The TI datasheet, Fig. 19 - Cascading the CD4017B, has an example of one way to do this. TI does It by inhibiting the clock to the first stage when it reaches a count of 9. Thus the first stage counts 0, 1, 2, ... 7, 8, 9 and stops on 9. The common clock line for the remaining 4017s is passed through an AND gate to allow each of those stages to be clocked, but only when the preceding stage has reached a count of 9. Thus each additional stage will count 0, 1, 2, ... 7, 8, 9 and stop on 9. As each 4017 stage reaches its count of 9, this is fed back to raise the active-high clock inhibit input to a high state, disabling that particular 4017. The last stage has its decoded "9" output fed back to the reset input of the first stage, causing it to change from 9 to 0. The decoded "0" output of the first stage is applied as a reset to the next stage, which repeats the process by resetting the next stage, and so on until this ripple-propagated reset reaches the last stage. There may be some problems with this design as the internal flip-flops of the ring counter could come on with random states, requiring some sort of power-on reset to ensure all stages are reset to zero before beginning counting. Notice too that the "0" count is not used in subsequent stages, so each stage has only eight distinct outputs: 1, 2, 3, 4, 5, 6, 7, and 8. The "0" state is always on until that stage is clocked, and the "9" state stays on when it is reached until that stage is reset.

If you are thinking of using the CD4017B to implement the "21" game that @Rich Man offered up in this thread... well, I can think of better things to do with my time. But you could steer twenty outputs of three counters through small-signal diodes to enable "computer" clock pulses that would advance the display the requisite number of times, each time the "computer" makes its move. In other words, wire the diodes to implement the logic on the stepper "locking deck" in the image that @73's de Edd posted in reply #7 to that thread. :cool: Ummm... is the sawdust collector operational yet? :D

Hop
 
There may be some problems with this design as the internal flip-flops of the ring counter could come on with random states, requiring some sort of power-on reset to ensure all stages are reset to zero before beginning counting.
Perhaps a logic gate, to switch the reset during power on vs. during run time? Might need a latch as well to determine between the states...

If you are thinking of using the CD4017B to implement the "21" game that @Rich Man offered up in this thread... well, I can think of better things to do with my time.
LOL, no, I am burdened down with my own projects, I just so happened to have some 4017's on hand and thought it would be fun to breadboard a seemingly 'simple' IC. No offense intended to anyone, but demuxing a pic pin is a severe pain in the rear in comparison.... I also ordered some basic quad logic gates to have on hand, a few bucks for 10 each nand,and, nor & or IC's. I want to have them on hand for when I get through my current reading list to have a go at this interesting title.

Ummm... is the sawdust collector operational yet?
err....uh, no :oops::eek::D and tis a pity.... I have a large closet project that needs to be cut up and it's pretty humid out... It would have been nice to not have to bathe in sawdust mixed with sweat! :mad::mad: To my credit, I did spend some time last week breadboarding the 12F675 and got as far as initializing the pic, startup registers, etc. and got to ouput to one pin. (LED on). My goal is to write enough code to simulate on the breadboard with low voltage only. I intend to feed a low voltage signal into my adc's on the pic to simulate the output of the allegro chips and to test the 'turn on' thresholds and adjust as necessary. Perhaps by the end of the week, I can scab together some code and post it on that long thread!

BTW, 'simple' is debatable. Had I not known about debouncing a switch from various pic tutorials, I would still be having fits :p - I put a 4.7kΩ pull down resistor between the switch and clock in pin of the 4017 and I have fairly stable switch response, it still trips and skips, so I will experiment with a higher value as well as introducing a capacitor.

edit - fixed this morning with 472 sized cap. - completely debounced!
 
Last edited:

hevans1944

Hop - AC8NS
Perhaps a logic gate, to switch the reset during power on vs. during run time?
Yes, a power-on reset circuit is easily constructed with a resistor, capacitor, small signal diode, and a Schmitt-trigger 2-input NAND gate. Connect resistor and capacitor in series with Vcc to circuit common, place a diode across the resistor for the capacitor to discharge into when Vcc goes to zero, connect the junction of capacitor and resistor to one of the inputs of the NAND gate. The other input to the NAND gate is held high by inverting the active-high reset signal from the CD4017B ripple-reset chain.

NAND output will be high initially (representing the RESET signal) until capacitor charges toward Vcc and causes the NAND output to go low and stay low as long as power is applied and the other ripple-reset input remains high. Remove power and the capacitor quickly discharges through the diode (anode of diode is connected to capacitor, cathode is connected to Vcc) in preparation for another power-on event. The NAND gate is inserted in the reset chain of the CD4017, by means of a hex inverter element on its other input. The ripple-reset from the "9" output of the last stage is active-high, so you disconnect this line from the reset input of the first stage and connect it through an inverter to the second input of the NAND gate. The NAND gate output replaces the former connection to the reset input of the first stage.

I put a 4.7kΩ pull down resistor between the switch and clock in pin of the 4017 and I have fairly stable switch response, it still trips and skips, so I will experiment with a higher value as well as introducing a capacitor.
Since you now have a stash of (hopefully) CMOS logic gates, liberate a hex inverter or a quad NAND or quad NOR and cross-connect the outputs of two of these and use with a SPDT switch to create a clean, de-bounced, "clock" for your CD4017B. Common terminal of switch to ground, N.O. and N.C. contacts to other NAND inputs or to cross-connected inverter inputs. If using NOR gates, pull up switch common to Vcc and use 10 kΩ pull-down resistors at switch contacts (NOR gate inputs).

images


images


upload_2016-5-25_12-42-56.png

Note that for the NOR gate implementation, R1 and R2 in above diagram are waaaay too low in value and would represent a constant 50 mA drain on the +5 V logic supply! I don't recommend using NOR gates for TTL de-bounce logic, and if using CMOS NOR gates, 10 kΩ should be enough pull-down to create a logic "0" condition. Use NOR gates for de-bounce only if that's all you happen to have available. I much prefer the two hex-inverter approach for its simplicity.

I intend to feed a low voltage signal into my adc's on the pic to simulate the output of the allegro chips and to test the 'turn on' thresholds and adjust as necessary.
That's always a good idea. Analog signals can be a bitch kitty to troubleshoot compared to digital logic. And don't forget the Allegro will be putting forth a faithful AC representation of the load current as a DC signal with the AC current superimposed, the zero of the AC waveform being at Vcc/2 or 2.5 V with a 5 V DC supply. That means the A/D conversions will be all over the map, and you will have to make a lot of them to find the peak amplitude for your threshold adjustment. A "better" way might have been to add a peak detector to the output... a capacitor in series with the output (to suppress the 2.5 V DC offset), followed by a diode to common in parallel with a peak-holding capacitor to rectify and hold the peak AC signal. Such a simple circuit would greatly simplify the software since you would then only have to look for a DC voltage greater than your threshold setting. The PIC might not like it though. It wants to "see" 10 kΩ or less source impedance. You could connect a loading resistor in parallel with the diode and the holding capacitor to satisfy the source impedance requirements for the PIC, but that would decrease the amount of signal available for digitizing unless you made the peak-holding capacitor large enough to compensate for the current drawn by the loading resistor. Not much room on your circuit board to add these modification, so perhaps the software solution is "better" in the sense that no hardware hacking is required... just some fancy programming to find the peak-to-peak AC values, subtract the smaller from the larger, and compare that difference with your current-setting threshold. Ain't programming fun?:D

Hop
 
My parts are on the slow boat, perhaps a few weeks, LOL. Thank you for the detailed explanation, I sometimes get the broad strokes and can see a logical path, but actually sitting down to draw a schematic to follow, I get a bit lost... But I keep trying for that view :D

And don't forget the Allegro will be putting forth a faithful AC representation of the load current as a DC signal with the AC current superimposed, the zero of the AC waveform being at Vcc/2 or 2.5 V with a 5 V DC supply
Now you've lost me :confused: - I thought the Allegro chip we chose was a hall effect current monitor and completely isolated. I did a quick review of the datasheet and did not spot any mention of a superimposed AC on the output. Let me know, I thought it was going to be a bitch to simply learn ADC input on the pic and then write code to if,then between a range! Now we need to filter the results and then search for a range - might run out of memory again, LOL :rolleyes:
 

hevans1944

Hop - AC8NS
actually sitting down to draw a schematic to follow
Hmm. I have the same problem posting schematics here in the Forum. I can draw a schematic and photograph it and eventually figure out how to retrieve the image and post it here... but it seems so much simpler to just describe the circuit and let someone else use a schematic-capture program to post it. Maybe I am just lazy because I do have several schematic-capture programs that I've tried. I have even tried using Microsoft Paint but usually give up in frustration. But I will keep trying and eventually will be able to post "pretty" schematics instead of photos of hand-drawn schematics. I try to follow in the footsteps left by Robert Pease, who never drew "pretty" schematics but still was able to communicate if the reader persevered in deciphering Bob's "chicken scratches".

Now you've lost me :confused: - I thought the Allegro chip we chose was a hall effect current monitor and completely isolated.
It is a Hall Effect sensor, and it is completely isolated. A Hall Sensor produces a positive or negative output, depending on the direction of the magnetic field producing the Hall Effect. At zero current, the output of the Allego will be at Vcc/2 which is clearly stated in the datasheet. For positive current the output increases toward Vcc. For negative current the output decreases toward circuit common. If the current is AC, the output will be an AC sinusoid oscillating above and below the 2.5 V "zero current" level. See image below from page 6 of the Allegro ACS712 datasheet, which shows the response for ±5 A currents, producing about 1.5 V output for -5 A and 3.5 V output for +5 A. This is actually a "good thing" because it allows analog multiplication by the voltage across a load to calculate real power delivered to the load. Not that you want to do that, but it is a "feature" to keep in mind. The Allegro is an analog device that reproduces the analog current input (AC or DC) as an analog voltage on the output, offset by Vcc/2 because it operates from a single supply.

upload_2016-5-25_21-0-53.png

It is a relatively trivial software algorithm to measure and compare a value digitized by the PIC ADC against previous high and low values temporarily stored in PIC RAM, replacing the high value if the current A/D value is greater, or replacing the low value if the current A/D value is lesser. You just need to be sure that you sample enough of the 60 Hz waveform to assure that the maximum and minimum values are found.

This means you should loop until those values don't change anymore for a "constant" AC current. At that point you do the subtraction of the minimum value from the maximum value and compare the difference to your threshold value. You do this subtraction before the comparison to eliminate any drift in the "zero current" output. Once the determination has been made that the peak-to-peak AC current is above or below the threshold value, you take whatever action is required as a result of that determination. Then you set the maximum and minimum values back to "zero," which will be half the full-scale A/D output, and go through the max/min measuring process again. I would set two flag bits in a RAM status byte to indicate whether a comparison resulted in the replacement of a previous maximum or minimum value, setting both flag bits initially, and clearing the appropriate bit only if a substitution does not occur for the max or min value associated with that bit. When both bits have been cleared you can be assured that the maximum and minimum values have been discovered. Or so it would seem. I have never actually written any code that does all this.:p

You are going to have a lot of "fun" learning how to use the ADC function in the PIC.

Hop
 
but it seems so much simpler to just describe the circuit and let someone else use a schematic-capture program to post it.
I have no problem inputting the information to Eagle, its getting the information that is the trouble for me! I can envision what I want done, I can roughly flowchart it, but that is where the broad strokes end... It's a knowledge gap and I am working on filling the voids. It's taking some time though ;)

At zero current, the output of the Allego will be at Vcc/2
I did see that, but I thought that the output would be DC - automagically....

You are going to have a lot of "fun" learning how to use the ADC function in the PIC.
I have the pain...
 
Top