Arduino Forum

Using Arduino => Microcontrollers => Topic started by: pytel_zajicu on Aug 12, 2013, 12:28 am

Title: My first standalone project - chceck correctness please
Post by: pytel_zajicu on Aug 12, 2013, 12:28 am
Hi,
I am projecting my first standalone arduino project. I making LED lighting for my aquarium, there will be 7 branches of serial LEDs. Each branch can be controlled one of 3 pwm signals (signal is choosed by jumper). There will be an i2c display and DS1306 clocks, maybe some sensors in future. 4 buttons for control and one reset button.
Can you tell me, if it is correct? It is my first standalone arduino project, so I want to make me sure that PCB will be ok at first time.

I am glad for any comment.

sorry for my bad english

(https://dl.dropboxusercontent.com/u/17296312/led-controller.png)

EDIT:
(https://dl.dropboxusercontent.com/u/17296312/led-controller2.jpg)
Title: Re: My first standalone project - chceck correctness please
Post by: johnwasser on Aug 12, 2013, 02:16 am
Both ends of LED2 seem to be connected to Ground.  It will never light.

If you press the Reset button you will be shorting +5V to Ground.  That will fry something.
Title: Re: My first standalone project - chceck correctness please
Post by: larryd on Aug 12, 2013, 02:17 am
Place a 100nF capacitor right next to the 7805 pin 1 to 3.
Your reset switch is wrong! You are shorting out the +5 to GND.
Title: Re: My first standalone project - chceck correctness please
Post by: Paul__B on Aug 12, 2013, 05:27 am

If you press the Reset button you will be shorting +5V to Ground.  That will fry something.


Not necessarily fry - the 7805 will current limit and thermal shut down if it persists.  Not a good idea however, and shorting the capacitor will reduce the working lifetime of the pushbutton.

Hopefully innocent draughting blunder as with the LED - the button should have been connected to the reset pin and resistor further right.

Seems to have the "raw" supply connected to the I2C spills - should of course be the regulated 5V line.


Title: Re: My first standalone project - chceck correctness please
Post by: dc42 on Aug 12, 2013, 08:52 am
As well as fixing the problems already mentioned, I suggest you add a standard 6-pin ICSP header so that you can reprogram the microcontroller in-situ.
Title: Re: My first standalone project - chceck correctness please
Post by: pytel_zajicu on Aug 12, 2013, 12:24 pm
Thank you guys.

Lary, there is 10uF capacitor, should I replace it?

I edited my sketch, so I hope, everything is OK... Added ISP pins and add power suppply for fans for cooling leds, but I dont know if it is connected right...
New sketch is in first post
Title: Re: My first standalone project - chceck correctness please
Post by: dc42 on Aug 12, 2013, 12:43 pm
You now have C3, C4 and pin 22 of the mcu connected to +5V instead of to ground. The reset pins of the MCU and ICSP header should go to the junction of the 10K resistor and the reset switch, not to +5V.

You don't need to connect Aref to +5V, you can do that inside the chip - and it's better to do it that way, in case you accidentally connect Aref to the 1.1V internal reference in the code.
Title: Re: My first standalone project - chceck correctness please
Post by: xl97 on Aug 12, 2013, 05:34 pm

As well as fixing the problems already mentioned, I suggest you add a standard 6-pin ICSP header so that you can reprogram the microcontroller in-situ.


this!  ^^

recently had to deal with pre-existing pcb's that didnt have any ICSP headers/breakouts..

(FYI.. I used this cable from HobbyKing.com since my chips were Atmega328P-AU/SMD versions of the chip)
http://www.hobbyking.com/hobbyking/store/__27195__Atmel_Atmega_Socket_Firmware_Flashing_Tool.html

(worked a treat too!)

Title: Re: My first standalone project - chceck correctness please
Post by: pytel_zajicu on Aug 12, 2013, 05:48 pm
OK, 3rd version, I hope now it is without errors :0... Can you explain me please, what to do capacitors around 7805 regulator? Should I place it by the 7812 too?

(https://dl.dropboxusercontent.com/u/17296312/led-controller3.png)
Title: Re: My first standalone project - chceck correctness please
Post by: dc42 on Aug 12, 2013, 06:10 pm
1. You should add a 0.1uF ceramic capacitor between the atmega Vcc and Gnd pins, and another between Avcc and Agnd. Place these capacitors as close to the atmega as reasonably possible.

2. Regarding capacitors at the input and output of the regulator, check the regulator datasheet for the recommendations for the particular regulators you will be using. Generally, you always need an input capacitor (which must be placed close to the regulator), but the output capacitor is optional for many regulators. So you do need to add an input capacitor on the 7812. The input capacitor of the 7805 can double up as the output capacitor of the 7812.
Title: Re: My first standalone project - chceck correctness please
Post by: Tom Carpenter on Aug 12, 2013, 06:26 pm

Can you explain me please, what to do capacitors around 7805 regulator? Should I place it by the 7812 too?

The capacitors have two roles.

The first is to filter noise from the supply lines which could interfere with circuitry (especially microcontrollers). Simply put, capacitors act like a short circuit to AC signals, effectively removing them from the power rails.

The second in respect to regulators is to prevent them oscillating. These regulators rely on a closed loop feedback control, whereby it aims to make the output voltage constant even if output current or input voltage changes. In some cases this feedback loop can overcompensate and go out of control resulting in high frequency waveforms being added to the supply line. The capacitors help slow any change in output/input voltages to help reduce the chance of oscillation, and remove the noise.
Title: Re: My first standalone project - chceck correctness please
Post by: pytel_zajicu on Aug 12, 2013, 11:54 pm
Thank you Tom, thank you dc42 :)...
Is it correct now?

(https://dl.dropboxusercontent.com/u/17296312/led-controller4.png)
Title: Re: My first standalone project - chceck correctness please
Post by: dc42 on Aug 13, 2013, 02:31 pm
I can't see any obvious errors now. I presume the input at J1 will be more than 12V?

I suggest you make provision for an output capacitor on the 12V regulator, just in case you find you need one - even if you don't plan to fit one initially. My previous comment "The input capacitor of the 7805 can double up as the output capacitor of the 7812." was wrong; I thought the 7812 was powering the 7805, but I see now that they are both powered from J1. C1 can serve as the input capacitor for both regulators, as long as they are fairly close together.
Title: Re: My first standalone project - chceck correctness please
Post by: Samba on Aug 13, 2013, 07:26 pm
This was enlightening! I know nothing about electronics but now it doesn't seem totally impossibly to design your own board!
Just a thought, why not have the ADC and other pins on the top next to 5V and GND like
5V-A0-GND-A1-5V-A1-GND-A2-5V, or
GND-A0-5V GND-A1-5V GND-A2-5V

Have them on a 2.54mm pitch and maybe add some Screw Terminal Block later...

Don't you use TX and RX to program a Atmel382?
Title: Re: My first standalone project - chceck correctness please
Post by: pytel_zajicu on Aug 13, 2013, 10:40 pm
Thanks again dc42 for your patience with me, I am glad about people like you. Here is modified sketch.
(https://dl.dropboxusercontent.com/u/17296312/led-controller5.png)

I placed own capacitor on 12V regulator (in and also out), add RXD, TXD pinout and add some gnd holes. Hope, it is finish version :))...

Samba: this is only sketch, when Ill design board, probably it will be placed together (GND-IO-VCC).

I have question about ICSP uploading sketches. I never used RX/TX pins or SPI pins to communication. I only use i2c, but if I understand well, SPI and RX-TX is using for communication with other devices too. But I cant find how works ICSP uploading sketches explained for dummies. Is it uploads via SPI or RX/TX or both?
Title: Re: My first standalone project - chceck correctness please
Post by: Tom Carpenter on Aug 13, 2013, 11:01 pm
You have your ISP connections so you can use an AVR programmer to download programs. This is the primary method they were designed to be programmed with.

An alternative method involves having a portion of the flash devoted to a small piece of software (bootloader) which allows you to program via a serial port (RX TX).

As you would need the ISP pins to download the bootloader in the first place, you might as well just stick to using ISP to download your program and skip the bootloader.
Title: Re: My first standalone project - chceck correctness please
Post by: pytel_zajicu on Aug 13, 2013, 11:21 pm
Thank you Tom. Just for my assurance - standard way to upload program is via SPI (MISO/MOSI pins), that can be also used to serial communication with another devices.  I can use RX/TX pins too, but there must be bootloader in AVR. So, If I have AVR with bootloader, I dont need SPI pins anymore, because I can upload sketches via rx/tx. Am I right?
Title: Re: My first standalone project - chceck correctness please
Post by: Tom Carpenter on Aug 13, 2013, 11:28 pm
Correct, although you would need the SPI pins there to be able to program the bootloader on in the first place.
Title: The purpose of a schematic diagram
Post by: Paul__B on Aug 14, 2013, 10:59 am
is not only to indicate which wire connects to which, this is a necessary but not sufficient condition.  If you are using a system which directly translates the schematic to a routing pattern, it may work, though even then there are certain "rules" that need to be followed.

A schematic diagram should also serve to explain the function of the circuit.  In order to do this, it is necessary to follow certain general conventions.  I believe you need to re-draft at least the left-hand side of your schematic in order not only for us to understand it and check for errors, but so that you can do so effectively as well, because this has obviously been the source of design problems.

A first convention is that the vertical axis suggests voltage.  Wherever possible, all the grounds should be at the bottom of the diagram, preferably entering components from below.  Similarly, supply feeds should be toward the top and enter from above (with the exception of the regulators where a feed from left to right makes sense).  You have initially observed the convention of the power feed from the left-hand side, but things have become confused after then.

Power feeds - regulators and such - should run in sequence (from left to right) indicating flow.  If as here, you have two alternate feeds (and you have correctly sourced both from the primary voltage rather than in cascade, to best utilise drop-out voltages), then make two parallel sections one above the other with the split to these on the left-hand side.  Avoid round-about loops.

Wherever possible, buttons and their associated pull-ups should appear in the same vertical line from one power rail to the other, and similarly for (power) indicators.

The crystal loading capacitors (as with all bypass capacitors) should preferably be shown vertically, down to the ground.  You need to organise the confusion of ground joins - almost all should go down to one rail along the bottom.

If you note the Arduino schematics, they frequently split parts of the I/O busses into completely separate sections of the overall diagram, simply to manage so many connections.
Title: Re: My first standalone project - chceck correctness please
Post by: pytel_zajicu on Aug 15, 2013, 06:55 pm
Ok, Paul, thanks for remarks. Its right my schematic was quite messy, so Ill takes your advices and tried modify schematic... Hope, it is more clear now... Please check it, and if there is no more errors, Ill start project PCB design...

(https://dl.dropboxusercontent.com/u/17296312/led-controller-final.png)
Title: Re: My first standalone project - chceck correctness please
Post by: SirNickity on Aug 15, 2013, 09:04 pm
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.  :)
Title: Re: My first standalone project - chceck correctness please
Post by: Docedison on Aug 16, 2013, 02:43 am
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
Title: Maybe not!
Post by: Paul__B on Aug 16, 2013, 01:27 pm

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

Absolutely!


- 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.


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.


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.


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

Ditto my comment above.


- 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.


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.


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).


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.  :)

As one does.
Title: Re: My first standalone project - chceck correctness please
Post by: JoeO on Aug 16, 2013, 07:07 pm
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!

 
Title: Re: My first standalone project - chceck correctness please
Post by: SirNickity on Aug 16, 2013, 09:39 pm
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)
Title: Re: My first standalone project - chceck correctness please
Post by: Paul__B on Aug 17, 2013, 12:15 am
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.
Title: Re: My first standalone project - chceck correctness please
Post by: SirNickity on Aug 17, 2013, 03:35 am
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?
Title: Re: My first standalone project - chceck correctness please
Post by: Docedison on Aug 17, 2013, 04:44 am
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 (http://www.gammon.com.au/forum/?id=11637).

Doc
Title: Re: My first standalone project - chceck correctness please
Post by: SirNickity on Aug 17, 2013, 04:54 am
Well, to be fair, a TTL pulse isn't exactly the same kind of impulse as a pressed switch button.   :smiley-mr-green:
Title: Re: My first standalone project - chceck correctness please
Post by: Docedison on Aug 17, 2013, 04:57 am
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
Title: Re: My first standalone project - chceck correctness please
Post by: Paul__B on Aug 17, 2013, 03:55 pm


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.


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.


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.)


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.
Title: Re: My first standalone project - chceck correctness please
Post by: pytel_zajicu on Aug 18, 2013, 11:09 pm
At first thanks for the critique. I read all comments and something is still not clear for me.

Quote
- 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.
Quote
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

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

Quote
Quote
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"

Quote
Quote
- 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?

Quote
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...

Quote
Quote
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.

Quote
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.

Quote
- 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.

Quote
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:

(https://dl.dropboxusercontent.com/u/17296312/led-controller-final2.png)









Title: Re: My first standalone project - chceck correctness please
Post by: Paul__B on Aug 19, 2013, 04:57 pm
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.
Title: Re: My first standalone project - chceck correctness please
Post by: SirNickity on Aug 20, 2013, 12:42 am
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.

Quote
Quote
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.

Quote
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.