Author Topic: Suggestions needed for an AVR board.  (Read 6501 times)

0 Members and 1 Guest are viewing this topic.

Offline ghani256Topic starter

  • Contributor
  • Posts: 15
  • Country: pk
Suggestions needed for an AVR board.
« on: July 26, 2017, 03:31:33 pm »
I have just finished laying out a PCB for a AVR clock project that I am designing. This will be my first board built around a microcontroller and I want you guys to give your valuable suggestions so that I can learn from them.

You can see the schematic as well as the board below. In designing the board I had to choose among a number of competing design considerations.

First of all the crystal. Keeping design guidelines in mind, I placed a ground plane under the crystal. I tried to place the crystal as close to the AVR as possible, and I had to use short 90 degree traces on the loading caps and connect to the ground plane to avoid the stray inductance. I tried to route using only the top layer, but two jumpers were unavoidable. Still the ground plane is pretty much continuous.

The decoupling capacitors were placed close to the supply pins. Also there is a plated via under the TQFP package of the AVR. I hope that will not cause any problems.

Let me clear about the board a bit. JP_LCD is a jumper to which 7 wires of an 16x2 LCD connect ( as for the power pins, I will be supplying power to the LCD from another board therefore power pins are not needed here. Same goes for contrast control.) JP_SPST connects to four pushbuttons, which will also be on a seperate board. POW is for VCC and GND and BATT is for connecting a CR2032 cell to the RTC chip.

So, take a look and give me some feedback. Thank you. :)


 

Offline georges80

  • Frequent Contributor
  • **
  • Posts: 916
  • Country: us
Re: Suggestions needed for an AVR board.
« Reply #1 on: July 26, 2017, 03:53:09 pm »
Other than making things 'easier', why have an clock/calendar chip when you have a microcontroller already? i.e. why not write your own code to keep time/date (deal with leap years etc etc)??

I prefer 10k for the reset pullup.

Hope you have a decent common ground going from your uC board to your LCD board.

The internal pullup resistors (which I assume you will configure for your switch inputs) are rather weak, especially with long wires to the switches and noise input - i.e. if any are used with pin change interrupt then you can get mis-triggers. All depends on your planned use.

Via under the uC is not an issue.

I'd shorten the ground via to caps trace length (to your bottom ground plane) just for good measure.

cheers,
george.
 

Offline ghani256Topic starter

  • Contributor
  • Posts: 15
  • Country: pk
Re: Suggestions needed for an AVR board.
« Reply #2 on: July 26, 2017, 04:13:03 pm »
Hey thanks for the feedback.

Rest assured, all the wires I will use will be small, on the order of 6-7cm, because I will mount everything in a pretty small case and connect them together.

The main reason for using the RTC is in case of power loss, it will keep the current time and run off its backup battery.

Here is a little updated version. I have shortened the traces between the caps and the vias which connect to ground. I have also modified the position of the crystal a bit. Take a look.

In terms of overall design, would you say is this a good design or a bad one?


 

Offline georges80

  • Frequent Contributor
  • **
  • Posts: 916
  • Country: us
Re: Suggestions needed for an AVR board.
« Reply #3 on: July 26, 2017, 04:50:10 pm »
You can battery back the uController too.... An opportunity to write some energy efficient code to throttle the clock speed (change divider), use standby modes that wake on timer interrupt etc etc, based on detecting if the main VCC input had gone out and are operating on battery backup. You could easily get to sub mA without trying. Good enough to deal with power outages etc. The cell could recharge when power returns etc.

Layout will be fine - AVR are pretty robust/tolerant.

I'd add one bulk cap to the VCC rail for good measure (something in the 10 - 20uF range is good enough, ceramic will do fine).

cheers,
george.
 

Offline ghani256Topic starter

  • Contributor
  • Posts: 15
  • Country: pk
Re: Suggestions needed for an AVR board.
« Reply #4 on: July 26, 2017, 05:04:12 pm »
I will definitely add the capacitor you suggested.

Apart from that, will this design work well, so should I consider it as final and send it out for fabrication? ( I will be using Seeed)

It has been 3 days since I have been working on this board and I would like to get it done with  :(
 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2903
  • Country: 00
Re: Suggestions needed for an AVR board.
« Reply #5 on: July 26, 2017, 05:11:24 pm »
AVR042 recommend a pull-up resistor of at least 10 kOhm to be able to use debugWire (hardware debugging on the AVR). That entire appnote might be a good read, since it is exactly about this topic. 22 pF sounds quite low, what is the load capacitance of your crystal? See page 14 of AVR042 on how to calculate the capacitors.

C6 is far from the Vcc pin of IC2, but I am not sure if that matters for this IC. Ideally you would want it closer to the power pin. I do not love the routing of the power trace through the ISP header all the way around the board. I would connect pins 4 and 6 together with a short trace and a single decoupling cap. I would put a via near the pin 3 and 21, instead of running ground through C5.
« Last Edit: July 26, 2017, 05:58:27 pm by alm »
 

Offline georges80

  • Frequent Contributor
  • **
  • Posts: 916
  • Country: us
Re: Suggestions needed for an AVR board.
« Reply #6 on: July 26, 2017, 05:14:54 pm »
If all the pin assignments etc are correct, then should electrically function.

I'd check the clearance between your uC pin 9/10 traces, they seem a bit tight - you could open that area up a lot, no need (or desire) to run traces too close together. Your board is pretty sparse - put a bit more space between tight traces.

cheers,
george.
 

Offline ghani256Topic starter

  • Contributor
  • Posts: 15
  • Country: pk
Re: Suggestions needed for an AVR board.
« Reply #7 on: July 26, 2017, 05:42:08 pm »
Quote
AVR042 recommend a pull-up resistor of at least 10 kOhm to be able to use debugWire (hardware debugging on the AVR).

I will be using a cheap USBasp programmer to program this so I do not think I need that.

Also, I looked at the appnote an it says for standard high frequency crystals, the recommended capacitor value is 22-33pF , so I am just going with that.

@alm I will take the rest of your suggestions into account.

Quote
Your board is pretty sparse - put a bit more space between tight traces.

I will do just that. Sometimes you do not see the obvious.  ;)
 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2903
  • Country: 00
Re: Suggestions needed for an AVR board.
« Reply #8 on: July 26, 2017, 06:02:41 pm »
Also, I looked at the appnote an it says for standard high frequency crystals, the recommended capacitor value is 22-33pF , so I am just going with that.
Careful. The appnote is talking about ceramic resonators and crystals as resonators, and about external oscillators like this as oscillators. An oscillator will produce a clock signal if you just apply DC power. A crystal works together with the oscillator inside the AVR to create the clock (see Figure 5-1 (1) in the appnote). For oscillators the suggested capacitor value is 22 pF - 33 pF. For resonators, equation 2 on page 15 is the suggested way. CL is from the crystal datasheet, and CS depends on the board layout. So for a crystal with CL = 18 pF, the capacitors should be something like 30 pF. For a crystal with CL = 33 pF, the capacitors should be about 60 pF.
« Last Edit: July 26, 2017, 08:33:16 pm by alm »
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3885
  • Country: de
Re: Suggestions needed for an AVR board.
« Reply #9 on: July 26, 2017, 08:20:27 pm »
Also, I looked at the appnote an it says for standard high frequency crystals, the recommended capacitor value is 22-33pF , so I am just going with that.
Careful. The appnote is talking about ceramic resonators and crystals as resonators, and about external oscillators like this as oscillators. An oscillator will produce a clock signal if you just apply DC power. A crystal works together with the oscillator inside the AVR to create the clock (see Figure 5-1 (1) in the appnote). For oscillators the suggested capacitor value is 22 pF - 33 pF. For resonators, equation 2 on page 15 is the suggested way. CL is from the crystal datasheet, and CS depends on the board layout. So for a crystal with CL = 18 pF, the capacitors should be something like 30 pF. For a crystal with CL = 33 pF, the capacitors should be about 60 pF.

Please, do re-read the appnote. Your advice is somewhat incorrect.

From the text, second paragraph of section 5.3 (emphasis mine):

"When using the external crystal oscillator, crystals with a nominal frequency range starting from 400kHz
can be used. For the standard high frequency crystals, the recommended capacitor value range is in the
range of 22pF - 33pF"

By "external crystal oscillator" they obviously referring to the internal oscillator with an external crystal, not a can oscillator like you have linked to from Digikey - for that one discussion about load capacitors wouldn't make any sense! The app note is not written in the best way, there are several such issues just on that one page.

So the OP had it correct and 22pF is actually a very typical value used for AVRs (and not only for them) when a normal crystal is used. You have to also take into account the parasitic capacitance of the tracks/leads, so with a 22pF cap the actual capacitance seen by the circuit will be higher, probably closer to the 30pF. Fairly safe bet for most cheap crystals where there is no datasheet.

Anyhow, for a one-off hobby circuit this is really not an issue - if the oscillator doesn't start reliably (never had that situation but could happen), it is trivial to swap the capacitors for another value.

« Last Edit: July 26, 2017, 08:36:38 pm by janoc »
 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2903
  • Country: 00
Re: Suggestions needed for an AVR board.
« Reply #10 on: July 26, 2017, 08:32:37 pm »
You are right, my reading of the oscillator vs resonator was wrong. However, two (effectively) 30 pF caps in parallelseries is 15 pF. That is still low for a 8 MHz crystal, though it will likely work fine. The lowest CL for an 8 MHz crystal I found on Digikey was 18 pF, and the highest 33 pF. So I maintain that the given values are low for an 8 MHz crystal.
« Last Edit: July 26, 2017, 08:58:08 pm by alm »
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3885
  • Country: de
Re: Suggestions needed for an AVR board.
« Reply #11 on: July 26, 2017, 08:40:27 pm »
You are right, my reading of the oscillator vs resonator was wrong. However, two (effectively) 30 pF caps in parallel is 15 pF. That is still low for a 8 MHz crystal, though it will likely work fine. The lowest CL for an 8 MHz crystal I found on Digikey was 18 pF, and the highest 33 pF. So I maintain that the given values are low for an 8 MHz crystal.

Hmm, I have always thought that two caps in parallel add up, so two 30pF caps in parallel is more like 60pF total ...
« Last Edit: July 26, 2017, 08:44:10 pm by janoc »
 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2903
  • Country: 00
Re: Suggestions needed for an AVR board.
« Reply #12 on: July 26, 2017, 09:02:39 pm »
Clearly I suck at explaining app notes today. Just read the equation in AVR042, or one of the various other appnotes on parallel resonant crystals and explain me how 22 pF to 30 pF makes more sense than 30 pF to 60 pF for an 8 MHz crystal with CL between 18 pF and 33 pF.

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9935
  • Country: us
Re: Suggestions needed for an AVR board.
« Reply #13 on: July 26, 2017, 09:09:05 pm »
Looking at JP-LCD, I'm not fond of a trace hitting a pad at an angle when it isn't necessary.  Look at the 3rd pin from the right.  I can't convince myself that there is sufficient clearance between the trace and the 2d pin from the right.

 

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2507
  • Country: gb
Re: Suggestions needed for an AVR board.
« Reply #14 on: July 26, 2017, 09:25:12 pm »
You have plenty of space....

... it looks a bit like an Ardunio Uno...

.. you can bring TX, RX and GND and RESET out to a pin header (which you need not populate)... but might be useful later if you ever decided to put the Arduino bootloader on it.  (You could then reprogram via serial using an appropriate USB/TTL converter)

... also put a place for an LED and Resistor to a spare line.... you can populate and blink.  :)

(https://www.mikrocontroller.net/attachment/325540/CH340G_UNO_ArduinoBoard_3.pdf is a nice design to borrow ideas from ... you could drop all the CH340G stuff but keep the C5,R2,D2 bit which is the DTR/RESET logic and have a board you could re-purpose at a later date)

(Try to avoid using pins 19 and 22 as outputs.. I made that mistake twice!)

I like the DS3231, you could also add a 3V Battery holder on the board for backup. (but it takes an annoying amount of real estate) (I buy DS3231 modules off ebay and use the parts required, ignoring the bits I don't need)

https://edwardmallon.files.wordpress.com/2014/05/rtc-goodparts.jpg

« Last Edit: July 27, 2017, 07:12:12 am by NivagSwerdna »
 

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2507
  • Country: gb
Re: Suggestions needed for an AVR board.
« Reply #15 on: July 26, 2017, 10:10:54 pm »
Only my 2p worth...

... if you put the headers along the edges then that gives you better routing options since they cut through on both sides and can be a PITA to route around.
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3885
  • Country: de
Re: Suggestions needed for an AVR board.
« Reply #16 on: July 26, 2017, 10:50:35 pm »
Clearly I suck at explaining app notes today. Just read the equation in AVR042, or one of the various other appnotes on parallel resonant crystals and explain me how 22 pF to 30 pF makes more sense than 30 pF to 60 pF for an 8 MHz crystal with CL between 18 pF and 33 pF.

22pF-30pF is actually ok for crystals with CL around 18pF which are the most common case (totally nonscientific guesstimate from what Farnell stocks). Assuming 10pF stray capacitance (it is a through-hole board), that gives you the range of 16-20pF for the CL, covering the most crystals commonly sold.

The rule of thumb formula is C = 2*CL - Cs
The C is the value of each of the caps, not their combination.

So for an 18pF crystal and 10pF stray capacitance, you get: C = 2*18pF-10pF = 36pF-10pF = 26pF. So the common 22pF cap is a pretty good match there.

With your range of 30-60pF you would need crystals with CL from 20pF to 35pF. Those aren't really common.

Adafruit has the calculation explained (she uses 2xCs but that's a detail):
https://blog.adafruit.com/2012/01/24/choosing-the-right-crystal-and-caps-for-your-design/

In the previous reply, when you were talking about the parallel (now corrected to serial) combination, you were almost there - 15pF (from two 30pF caps) is right on the money for an 18pF crystal, because you need to add in the stray capacitance of the board/leads too (the Cs value in the formula). Which is cca 5-10pF - exactly what is missing.
« Last Edit: July 26, 2017, 11:03:17 pm by janoc »
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 12704
  • Country: ch
Re: Suggestions needed for an AVR board.
« Reply #17 on: July 27, 2017, 01:31:53 am »
If you're going to use a RTC -- which, unlike georges80, I think is a very good idea -- then use the DS3231. It's far more accurate than the DS1302/1307. The 3231 has an accurate temperature compensated internal oscillator, whereas the crystal circuit for the 1302/1307 is finicky. (I've built a number of clock kits that use the 1302, and they are all over the place. The 3231-based clocks just work right.)
 

Offline ghani256Topic starter

  • Contributor
  • Posts: 15
  • Country: pk
Re: Suggestions needed for an AVR board.
« Reply #18 on: July 27, 2017, 05:52:17 am »
It would be great if someone could clear up if I need to replace the 4.7k resistor with a 10k one. I will not be using any advanced debugger I will just be programming using a simple USBasp.

Quote
Looking at JP-LCD, I'm not fond of a trace hitting a pad at an angle when it isn't necessary.  Look at the 3rd pin from the right.  I can't convince myself that there is sufficient clearance between the trace and the 2d pin from the right.

Yes I have space and I will clear that up. Thanks for pointing it out.  :)

Quote
... also put a place for an LED and Resistor to a spare line.... you can populate and blink

Hmmm this can be useful for debugging purposes. I have some pins free on PORTC. Guess I will use one for this purpose.

@tooki: Well currently I have completely designed it to work around the DS1307, and it would not be wise to replace it right now. I will surely use the 3231 in future updates. :)
 
The following users thanked this post: NivagSwerdna

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4313
  • Country: us
Re: Suggestions needed for an AVR board.
« Reply #19 on: July 27, 2017, 07:18:46 am »
A couple of additional comments:
  • An 8MHz AVR isn't all that critical.  You don't need to be so worried about maintaining your unbroken ground plane, for instance.  Single-sided versions of Arduino (16MHz with no ground plane at all) work fine, and the standard arduino has many traces on both sides.
  • I think the 10pin programming header is losing out to the 6pin version these days.  That's up to you, and depends on what device programmer you'll be using.
  • I would make the VCC traces thicker, especially for the "long" runs not connecting directly to the chip.
  • Go ahead and put a ground plane fill on the top layer as well.  It's probably good for noise suppression, not to mention static avoidance (maybe?  The idea is that a pokey finger will discharge into the nice robust power supply instead of a sensitive IO pin.)
  • (combining 3 and 4, I tend to put a ground plane and thick VCC traces on the back for power dissipation, with the top-layer ground plane doubling as paths over the VCC traces, like the PCB here: https://farm1.staticflickr.com/685/32224166375_0ffcdf6889_z_d.jpg )
  • Um.   Power (VCC) for the LCD?
« Last Edit: July 27, 2017, 07:22:15 am by westfw »
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4313
  • Country: us
Re: Suggestions needed for an AVR board.
« Reply #20 on: July 27, 2017, 07:30:36 am »
Make sure you spend some time looking at what the silkscreen layers are going to look like.  One tends to get so involved with making the traces work that you forget that the drawing a text info is useful.   Go ahead and make copies of important names on the back side of the PCB, label signals that don't have names (on both sides), add a copyright notice and a version number...

Look at the different layers with a gerber viewer (if you have trouble finding a working gerber viewer, the preview screens at OSHPark can be used instead.  Their web interface is substantially brilliant and way beyond almost everyone else!)
 

Offline ghani256Topic starter

  • Contributor
  • Posts: 15
  • Country: pk
Re: Suggestions needed for an AVR board.
« Reply #21 on: July 27, 2017, 11:24:30 am »
Thank you everyone for your valuable suggestions and feedback.

This here is the final version of the board I will be sending to the fab house. :)

 

Offline Fungus

  • Super Contributor
  • ***
  • Posts: 17224
  • Country: 00
Re: Suggestions needed for an AVR board.
« Reply #22 on: July 27, 2017, 11:54:50 am »
If you're using a DS1307 RTC then why do you need an external crystal?

The AVR chip will be perfectly happy using its internal clock.

 

Offline ghani256Topic starter

  • Contributor
  • Posts: 15
  • Country: pk
Re: Suggestions needed for an AVR board.
« Reply #23 on: July 27, 2017, 12:34:38 pm »
Well the buttons am I using, they require debouncing. The debounce code I use requires pretty accurate timing therefore the use of the external crystal.

Besides I did some research and in most scenarios its just advised to use an external crystal instead of the internal RC Oscillator.
 

Offline Fungus

  • Super Contributor
  • ***
  • Posts: 17224
  • Country: 00
Re: Suggestions needed for an AVR board.
« Reply #24 on: July 27, 2017, 12:45:52 pm »
Well the buttons am I using, they require debouncing. The debounce code I use requires pretty accurate timing therefore the use of the external crystal.

It's an 8MHz clock (more or less).

I'd be interested to see some button debounce code needs to run at 8MHz and be accurate to 1%.


Besides I did some research and in most scenarios its just advised to use an external crystal instead of the internal RC Oscillator.

Citation?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf