Pages: 1 [2] 3   Go Down
Author Topic: My first standalone project - chceck correctness please  (Read 2464 times)
0 Members and 1 Guest are viewing this topic.
Leeds, UK
Offline Offline
Edison Member
*
Karma: 71
Posts: 1638
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

~Tom~

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Leeds, UK
Offline Offline
Edison Member
*
Karma: 71
Posts: 1638
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Correct, although you would need the SPI pins there to be able to program the bootloader on in the first place.
Logged

~Tom~

NSW Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 2292
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Anchorage, AK
Offline Offline
Edison Member
*
Karma: 37
Posts: 1143
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 44
Posts: 2804
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.43 KB - downloaded 7 times.)
* LT1174fe.pdf (256.53 KB - downloaded 6 times.)
« Last Edit: August 15, 2013, 07:51:52 pm by Docedison » Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

NSW Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 2292
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley
As one does.
Logged

Upstate NY
Offline Offline
Full Member
***
Karma: 2
Posts: 183
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!

 
Logged

Anchorage, AK
Offline Offline
Edison Member
*
Karma: 37
Posts: 1143
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley-cool
Logged

NSW Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 2292
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Anchorage, AK
Offline Offline
Edison Member
*
Karma: 37
Posts: 1143
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 44
Posts: 2804
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Anchorage, AK
Offline Offline
Edison Member
*
Karma: 37
Posts: 1143
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, to be fair, a TTL pulse isn't exactly the same kind of impulse as a pressed switch button.   smiley-mr-green
Logged

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 44
Posts: 2804
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Pages: 1 [2] 3   Go Up
Jump to: