[HARD] Atmega328 Hardware Design - The Right Way

Go To Last Post
27 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


 

 

For 99% of all cases this design is the right way to start with a '328 design...

 

 

 

 

And, if using a breadboard, please start neat and tidy and keep your wires short. This is the above circuit, without the reset switch and IO connections to the ISP pins...

 

 

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

Last Edited: Thu. Jul 16, 2020 - 04:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And as a PDF.

Attachment(s): 

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


The ISP connectors viewed from the top of the connector looking down towards the PCB...

 

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

Last Edited: Mon. Feb 24, 2020 - 01:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would add pins and pinout to ISP.

 

David

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DAFlippers wrote:

I would add pins and pinout to ISP.

 

Good idea. Done.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian, Your ISP connector (first schematic) looks a bit odd, it seems to imply all the pins are shorted together.

Other than that, a very nice posting!

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also, show an optional Xtal for Uart operation

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

Brian, Your ISP connector (first schematic) looks a bit odd, it seems to imply all the pins are shorted together.

 

It's just a style thing, all my schematics, even the CAD ones, have that style of connector.

 

 

avrcandies wrote:

Also, show an optional Xtal for Uart operation

Done.

 

Thanks for the suggestions. I'm probably going to stop there as any further tweaks will take it away from my 99% goal.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

(optional) filter inductor for AVCC ?

 

The reset circuitry looks more complex than I've seen in real life.  "Decrease life of switch"?  Because of those harsh 0.25uJ discharges?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Brian,

 

Why do you have 4.7k ohm resistors in series with the SPI signals?  For impedance matching to to typical PCB traces, it is more common to use values around 33-39 ohms (allowing some 10-15 ohms for the on-chip driver impedance).  At 4.7k ohms, parasitic capacitances may severely limit the speed of the SPI bus.

 

Also, I'm not sure about this device - I exclusively have used XMEGAs - but the RESET# signal is used by the PDI, and putting capacitance on RESET# will strangle PDI operation.  Does the ATmega328 do something different?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes - impedance matching! Not for transmission line effects but so that the ISP signals can override other devices connected to SPI when programming the flash.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
Yes - impedance matching! Not for transmission line effects but so that the ISP signals can override other devices connected to SPI when programming the flash.

 

Ugh.  It appears that my decision to stick with the XMEGAs was a good one.  I can get maximum speed out of the SPIs.  Thanks for the explanation.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
Yes - impedance matching! Not for transmission line effects but so that the ISP signals can override other devices connected to SPI when programming the flash.

Altazi wrote:
Why do you have 4.7k ohm resistors in series with the SPI signals? 

 

I myself use 220 ohm resistors in series, but Hey Ho, whatever works.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Greater than 220 ohms is recommended though if the attached SPI device is de-selected and not in tri-state then 4K7 may work for an Atmel-ICE.

Shared Use of SPI Programming Lines | AVR® Microcontroller Hardware Design Considerations (AVR042)

...

Typically, the resistor value R can be of 330Ω.

...

These typical values are used to limit the input current to 10 mA for a supply voltage (VCC) of 3.3V. It may vary depending on the programmer/debugger used and the requirements of specific hardware design.

...

Pull-up Resistors | AVRISP mkII

... i.e. the resistor should have a value of 820Ω or more.

...

 edit : typo

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was not saying my 220 ohms were used for pullup. But for isolation of downstream devices from the ISP when used.

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a (stupid I'm sure( question on this ISP connector pinout.

 

I have the Atmel ICE package, the ATMega328 Explained board (and a couple others).

Looking at the schematic and the pinouts, I traced everything out and it seems to match.  The problem is the connector itself that comes with the ICE.

(we called them "Berg" connectors back in the day).

The connector block itself has a small, hard to see, arrow denoting pin on.  This doesn't match anything.

The connectors pin on would (looking down on to the connector from the top) connect to pin 5, or 2, depending on which way you plugged it in.

 

Plus, I notice that the Number One wire, the red stripe, actually connects to "3" (again, looking down), which is next to the pin one (would be on the left).

 

I'd like to get this clarified before I plug this thing in.  Without a key to ensure you plug this in only one way, it's a might confusing.

 

The PCB's, all match up, pin one being in the lower left, or upper right corner, depending on board orientation.  (which matches the drawing here)

 

I can post photo's if that would help clarify things, but that little arrow on the connector may not show up as it's very hard to see.

 

 

 

 

EDIT.....  never mind, I just looked at the ICD documentation, (don't ask me why I didn't think of this before....) and Atmel ignores the pin one marker on the connector.  That pin that is marked as number one, is indeed number 5 by Atmel configuration.

 

Sorry.

Just gettin' started, again....

Last Edited: Sat. Apr 25, 2020 - 12:17 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nice.

 

You might consider adding an LED WITH a series resistor, so the user can see the results of their work.

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Can I add another photo, from a 2015 Thread:

 

The microcontroller has its own Internal clock.

If this is used then no external clock crystal is required.

The internal (RC Oscillator) isn't very accurate, but can be calibrated.

 

Shown below are other options for providing the clock for the microcontroller.

#1 Ceramic Resonator  Usually 3 leads, the center being ground.

It usually has capacitors built into it.

It is inexpensive, and more accurate than the uC's internal clock.

The one shown is 20 MHz.

 

#2 SMD "Crystal"  Also called an Xtal for short.

This is a two lead device. The one shown is 14 MHz.

External capacitors are required.

Crystals use active circuitry inside the chip to make an oscillator, (clock).

 

#3  "Clock Crystal"  These are, by definition, 32.768 kHz.

They are often used in watches, Real Time Clocks, and as a reference clock source.

They, like the other devices shown here, come in different shapes and sizes.

 

#4 & #5 Are both "Crystals"  These are two different packages for 14 MHz crystals.

They are very accurate compare to the other ceramic resonator and the uC's internal RC Oscillator.

They both require external capacitors.

 

#6 External Oscillator   This is a chip which has its own V+ and Ground pins, and outputs a square wave.

This one puts out a 25 MHz clock (square wave) at 3 V.

It uses a By-Pass, (decoupling), cap, 0.1uF, on its V+.

It doesn't otherwise use any capacitors.

 

The Wiki Page below has info on other clock sources, including those with their own temperature and voltage controller built in.

 

Wiki has a page on Crystals, seen here, with lots more info.

 

Note that on AVR Mega and Tiny microcontrollers one has to use the "Fuses" to tell the micro what is being used for the clock source to make the uC run.

On the Xmegas one can set the clock source via software.

 

Some uC's also have a Fuse to divide the clock, (whatever the source), by 8.

This slows the clock down a lot.

 

Some uC's have an internal 32 kHz clock as well as the internal clock that runs at several MHz.

 

 

Last Edited: Fri. Nov 27, 2020 - 02:13 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Great summary, Doc. 

 

See also Tip #4 in my signature, below.

 

DocJC wrote:
The internal (RC Oscillator) isn't very accurate

Indeed.

The main upshot of this is that it really isn't a good choice of you want to use the UART - because UART comms does rely upon an accurate & stable clock

 

 

Crystals use active circuitry inside the chip to make an oscillator

Might be worth clarifying that the "chip" in question here is the microcontroller itself.

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Fri. Nov 27, 2020 - 08:34 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Indeed, an excellent clock summary. Worth its weight in nooby questions! 

 

In terms of performance, ceramic resonators range in accuracy from twice (or so) the limit for UART communication (which is around 2%) to half, or so, of the required UART accuracy. So, you CAN use a resonator for UART clocking if you watch out for the accuracy spec. To accurately clock a UART, a frequency source that is 2% or better is really needed.

 

All of the others tend to be good enough for UART clocking, over a wide range of temperatures. Clock (e.g. 32.768KHz) crystals are rarely used for direct UART clocking but, in most AVRs, can be used to calibrate a higher frequency but lower accuracy internal clock.

 

All rely on the active half of the oscillator (which is inside the MCU) to oscillate EXCEPT for the external oscillator (#6). External oscillators tend to use a lot of power, although there must be low power or micro-power devices out there. They also tend to be relatively expensive compared to a bare crystal. They keep generating a clock signal even if the micro is unpowered. 

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
the limit for UART communication (which is around 2%) 

note that this is the final, overall error on the UART baud rate; the clock source contributes to this, but other things (like not-quite-exact division ratios) also contribute.

 

So you don't want to be starting out with a clock source having 2% error!

 

External oscillators tend to use a lot of power, although there must be low power or micro-power devices out there

Indeed there are; eg,

 

https://www.sitime.com/

 

They also tend to be relatively expensive compared to a bare crystal

but they are also available in temperature-controlled versions (TCXO) - to give even higher accuracy.

 

 

EDIT

 

Perhaps from #20 on should be split out to a separate tutorial ... ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Fri. Nov 27, 2020 - 06:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


I use a standard Arduino Nano module board with an 8-pin wide header pin strip soldered across the tops of the VIA holes for A2 to GND.

Then this module plugs into an Arduino-style 8-pin socket on the protoboard. 

This gives Vcc,Gnd, Reset, I2C, two digital and two analog I/O in a plug-in space-saving module.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The list of "clocks devices" in Doc's #20 post is wonderful.  However, it should be stated in term of Atmel's strange and EXTREMELY confusing naming of clocks devices in the fuse selections.  They keep mixing in the word  "oscillator" all over the place.Whoever came up with the names should be required to eat a bowl of burned chips for breakfast. 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Indeed - that's noted in the post linked from my Tip #4

 

https://www.avrfreaks.net/commen...

 

frown

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried to flesh out the distinction between  crystal and oscillator in #22, so that it would be all together, in one place, with Doc's excellent photo.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!