Bare ATMega328P schematic: Request for Comment

Hi,

You mention "shunt capacitance", I assume that's synonymous with "stray capacitance"; is that correct?

In theory, the stray capacitance is the parasitic capacitance present on the PCB plus the capacitance of the oscillator pins OSC_IN and OSC_OUT. However, almost all IC manufacturers do not specify the oscillator input and output capacitance.

On the other hand, the shunt capacitance is the capacitance of the metallic plates in the cristal, see picture below (The shunt capacitance is a parameter given by the manufacturer)

.

As you can see, they are two different parameters, however, I took the liberty of interpreting Cstray as Cshunt.

Next, you use the value of 7pF; is that a "rule-of-thumb" for stray/shunt capacitance?

In this case, manufacturers will always give you the CL (C_Load) and C0 (C_shunt) values. If you check the LFXTAL023401 datasheet for example, you will be able to see these two values

If we check another crystal, the 830108313809 for example, we can see these two values


If I were to select that crystal, the calculations would be, again, took the liberty of interpreting Cstray as Cshunt:

CL = 12pF
Cstray = 3.5 pF

C = 2(CL - Cstray) = 2(12pF - 3.5pF) = 17pF (Select the closest standard value)

Finally, as you said, a "rule of thumb" is to select a Cstray on the order of 2~5pF. Always check the data sheet of the crystal you are going to select.

Well that is totally wrong!
Maybe you and @hcb007 should spend some time reading the datasheet and app notes.

Jaja :joy:

1 Like

Why do you think be wrong is funny?

I don't think being wrong is funny. I think you're so funny.
I'm laughing at you, not with you.

1 Like

So you think trying to improve yourself is something to laugh at.
Well,that says a lot about a person.

Sorry, I've been away.

Understood on the USB to serial converter. There's a 16 pin SMD chip on the bottom of the Nano knockoff which I presume is just that.

Okay, that's reminding me of something I picked up somewhere in my reading...the same function which actually burns the bootloader also sets the fuses. I'll find out when I get there but I assume it'll be a selection: actually burn the bootloader or not and set the fuses. I don't have any bare chips yet to try it. The Nano knockoff boards use the SMD 328. I have one DIP 328 but it's on an Uno knockoff . I'll not mess with that as I intend to use that board as the programmer for ISP. Thank you for the clarification. There's a lot here to learn.

My next step is to get and try MiniCore but I have to do some final work on the first working model of my design. This "from scratch" board is a revision of that design. As soon as I model and print some mounting brackets for a linear actuator I'll be able to install the first model...so close....

Thank you.

--HC

While you were responding to Paul, I will pick up on this briefly to say: that's a good point. The ability to feed an external clock source into it, if it will work by not being subject to the failing of the limit of the internal settings would be a great work-around. I'll say something possibly stupid here but...some of the 555 chips can, reportedly, hit 2Mhz. And follow up with a dumb question: if that was fed into XTAL 1, would that be sufficient to be able to again burn/set the fuses to correct an improper clock selection?

The goal behind the topic of this thread is to take my current design using a Nano knockoff and reduce that footprint. I'm making it all fit on 50x100mm so I can get 2x on a 100x100mm because they're pretty cheap that way. I have all of it laid out and it fits but it's tight. I've looked at the SMD versions and the PB in particular. In fact, I bought a couple of "practice" SMD soldering board kits and started trying those yesterday. I did one project, 9 years ago, with SMD but the components were very spread out; I need to know if I can do this now and with closely-spaced components. This practice board is being a challenge, although I'm using the 9-year-old solder paste (stored refrigerated). Yes, it's supposed to go "bad", but I wanted to try it. I have a new tube which I'll be trying the next time I get to spend time on it. I can say, with complete confidence: 0402 components are &*#$ tiny. :wink:

Thank you.

--HC

That link to the article about using the "Standalone AVR Chip" as a programmer is a piece of the puzzle I've been looking for, I think. 15 years ago when I (foolishly) thought I was going to do some uC programming, I had a PICKit3. I liked the simplicity of how that worked (as I recall...it's been 15 years). I'll devote time to go through that whole Lady Ada writeup later, but I did read page one and that sounds like good/handy stuff. While the Arduino as ISP will be helpful, the ability to have an "image" on-board to duplicate sounds slick.

Yes, the PB is significantly cheaper: I was looking yesterday at Digikey and it's roughly $2.89 for the DIP 328P, $2.63 for the DIP 328, and $1.63 for the QFP 328PB. I believe I have those prices accurately listed. The QFP 328PB was about $1 less per unit in small quantities.

--HC

Thank you for those images. I understand. As I've only used the Uno and Nano clones, my experience is very limited. I had not seen the clock options.

MiniCore is on my to-do list.

As has been suggested along the way: the 8Mhz internal clock may do all I need for my current project and would eliminate the external crystal/caps. A little reading I did elsewhere along with what you've presented here shows that, to use the internal clock, I either need to program the chip with an ISP or use MiniCore.

Thank you again.

--HC

Correct. You can get these chips on a breakout board and put some female PCB headers on your board to plug it into when needed.

Yes, that was my post #50 you read!

It always sets the fuses. Burning a bootloader is an option you can select/deselect.

1 Like

See post #61

Then you don't need anything else.

Yes, it should be.

1 Like

That all depends on how the clock fuses are set.
Some settings will not work a 2MHz

Okay, Belmont, thank you, that was further helpful. The diagram is appreciated.

I worked through your earlier example, then one from a datasheet, and then this more-recent example. I can now not only calculate the value, but understand how I arrived.

I have a crystal in my Digikey cart. It's one I'd selected as I was just compiling a list. It's a Raltron AS-16.000-20-EXT. The datasheet lists 20pF with a shunt capacitance of 5pF max. Using symmetrical capacitances: CL = 20, Cs = 5. 20 - 5 = 15pF. 15pF = Cpereach * 1/2. 30pF = Cpereach. My subscript notation may be garbage but I was running out of ways to be sure I was clear. In order to set that crystal up correctly I would need to use 30pF for each of the capacitors in my schematic, listed as C5 and C6. If I've got that correctly then, any future schematic should leave off the value as it will likely vary from one crystal to another; specifying one part (capacitance) without specifying the other (which crystal) will be confusing.

Thank you again for your help.

--HC

Thank you, Paul. I'm not 100% sure where I'm going because I'm not there yet. But, I feel drawn to using ISP/ICSP. However, that could be used as another way to program the chips. Something about the simplicity of dedicated devices or something. I always had a mad-on in my heart when they started introducing multifunction printer/copier/scanner/fax/toasters. I want to know which device is doing what and the ability to flush one if it's not performing/working. AIGHHH...I'm a control freak.

Well, at least that shows I'm retaining knowledge...even if I'm so daft as to not retain that the person I'm communicating with is the one who gave me the knowledge in the first place. My glass is half-full. Keeps me humble. :slight_smile:

Understood on the fuses. Thank you.

--HC

It been pointed out several times that Cshunt IS NOT EQUAL to Cstray.
See post #5

Read the data sheet and app notes!

If you don't understand the datasheet and app notes just say so.

Another revision. And I found an application note I'll reference.

https://ww1.microchip.com/downloads/en/Appnotes/AN2519-AVR-Microcontroller-Hardware-Design-Considerations-00002519B.pdf

I've changed the XTAL caps values to indicate they need to be calculated based on the crystal datasheet, whichever crystal is chosen (this thread and AN2519 Section 5.2). I've changed the bulk capacitor at the PS to indicate it should be done per installation requirements. Ask me why a 10uF (shown previously in this thread as 4.7uF) isn't a "one-size" solution...don't really ask (School of Doh).

Per AN2519:

  1. Reset should have more components around it to simultaneously make it more impervious to noise and allow it to still be used with ISP/ICSP and protect the RESET pin on the uC. (AN2519 Section 3)

  2. Vcc/GND and AVcc/GND pins which are in close proximity (7 & 8, 20 & 22, respectively) should be decoupled in close proximity to the pins, not just decoupled near the PS. (AN2519 Section 2.1)

  3. Notes for the grounds have been added re decoupling the (A)Vcc inputs: namely, GND and AGND should only be tied near the PS. (AN2519 Section 2.2)

It has been suggested on this thread to perhaps use the ATMega328PB. The PB is a "newer" 328 and reading about it online has brought up concerns from the Internet Population about its use with crystals. Like AI, I'm just harvesting the garbage people spew online; maybe it's not really a concern amongst those who know what they're doing. But, some folks seem to have a question about the PB and "full-swing" crystals. I found it interesting, then, when reading this AN2519, I found explicit mention of the PB and its use with "standard high-frequency crystals". The AN thoroughly explains the capacitors used with the crystals, if not as clearly as @belmont1591 did. With the math we've been over re those capacitors, we have arrived at a capacitance of about 30pf for each in order to get a crystal with a specified 20pf load to "see" the capacitance it requires. Specifically, one crystal I mentioned has a load capacitance of 20pF with a shunt capacitance of 5pF which maths out to 30pF per each of the external capacitors for that crystal. The AN states the following:

"For the standard high-frequency crystals, the recommended
capacitor value range is in the range of 22 pF - 33 pF. For the newer AVR PB, the recommended
capacitor value range is 12 pF - 22 pF, the total capacitance (Ce + Ci + Cs) for each pin must not exceed
22 pF."

So, if there is any actual uncertainty about the PB variant working with full-swing crystals and its complementary capacitors, that would seem to address that. If I harvested incorrect junk from the internet that anyone has any concern re running the PB variant with full-swing crystals then know that I didn't cost as much as Google AI which isn't any better; I'm a bargain in wrong answers. :slight_smile:

--HC

I didn't read it all but it is like reinventing the wheel. There is UNO R3 design available so why don't you use it, just the 328P part of schematics. It is definitely well tested design.
BTW you are very close, except C8. In your case it is low-pass filter. Maybe it was mentioned above but I have to ask: Why?
Avrdude produces RESET pulse 200ms long. It is way too long (for 16MHz). UNO R3 has 100nF in high-pass configuration so behind the capacitor there are two spikes from the falling and rising edge of pulse (it is negative). Finally, with D4 it makes just one short pulse and that 's it.

I forgot the RESET button. I don't know your intention but it is good to have it. Just think about it.

1 Like