Maker Pro
Maker Pro

Pre-Scaling a squarewave. Output weird.

Balrock

Mar 1, 2012
39
Joined
Mar 1, 2012
Messages
39
Hello all.
I am using a 74HC4040 to prescaler a 5v p2p square wave from my Signal generator.

When I am in the lower KHz range every thing seems to be working ok and I can see the /2 /4 /8 /16 ... etc output from the 74HC4040. When I start to move into the MHZ range, my scaled output goes a bit weird. I have the output going into a microcontroller (STM32f103) so I can see the captured frequencies as well as measuring on the scope.

If I am at 1MHz my STM outputs to the serial debug 1000.00KHz, 1333.56KHz, 1833.33 KHZ etc. Looking at the 'scope I can see that I am getting not a square wave output but a 'box' (for want of a better word) output. I am wondering if the 74HC4040 is triggering on the rise AND fall of the Source square wave.

It's weird because there are the same 3 or 4 numbers, that look like multiples, everytime. The higher I go, say 7MHz, the worse the output is.

According to the data sheet the 74HC4040 should easily manage that frequency. I have used a 100uf (I think it was that) on the IC as a decoupler but it made no difference. .
I did a screen capture of my scope on my PC but it only showed straight square wave output but some began as a rising squarewave and some began with a falling squarewave. In my mind the 4040 is triggering incorrectly.

I am not sure what to look at next. Any pointers, help or advise is very welcome.
Thanks ... Paul
 
Last edited:

AnalogKid

Jun 10, 2015
2,895
Joined
Jun 10, 2015
Messages
2,895
Without a schematic or scope photos or a photo of the construction, I have nothing to look at, either.

Scope photos? Grounding scheme? Construction photo? Length of the ground lead on the scope probe? Perf board? Solderless proto-board? Power supply decoupling?

Schematic?

ak
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,743
Joined
Nov 17, 2011
Messages
13,743
At 5 V the 74HC4040 is good for at least 30 MHz operation.
Do you realize that the 4040 is a ripple counter and what this means for the output? A ripple counter toggles the first output, then subsequently the second, the third etc. When the period of the clock frequency reaches the delay time of the ripple signal, the first output of the counter may already change while the last output is still waiting for the ripple clock from the previous state change to arrive. This will give weird readings when you look at the output of the 4040 as separate signals. When you look at only a single output everything will look fine.
If you need to have a stable counter output at high clock frequencies you need to use a synchronous counter

100 μF is not suitable for decoupling. Use a ceramic capacitor 100 nF.

I did a screen capture of my scope on my PC
Care to show us? (with a legend explaining the traces, please)
 

Balrock

Mar 1, 2012
39
Joined
Mar 1, 2012
Messages
39
My first post here so sorry for the missing info. I was/am in fact using a 100nf decoupling capacitor.


1MHz squarewave frm my Sig Gen.

20180125_102955[1].jpg


Channel 1 (Yellow) Shows 1MHz squarewave (sort of, not sure why it looks like that)
Channel 2 (Light Blue) 500Hz on the /2 output of the 74HC4040
20180125_103333.jpg



Screen capture 1 from PC shows triggering on rise of the input squarewave

1.jpg



Screen capture 2 from PC shows triggering on fall of the input squarewave.


2.jpg



My circuit is just breadboarded. This photo shows pin 11 going to ground. It is now on pin 14 (Q9 = /512) but in reality I have seen no difference.

circuit.jpg



5v wall wart. I have tried several different ones. Maybe I should make my own supple using a 5v reg?

20180125_064735.jpg





This is my first attempt with KiCAD. It may not be perfect but I hope it shows what you need.
EDIT: My schematic is slightly wrong. It should be Q0 /2, Q1 /4, Q3 / 8, Q4 /16 etc...
schematic.png

I hope this is a little bit more informative. Please feel free to ask for additional information if needed.
 

Attachments

  • 20180125_064735.jpg
    20180125_064735.jpg
    275.5 KB · Views: 71
Last edited:

Balrock

Mar 1, 2012
39
Joined
Mar 1, 2012
Messages
39
I have just tried using my DSO 1kHz probe calibration as the clock squarewave input to the 7HC4040 and I am seeing the same type of triggering. I did think about making a 555 circuit on the breadboard fr test purposes. Reading online it goes upto 500k - 2MHz in theory but I am not sure it is worth it is my 1KHz scope wave is showing the same problem.

What I expect is a steady square wave triggering at the same time consistently but at 1/2, 1/4 , 1/8 etc frequency. I do get that but I get others too that look like multiples. I'll run my Serial debug from my microcontroller and post the results here.
 

Balrock

Mar 1, 2012
39
Joined
Mar 1, 2012
Messages
39
IIt seems your circuit lacks the current limiting resistors in series with the LEDs. The high current through the LEDs will distort the waveform by bringing the outputs of the IC into overload.

I had in the past and just again removed the LEDs. I had seen elsewhere that the resistors were not needed with this particular IC but that may be wrong. Anyway removed and it is still the same.

This is the serial output from my microcontroller. The74HC4040 has a 1MHz input and I am measuring the /2 Q0 output (With no LEDs attached)


screenshot_8.png

Those are the frequencies I keep getting.

It should be
 

Attachments

  • screenshot_7.png
    screenshot_7.png
    9 KB · Views: 83

AnalogKid

Jun 10, 2015
2,895
Joined
Jun 10, 2015
Messages
2,895
A common issue with small wall wart power supplies is that they need a minimum load current to stabilize the magnetics and make a clean, low impedance output. This can have all kinds of strange effects on circuits. If you have a 47 ohm 1 W resistor, add it to the circuit directly across the 5 V output and GND.

The spikes on the signal generator output might be caused by incorrect equalization of the scope probes. Often there is a small variable capacitor built into the connector end of the cable. If the scope has a calibration output, this is what it is for.

What does the long blue wire connect to? That could be another contributor so some of the distortion.

While you often do not need a current limiting resistor when driving an LED with a CMOS output because the output has enough current limiting-ish built in to protect the LED, it is very bad practice and will cause the output to fail over time.

ak
 

Balrock

Mar 1, 2012
39
Joined
Mar 1, 2012
Messages
39
Function Gen I thought exactly the same about the SigGen square wave. It looks exactly like when you have to calibrate a scope lead so I am sure it is a capacitance issue too. I believe you can buy those BNC leads with trimmers in... I'll look and get some.

PSU
Closest I had was a 10 Ohm 7 watt resistor. I tried that and it made no difference to the signals but it could well have made the supply better. I took it off after a short period as it was getting hotter that my fan heater!

Cut the Blue Wire! The Blue wire goes to my microcontroller . i have tried it with it off and still have the same problem. Just tried it again now.

LEDs I take your comments on-board about the LED current limiting resistors and will use them in the future.

Thank you for your suggestions, it was appreciated.
 

AnalogKid

Jun 10, 2015
2,895
Joined
Jun 10, 2015
Messages
2,895
The schematic does not show the LEDs, and the protoboard image does not show how they are powered. Is the common connection to all LEDs Vcc or GND?

Also, do you have a scope shot of any output when *all* LEDs are disconnected?

ak
 

Balrock

Mar 1, 2012
39
Joined
Mar 1, 2012
Messages
39
The LEDs were common Ground. They have now been removed and this is the scope catching both rise and fall triggering.

screen4.jpg screen5.jpg

I am just assuming that is what is causing the false readings as the datasheet for the 4040 says it should only trigger on a falling edge.

screenshot_9.jpg
 

Audioguru

Sep 24, 2016
3,656
Joined
Sep 24, 2016
Messages
3,656
I had seen elsewhere that the resistors were not needed with this particular IC but that may be wrong.
This is not an ordinary Cmos low power CD4040, instead it is high speed , high power HC4040 Cmos. Its datasheet shows a maximum allowed output of 25mA and no more than 50mA for the entire IC.
But an HC Cmos IC can produce 45mA into an LED per output without a current-limiting resistor and you had many outputs active at the same time. This IC might be damaged now.
 

Balrock

Mar 1, 2012
39
Joined
Mar 1, 2012
Messages
39
This is not an ordinary Cmos low power CD4040, instead it is high speed , high power HC4040 Cmos. Its datasheet shows a maximum allowed output of 25mA and no more than 50mA for the entire IC.
But an HC Cmos IC can produce 45mA into an LED per output without a current-limiting resistor and you had many outputs active at the same time. This IC might be damaged now.


Yes you are correct in what you say. I purchased several of them so replaced it with a brand new one with no LEDs connected but I have the same issue.

What I was looking at was supply voltage V logic levels and input square ware logic level from the function generator. I found a CMOS mode on it too. I did find some things out after more research so I will post on here again tomorrow but I want to rebuild a basic version of the circuit on a new breaboard that came in the post. I'll check logic levels as I go and use new parts.

I'll keep you posted.

Thanks everyone for your help and suggestions.

EDIT: I would also like to mention while I am not new to electronics my knowledge is missing in quite a lot of areas so all suggestions are welcome. The issue concerning LEDs and power requirements of the IC is a case in point. As a relative 'start again'er' its easy to look at those data sheets and get overwhelmed. I will keep trying and keep learning :)
 

AnalogKid

Jun 10, 2015
2,895
Joined
Jun 10, 2015
Messages
2,895
The LEDs were common Ground. They have now been removed and this is the scope catching both rise and fall triggering.
I don't see any triggering on a rising edge. Also, the output trace now is not at all distorted.

It is ok for the chip to drive multiple LEDs as long as you keep the currents very low. For a 5 V circuit and 2 V LEDs (a very common Vf value), place a 2.7K to 3.3K resistor in series with each one. 1 mA per output should not cause any problems.

ak
 

Alec_t

Jul 7, 2015
3,591
Joined
Jul 7, 2015
Messages
3,591
Agree with AK. Trigger point (start of the ringing on the 4040 output trace) coincides with clock falling edge only.
 

Balrock

Mar 1, 2012
39
Joined
Mar 1, 2012
Messages
39
I don't see any triggering on a rising edge. Also, the output trace now is not at all distorted.

It is ok for the chip to drive multiple LEDs as long as you keep the currents very low. For a 5 V circuit and 2 V LEDs (a very common Vf value), place a 2.7K to 3.3K resistor in series with each one. 1 mA per output should not cause any problems.

ak

I believe I purchased a DIL resistor pack that will do just the job. I'll have a look tomorrow when I rebuild incorporating all of everyone's advice.
I believe I has misunderstood the scope capture. I saw the falling edge of the output (blue) and thought it was triggered by the input but it was actually the falling edge of an already high squater wave. So this assumption was wrong.

What I don't understand is why the scope looks like it does with the output imprinting over itself. Is it a normal frequency thing? Why isn't it just like the capture? The input (yellow) is stable why isn't the output? I realise by asking this I may open myself up ridicule for not knowing! :)

20180125_100609.jpg
 

duke37

Jan 9, 2011
5,364
Joined
Jan 9, 2011
Messages
5,364
The 'box' display is because the scan is running at the wrong speed. Thus on one scan, you get a square wave and the next you get another square wave offset between the first one.
Set the scope to trigger on the blue waveform not the yellow one.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
A simple technique is that if the display looks funny, try triggering on the other signal (also try triggering on falling rather than rising).

In this particular case we can see that on a falling edge of the yellow waveform, the blue waveform can have a rising or falling edge.

If the scope triggers after an even number of rising (or falling) edges, the display will look normal. However, Murphy will ensure that it triggers after an odd number of edges, so the blue trace is inverted on alternate sweeps.

In this case there are multiple solutions. The best, as mentioned previously is to sync on the blue trace. However, you can also use a variable trigger delay to tweak things so that the triggering occurs on even edges. Similar to this, slightly changing the timebase can force it into sync.

Now, as to the reason the lower trace looked funny (not square waves) may be due to an interaction between the heavily loaded outputs. I suspect that you had a LED on an output changing faster than this one. The current drawn on one output may have affected the ability of this output to drive it's load (another LED) resulting in a reduced voltage swing.
 

Balrock

Mar 1, 2012
39
Joined
Mar 1, 2012
Messages
39
A simple technique is that if the display looks funny, try triggering on the other signal (also try triggering on falling rather than rising).

In this particular case we can see that on a falling edge of the yellow waveform, the blue waveform can have a rising or falling edge.

If the scope triggers after an even number of rising (or falling) edges, the display will look normal. However, Murphy will ensure that it triggers after an odd number of edges, so the blue trace is inverted on alternate sweeps.

In this case there are multiple solutions. The best, as mentioned previously is to sync on the blue trace. However, you can also use a variable trigger delay to tweak things so that the triggering occurs on even edges. Similar to this, slightly changing the timebase can force it into sync.

Now, as to the reason the lower trace looked funny (not square waves) may be due to an interaction between the heavily loaded outputs. I suspect that you had a LED on an output changing faster than this one. The current drawn on one output may have affected the ability of this output to drive it's load (another LED) resulting in a reduced voltage swing.

Excellent answers guys and I just learned more thing that will help me a lot in the future. There are no LEDS on the circuit at the time of that photo and it was a new chip. However I will do a rebuild in a few moments with a new IC and see how it goes.
 
Top