My first standalone project - chceck correctness please

I agree with most of the content regarding schematic design, although I don't hesitate to break any and every rule in the name of clarity. The single most crucial aspect of schematic design is that it is readable. Everything else is merely a suggestion. Your latest sketch is many times better in this regard. I found the originals difficult to follow, whereas this one is pretty good.

Now my suggestions, mostly with regard to your power supply design --

  • First, add a diode at the power input. This will protect your circuit in case the DC barrel connector's polarity is accidentally reversed.

  • Ditch C1 and C7 in favor of a single large 100uF cap at the power supply input. There's no good reason to put separate bulk caps at each regulator unless they're far apart. As to the larger size, I always prefer a little more capacity when the power supply is capable. (100uF is a bit much for USB powered devices, but a decent wall-wart will have no issue with it.)

  • C2 is OK at 10uF, given the likely current demands on the 5V circuit, but I would use something like a 47uF instead just because you can.

  • C8 should probably be something like 47uF to 100uF, since fans tend to be current hogs at times.

  • In addition to bulk capacitance (the larger electrolytics) it's a good idea to use 0.1uF to 0.33uF ceramic caps on each side of the regulators. This prevents over/under-shoot oscillations. Electrolytics are good for smoothing larger ripples, but can be slower to react to high frequency variations due to higher internal resistance. Ceramic caps are better at this, but get large and expensive at bigger capacities -- so you can use both in parallel.

  • Put a diode in reverse across the regulators (anode on pin 2, cathode on pin 1 -- or in schematic terms, like this: 1 --|<|-- 2). This ensures the input side is ALWAYS higher than the output side, which prevents backwards flow if power is removed from the input, while charged capacitors or other external voltage exist on the output side.

  • I would recommend reconsidering the 19V input entirely. That means you're dropping 14V across the 7805, which will mean lots of heat. You'll have to heatsink that IC, especially if anything draws more than a few mA of current. Is it really necessary to provide regulated 12V DC? If you're only powering fans on the 12V bus, just use a 12V power supply instead, and leave the 7812 out entirely.

  • You should put a 0.1uF ceramic cap between the high side (pin 1/2) of every switch and ground. This prevents "switch bounce", which is a spiky oscillation as the switch contacts intermittently begin (or stop) conducting during button presses. Unless you either use a cap, or sample the input pins multiple times and average the results, you'll likely trigger multiple "presses" every time your press a button, which is enormously frustrating.

  • You're probably already doing this, but just to make sure, you are enabling the internal pull-ups on pins 13, 14, 18, and 19 (the pins connected to switches), right? If not, you'll need to pull them up to Vcc with 10K resistors. Otherwise, when you read those pins without the switch pressed, you'll get random results -- because the pin is floating and has no defined voltage.

As you can tell, in circuit design, you use a lot of 0.1uF ceramic caps. I buy them 25 to 100 at a time for that reason. :slight_smile:

SirNickity's comments are well on point however a slightly different view would be to ditch the 12 V regulator for a switcher and use a low power 5 V linear device to power the controller. There is a National Semiconductor LM2575T in a TO220 package good for an ampere and a Linear Tech LT 1174 good for 300 mA in an SO-8 package. Both come with reference designs and recommended PCB layouts as well. The total package power dissipation is cut by 50% or more due to offloading the fans to the 12 V switcher. The additional board area required for the switcher components will be more than offset by the smaller required heatsink for those components compared to the linear solution. The balance of SirNickity's comments on bypassing are correct and to the point. It is accepted design practice to add capacitors to a design and them test a handful to see exactly what the board requires due to the L's and R's imposed by PCB traces and then finalize the stuffing instructions to realize only the required parts.. Holes are cheap... The time to make new holes or their equivalents is not.
There is a distinct possibility that at your current experience level a switcher is not really a great idea. If for any reason, after you have read the applicable data sheets you feel any reservation then leave them for another day. The first design is more about "I Did It" and what that means than anything else. Once you "Do" a few then it's time to look at "How" you "Do" them.

Doc

LM2575T.pdf (422 KB)

LT1174fe.pdf (257 KB)

SirNickity:
Your latest sketch is many times better in this regard. I found the originals difficult to follow, whereas this one is pretty good.

Absolutely!

SirNickity:

  • First, add a diode at the power input. This will protect your circuit in case the DC barrel connector's polarity is accidentally reversed.

There are always two options here. One is a series diode, and since there already seems to be a surplus of voltage, a silicon diode would seem sufficient. If voltage drop is more critical, a Schottky diode and alternatively, a shunt or "crowbar" diode of sufficient capacity to safely (at least from the viewpoint of this particular circuit, but appropriate with switchmode supplies) bring down the supply.

SirNickity:
Ditch C1 and C7 in favor of a single large 100µF cap at the power supply input. There's no good reason to put separate bulk caps at each regulator unless they're far apart.

Quite so.

SirNickity:
C2 is OK at 10µF, given the likely current demands on the 5V circuit, but I would use something like a 47µF instead just because you can.

I would suggest the opposite. 10µF should be more than sufficient; it is the regulator's task to supply current on sudden demand; these capacitors are only present to stabilise the regulator at frequencies beyond its response. More important is to ensure that the reference (ground) terminal has the lowest possible impedance to the ground and is as far as possible, a "star" point for supply and load. Using ground "spill" or "fill" as far as possible is likely to enhance this. Better to maximise - as you have said - the input capacitor.

SirNickity:
C8 should probably be something like 47µF to 100µF, since fans tend to be current hogs at times.

Ditto my comment above.

SirNickity:

  • In addition to bulk capacitance (the larger electrolytics) it's a good idea to use 0.1µF to 0.33µF ceramic caps on each side of the regulators. This prevents over/under-shoot oscillations.

But they should go to the star point, not just to the regulator reference pin - so the circuit diagram as posted is still a trifle misleading in this respect.

SirNickity:
Put a diode in reverse across the regulators (anode on pin 2, cathode on pin 1 -- or in schematic terms, like this: 1 --|<|-- 2). This ensures the input side is ALWAYS higher than the output side, which prevents backwards flow if power is removed from the input, while charged capacitors or other external voltage exist on the output side.

That is in fact, one reason the output capacitors should be kept small. If you can ensure the supply capacitor has sufficient reserve (and you have a series diode feeding it), it will be continuing to feed the circuit as the output voltage falls, and these diodes are unnecessary.

SirNickity:
You should put a 0.1µF ceramic cap between the high side (pin 1/2) of every switch and ground. This prevents "switch bounce", which is a spiky oscillation as the switch contacts intermittently begin (or stop) conducting during button presses. Unless you either use a cap, or sample the input pins multiple times and average the results, you'll likely trigger multiple "presses" every time your press a button, which is enormously frustrating.

Sorry, the capacitor does not prevent switch bounce, but does cause substantial transients (even worse than bounce!) and wear on the switch contacts (unless extra resistors are employed).

Debouncing should always be performed in software. The algorithm to do so a byte at a time (that is, eight switches) is quite straightforward (though I would have to recall it from some thirty-odd years ago).

SirNickity:
As you can tell, in circuit design, you use a lot of 0.1µF ceramic caps. I buy them 25 to 100 at a time for that reason. :slight_smile:

As one does.

Please understand that the process you follow may be OK for an Arduino device that you will build and use in your home BUT you should not be using these "procedures" in real products.

If you design a circuit for a commercial product and then test it under varying conditions, you don't, at a later time, go through and remove capacitors. If it is working, don't fix it!

Good conversation, a lot can be learned from all the different perspectives.

Paul -- you raise a good point about the output reservoir caps. Maybe I should reconsider and sim a different approach than I usually take there.

But, on the switch bounce topic, doesn't the pull-up resistor achieve the effect you're talking about? Or do you mean to have another R between the switch and C+? I try to avoid using software debounce since it's code clutter (for sure not much, but still) and necessarily delays the execution of following statements. Again, not by much, but in a busy sketch, and especially when the switch is actually a rotary encoder triggering an ISR, I would prefer to keep the time spent reading pins to the absolute minimum.

Interested in your follow-up thoughts, if you have the time. 8)

The pull-up resistor (whether in the chip or external) limits the charging of the capacitor, but not the discharge, so it is asymmetric. You can put a resistor in series with the switch of a value less than a tenth of the pull-up value which will limit the impulse when the switch is closed - this will still be asymmetric - or if you have an external pull-up, you can put a resistor between the switch plus pull-up and the capacitor plus input line greater than ten times the pull-up which gives you fairly symmetric charge and discharge.

You do get a plausible debounce with a capacitor only because the chip input is a Schmitt trigger - if it was not, it would still be possible for the capacitor voltage to fluctuate with the bounce waveform, across the threshold voltage. The necessary penalty is requiring a quite long time constant to ensure the correct behaviour.

I am not sure why you would be using a rotary encoder triggering an ISR - this (use of an ISR) suggests to me that you are monitoring a high-speed device generating some kilohertz, and I would expect such an encoder to have inherent debouncing by hysteresis in its optical system.

I am thinking in terms of manual input devices such as pushbuttons, keyboards and manual rotary encoders where the debounce is performed in the one millisecond supervisory cycle using three memory variables: "prev_state", "last_state" and "count" and the key array is read as "now_state". On each cycle, if now_state differs from last_state, the count is set to the delay value - such as 20 - and last_state is set to now_state. If now_state == last_state and last_state differs from prev_state, then the count is decremented and if it reaches zero, then the (combined, as it is an array) difference between last_state and prev_state is acted upon, prev_state is set to last_state and the count is reset to the delay value.

Such code is quite compact (particularly as you can debounce eight inputs simultaneously with ease - you do not expect more than one or two manual inputs to occur simultaneously anyway), and performed in a non-time-critical fashion at the millisecond cycle rate which is obviously where I was expecting the OP to be using it.

I see what you're saying. As an honest question, is the discharge of a 0.1uF cap charged to 5v much of a concern to switch contacts? (I imagine it would depend on the switch of course.) Either way, you've given me some things to think about regarding noise and hysteresis. When I get some time, I'll have to set up some test circuits and see what happens on a scope. Thanks for the critique, I appreciate it.

To answer some questions:

Why trigger an ISR? Simply, pin-change interrupts. They're available, easy to use, and depending on the code, maybe preferable to polling. Couple of examples: Long loop() cycles, low clock speeds, sleep states, cases where it makes for more logical code paths. Or maybe "just because". The functional difference between reading pin states every loop() cycle, or setting marker variables in an ISR and checking for those in a loop is pretty much down to whims of the programmer in perhaps most cases.

Re: rotary encoders... No, not kHz speed. So far, only manual knobs. Although I have some back-burner projects involving rotational sensors (i.e., hall effect or optical).

If I'm understanding you correctly, you're talking about using something like a timer interrupt to perform UI polls every 1ms or so?

About half way down this page is an oscillogram of a 100 nF cap and a 10 K resister where the open end of the resistor is grounded and it would appear that the combination does a great deal to debounce the signalhttp://www.gammon.com.au/forum/?id=11637.

Doc

Well, to be fair, a TTL pulse isn't exactly the same kind of impulse as a pressed switch button. :grin:

No I agree but the effects are reasonable better with it than without... Which seems to agree with your 'standard practice'... Mine too I wouldn't go without it.

Doc

SirNickity:
As an honest question, is the discharge of a 0.1µF cap charged to 5v much of a concern to switch contacts? (I imagine it would depend on the switch of course.)

Perhaps, perhaps not. It most certainly depends on what sort of switch it is - in the case of more robust switches, some arcing is considered beneficial in keeping the contacts clean. If you look at the specifications for these miniature switches, you will not that they are qualified for milliamps, not amps, so even a tiny spark, repeated, can be significant. To say nothing of those consisting of metallised pads on flexible plastic - though their inherent resistance may (or may not) be protective.

SirNickity:
Why trigger an ISR? Simply, pin-change interrupts. They're available, easy to use, and depending on the code, maybe preferable to polling. Couple of examples: Long loop() cycles, low clock speeds, sleep states, cases where it makes for more logical code paths. Or maybe "just because". The functional difference between reading pin states every loop() cycle, or setting marker variables in an ISR and checking for those in a loop is pretty much down to whims of the programmer in perhaps most cases.

My perception is to use interrupts for priority events. Not entirely sure about "easy to use" as (and as you observe,) what you do in an interrupt routine - at least in this context - usually needs to be communicated by a semaphore to the non-interrupt routines in order to be acted upon which means code in both places.

SirNickity:
If I'm understanding you correctly, you're talking about using something like a timer interrupt to perform UI polls every 1ms or so?

But accuracy is not important. If you have a "heartbeat" loop, it makes sense to use it - noting that this is usually for low priority (or slow) events. Generally if the debounce routine happens to run slow on occasion, it is not a catastrophe.

Commonly, you have a "main" loop - the thing called "void loop() { }" in the Arduino IDE. This may or may not be isochronous, or to varying degrees (isochronous loops can be very effective), but it is not inappropriate to use this for the debounce if you can estimate the average loop time and consider it "near enough".

(I have chosen not to go into the considerations of a system which sleeps to conserve power.)

Docedison:
About half way down this page is an oscillogram of a 100 nF cap and a 10 K resistor where the open end of the resistor is grounded and it would appear that the combination does a great deal to debounce the signal.

I fail to see how a series capacitor "one shot" - which incidentally, has its own design problems to do with voltages exceeding the specified input range of the chip involved - has any relevance whatsoever to the matter of switch contact debouncing by the use of a parallel capacitor. I don't think you have understood my points, particularly those relating to impulse generation within the current loop comprising the capacitor on the PCB, the ground connections on the PCB and the leads connecting it to a remote switch.

It is salutary to remember that a rotary mechanical switch (or spark gap) of substantially more robust construction and dimensions, is the most commonly used form of exciter for the Tesla coil enthusiasts.

At first thanks for the critique. I read all comments and something is still not clear for me.

  • First, add a diode at the power input. This will protect your circuit in case the DC barrel connector's polarity is accidentally reversed.

I dont know, if should add diode to plus or minus pole of power supply. I added it at the minus because when reverse polarity, current will stopped immediately at beginning of circuit and will not come through any component.

Ditch C1 and C7 in favor of a single large 100uF cap at the power supply input.

C1 and C7 replaced by single 100uF capacitor

C8 should probably be something like 47µF to 100µF, since fans tend to be current hogs at times.

C2 is OK at 10µF, given the likely current demands on the 5V circuit, but I would use something like a 47µF instead just because you can.

I would suggest the opposite. 10µF should be more than sufficient; it is the regulator's task to supply current on sudden demand; these capacitors are only present to stabilise the regulator at frequencies beyond its response. More important is to ensure that the reference (ground) terminal has the lowest possible impedance to the ground and is as far as possible, a "star" point for supply and load. Using ground "spill" or "fill" as far as possible is likely to enhance this. Better to maximise - as you have said - the input capacitor.

Ok, I kept 10uF for Paul_B advice. But I dont understand what do u mean by ground "split" or "fill"

  • In addition to bulk capacitance (the larger electrolytics) it's a good idea to use 0.1µF to 0.33µF ceramic caps on each side of the regulators. This prevents over/under-shoot oscillations.

But they should go to the star point, not just to the regulator reference pin - so the circuit diagram as posted is still a trifle misleading in this respect.

Another sentences that is not quite clear for me. Can you explain it me more in details Paul?

You should put a 0.1µF ceramic cap between the high side (pin 1/2) of every switch and ground. This prevents "switch bounce"..

I am preventing switch bounce in SW like Paul says...

Put a diode in reverse across the regulators (anode on pin 2, cathode on pin 1 -- or in schematic terms, like this: 1 --|<|-- 2).

That is in fact, one reason the output capacitors should be kept small. If you can ensure the supply capacitor has sufficient reserve (and you have a series diode feeding it), it will be continuing to feed the circuit as the output voltage falls, and these diodes are unnecessary.

Paul says it is unnecessary and I belive him, so I didnt place them.

I would recommend reconsidering the 19V input entirely. That means you're dropping 14V across the 7805, which will mean lots of heat. You'll have to heatsink that IC, especially if anything draws more than a few mA of current. Is it really necessary to provide regulated 12V DC? If you're only powering fans on the 12V bus, just use a 12V power supply instead, and leave the 7812 out entirely.

19V input entirely is because of supplying led drivers and series of leds. I didnt want multiple power for LEDs and controller. Is it really bad idea 19 power suply for controller, when I add an heatsink? I should add 5V power supply, but it means one more wire.

  • You're probably already doing this, but just to make sure, you are enabling the internal pull-ups on pins 13, 14, 18, and 19

Yes, I am using internal pullups.

Please understand that the process you follow may be OK for an Arduino device that you will build and use in your home BUT you should not be using these "procedures" in real products.

Yes, it is device, that I will use at home. It is good project to lear basics of designing own Atmega circuits...

I also replace buttons in scheme by holes, because buttons will not be at PCB, they will be lead out of box. Here is my actual scheme:

A "star" configuration refers to the arrangement where all ground connections, and in this case particularly those of the regulator reference pin, the bypass capacitors, the power source and the power feed on to subsequent sections, converge on one point. You will find this description in the design notes to the regulators, perhaps particularly in older documentation. This of course applies to the physical layout of the board, not merely the diagram.

The ground "spill" or "fill" refers to the practice of extending the ground connections to occupy as far as possible, all areas of the board not otherwise used, with as many interconnections between these areas as possible, including multiple "vias", thus "spilling" out and filling the board. The intent is to create as low an impedance as possible between any two points and this assists in implementing the "star" topology. There are at least two objectives, to ensure stability of the regulator(s), and to reduce radio-frequency interference (that FCC compliance thing) and potential impulse coupling between sections. The placement of the bypass capacitors must also be arranged to minimise their lead and connection lengths.

As to the polarity protection diode, it does not go in the ground lead, as grounds (and notably casings, which should be grounded) of power supplies and peripheral devices are likely to (probably should) be connected, defeating a diode in such a position. Also, it should be placed before the reservoir capacitor, so that it does not introduce impedance into the regulator input.

pytel_zajicu:
I dont know, if should add diode to plus or minus pole of power supply. I added it at the minus because when reverse polarity, current will stopped immediately at beginning of circuit and will not come through any component.

It should be the first component after the positive pin on the power input. You definitely want it before your 100uF cap, since reverse polarity to an electrolytic cap can end in oozing electrolyte and/or confetti.

Technically, with proper orientation, you can place the diode on either side of a power input and it will block reverse polarity. It's a circuit, and both sides have to be connected for current to flow. But, as Paul said, grounds can and often will interface at more than one physical place, so if you impede flow just at the ground terminal, you risk allowing reverse current through some other, unintended means.

pytel_zajicu:

Put a diode in reverse across the regulators (anode on pin 2, cathode on pin 1 -- or in schematic terms, like this: 1 --|<|-- 2).

That is in fact, one reason the output capacitors should be kept small. If you can ensure the supply capacitor has sufficient reserve (and you have a series diode feeding it), it will be continuing to feed the circuit as the output voltage falls, and these diodes are unnecessary.

Paul says it is unnecessary and I belive him, so I didnt place them.

And Paul is right in this case, but.... If your circuit accepts input from any other externally-powered source, you could end up with power flowing back through your input pins. This is probably not the case in this project, so you don't need to worry about it here, but it is something you should keep in mind when designing.

FWIW, I usually don't add a diode across the regulator in my own circuits. But, I do consider the potential for power to appear from unintended sources. If the chances are high that it could happen, a diode at the regulator is cheap insurance to keep things in order. (Although, you may still fry pin protection diodes if you source too much current through an input, but that's another problem for another day.)

Another (admittedly rare, but possible) case where this diode could help -- if the input side cap is shorted, flows back to the supply (another reason for the input diode), powers other circuits (like yours does), or could otherwise conceivably drain before the inside cap does, you will end up with the regulator output higher than its input.

Again, you're probably fine here as-is. Just something to keep under your hat for later.

pytel_zajicu:

I would recommend reconsidering the 19V input entirely. That means you're dropping 14V across the 7805, which will mean lots of heat. You'll have to heatsink that IC, especially if anything draws more than a few mA of current. Is it really necessary to provide regulated 12V DC? If you're only powering fans on the 12V bus, just use a 12V power supply instead, and leave the 7812 out entirely.

19V input entirely is because of supplying led drivers and series of leds. I didnt want multiple power for LEDs and controller. Is it really bad idea 19 power suply for controller, when I add an heatsink? I should add 5V power supply, but it means one more wire.

The regulators are usually rated for something like 35V input, so you're still technically within limits, but it will get really hot dropping 14V. It's just not a great design practice. If you engineer the heat sinking effectively, it can be done though. Still, it might be easier to look into different series arrangements for the LEDs if that's a possibility. Again, it's your task as the designer to balance the many compromises and pick the method that works best for you. Know your options (and their consequences) and you'll be fine.