SparkFun Forums 

Where electronics enthusiasts find answers.

Questions relating to designing PCBs
By russosv
Hi Everyone,

I breadboarded a USB design using a Microchip 18F4550. It worked perfectly well on the breadboard, then I created a prototype with BatchPCB. The design uses a 20MHz crystal with 15pF load capacitors.

My PCB is almost completely SMT, as opposed to the breadboard. However, I think I flubbed the layout, because the board works with the internal oscillator, but won't operate at 20MHz. I suspect that my traces should have been equal length instead of completely asymmetrical as they are, but I don't know enough about PCB layouts to confirm this.

I don't have the Eagle files with me right now, but at the risk of total public humiliation and the hope of getting some help, I'm posting the layout pic from BatchPCB.

(image link)

2 questions:

1. Can anyone confirm how I flubbed this design?

2. Is there a good source with tips like the below for beginners on routing SMT boards? I just found the below in the forum, which was very helpful.
inventore123 wrote:Eagle's autorouter does not suck, it must be used properly. For example, you route manually all critical parts of the design, like traces from a crystal to a micro, and temporarily fill the manually routed pieces with some t_restrict, b_restrict to avoid the autorouter placing high speed digital lines close to the crystal. Or things like the ground lines of a DC-DC converter to avoid poor gnd design and high ripple, all things that an autorouter cannot know. Then you start the autorouter, that is enough intelligent not to ripup the manually routed traces. To avoid long lines with many vias you can reduce grid size, increase ripup level, and add more optimizations. My projects are extremely simple compared with what you want to do, but I think that eagle autorouter will be a better choice than manually routing everything.
link to original post here
By SpinDrah
i don't like the way you went around with the one trace, I usualy try and keep the two traces together in a line from the pins right to the crystal and as close to 1/2 inch or less i can keep it, and i am trying to run ground around all of it
By russosv
Thanks SpinDrah... do you think would that have caused the 20 MHz oscillator not to work?
User avatar
By Gsm Man
The traces between you processor and the crystal should be as short as possible - your's are way to long. Microchip has several application notes that address the selction of the crystal, the loading caps and PCB layout; AN588, AN949 & AN1288. I'm sure there are others. You can download these from Microchip's web site.

Here's a section from one of the App notes regarding layout:
The oscillator circuit connections should be as short as
reasonably possible. This suggests that the oscillator
circuit should be placed next to the controller and on
the same surface. This also suggests that the loading
capacitor grounds should be connected directly back to
the controller. If possible, there should be no other
connections or vias between the loading capacitors
and the controller ground, except at the controller itself.
The exception would be if a ground plane is present
and the loading capacitors are connected to it.
By russosv
Thanks GSM Man... I did some searching of the Microchip web site looking for advice, but didnt find those exact App Notes that you referenced. The quote and the ANs you provided are very helpful, thank you.

From AN1288- again, very helpful... thanks!
If the traces to the oscillator are kept short, under 10
mm-long each, their capacitance will be very low and
almost negligible.
I think I'm going to try moving the 0.1uF cap a bit, bringing the crystal closer to the MCU, and then hand-routing the crystal traces so that they are both the same length and much shorter.
By MichaelN
The main problem I see is not the length of the tracks from the crystal to the CPU (although they are too long as discussed). It is the ground connection on the load capacitors. Each of these capacitors should have its own via nearby directly to the ground plane. They should not be connected together like this. I also wouldn't route other connections through the crystal like that.

This is a good grounding rule generally - don't be afraid to use LOTS of vias to the groundplane, and put them as close as practical to the component pins. Are you using the bottom layer as a groundplane? You should be! Single sided PCBs should almost never be used, especially with high-speed circuits.

I would never bother with an autorouter for such a simple layout - much better just to route everything by hand IMO.
By russosv
Thanks MichaelN... I did not know that about the capacitors or routing under the crystal... that's exactly what I was talking about-- how does a beginner hobbyist like myself learn these little layout tips when transitioning from breadboard to PCB?
Are you using the bottom layer as a groundplane?
Yes, the bottom layer is a copper pour used as a ground plane... sorry I did not show it here; there's not much on it except for 1 trace and the ICSP header.
By Philba
I'd just move the crystal closer (like right next) to the pic and make sure the caps have a good ground in common. Route all the other traces away from the crystal and make sure there is a ground "guard ring" around it.

It looks like your copper plane isn't connected to anything. Try naming the rectangle GND (or what every you are using for ground). I wonder if those orphan copper pours are causing a problem.

By the way, you should check for solder bridges, shorts, opens and so on. It could be as simple as a bad solder joint.
By zarcondeegrissom
Philba; sounds good.

there are pours between caps/resistors that need to go (C9 & C5).

unfortunately if them orphan ground pours have Via's to the other side of the PCB. the DRC thingy doesn't show them. Good thought.

"O" O, there is a trace in the center of the crystal, that over oblique angle T should be touched up a bit. That angle is to sharp, Instant acid trap.
same on the trace going to the top pad on the USB connector on the left hand side.
By MichaelN
Russ, I wish I could offer a good book or reference, but I've picked up these types of things from lots of sources over the years, as well as by making lots of mistakes. I'm sure there are good books on the topic though.

A few points I keep in mind when designing (2-layer) PCBs:

- Carefully place components to minimise overall track lengths. If 2 components have a lot of connections between each other, try to put them close togehter.
- Try to separate high-speed digital and sensitive analog parts of the circuit to different parts of the PCB.
- Try to dedicate the bottom layer to a ground plane, and minimise any breaks in this plane. Where it is unavoidable to have tracks on the bottom layer, minimise their length.
- Avoid having tracks carrying high-speed signals cross over any breaks in the ground plane. This is because the "ground return current" won't be able to travel directly under the signal track, creating a loop which can cause EMI issues as well as injecting noise into other parts of the circuit.
- For all pins connectoed to ground, have a via to the ground plane located as close a practical to the pin.
- Locate decoupling capacitors as close as practical to the pins they are decoupling.
- Don't use split groundplanes unless it is really necessary for very sensitive analog circuitry, and then be VERY careful how you implement them (eg no tracks can crosss the split).
By MichaelN
One other thing with designing circuits, try to make sure any pins connecting to the "outside world" are well protected against ESD, voltage surges, incorrect polarity etc.

For example, I never directly expose microcontroller pins to a connector without protection. Sometimes this is as simple as adding a resistor (allowing the internal protection diodes in the micro to do their job without being damaged), and sometimes you'll need to add TVS diodes etc or add additional interface components.
By russosv
Philba, zarcondeegrissom, MichaelN (and again, everyone else who has responded so far)-- I can't say thanks enough. You are all so helpful; it's greatly appreciated. It's obvious that you all have plenty of experience with this and I'm thankful you are willing to share it.

I ripped up all the signals and re-routed the board by hand. Would you guys mind taking a quick look and seeing if you have any additional comments?

By the way -- I wanted to mention that the top copper pour isn't connected to anything, but the bottom pour is a ground plane. I wasn't sure whether it was correct or not to (a) make both planes GND, and (b) have a ground plane so close to all my components. I thought it might increase the risk of a short. The top pour is simply a 'reflex' from when I was home-etching boards, to make the etch process faster. Please let me know what you think is the best methodology.

Also, is it OK to have the ground pour running underneath the crystal? I hadn't really thought of this before, but what would happen if I inadvertently shorted one of the crystal's leads to ground? Couldn't that mess up the signal too?

I'm planning on putting this design-- and the software that will go with it-- on my web site and releasing it as open source.

Edit: By the way, I tried green-wiring the crystal directly to the OSC1 and OSC2 pins of the MCU, and the MCU ran at 20 MHz consistently each time I've started up the board. So I suspect that the 2 uneven, long traces were causing the problem I initially mentioned. I'm having problems now communicating with the FT232RL, but I think that's probably another issue. I think i have pretty much destroyed my current prototype from over-soldering the components so I may have to rebuild it on the 2nd board I got.

Michael-- your point is well taken with the protection. I think that the only "outside world" connection in this circuit is the ICSP header. I intend to remove this connection once I've finished developing the software/firmware as updates will probably be done via a USB bootloader.


Edit 2: Removed the ground layer from under the crystal... do you think this is better? Also moved the via near the crystal a little, and took Michael's advice re: a separate via for each ground on load caps.

By MichaelN
That looks MUCH better. A few points:

- I woud definately connect the top copper pour to ground. Are you worried about shorts because you aren't getting a soldermask? I always like a soldermask, but if you're not getting one you could always increase the separation in the design rules.

- Bond the top and bottom groundplane together using a bunch of vias, particularly in the area where you have tracks on the bottom layer (to minimise the distance the ground-return currents from those signal lines will have to travel).

- It is normally recommended to pour the groundplane underneath the crystal. If you have a soldermask, there shouldn't be any worries about shorts. The additional capacitance on the crystal pins shouldn't be an issue.

- I don't normally consider the ICSP / JTAG connectors the "outside world", since this is not something that is normally accessed by the end-user. Thus, I don't include additional protection on these lines. I would re-consider this if the ICSP / JTAG lines were actually accessible from the outside of the box during normal operation.

Static electricity can be a big danger for un-packaged electronics, but if you are sensible you should be OK. Once the PCB is packaged in a box, it is normally only susceptible to the lines that are actually presented to the outside of the box. In a production unit, depending on the end application, you might want to include additional protection on the USB data lines. You can't use normal TVS devices for this (as the capacitance would be too high). Something like the SP0502BAJTG is designed to work on high speed data lines.

- Re the 2 separate vias for the crystal load caps, this isn't really needed in this case (they are touching each other), but it isn't a problem either. The main thing is that all ground lines have a short connection to the groundplane, and you have acheived that.
By russosv
Thanks Michael... I revised it according to your comments. I added back the ground plane underneath the crystal, made the top layer VSS, and also added a bunch of vias between the top and bottom layer (did I go overboard?)

There wasn't a ton of room near the bottom layer tracks to add vias because of the top components, and there is isolation between them which prevents me from adding vias in between. Bottom isolation is 12 mil, and top is 16 mil. Is it better to rearrange the bottom tracks so I can add vias in between them?

I am getting a soldermask... I think that's included in the BatchPCB process. I'm worried about shorts because I just don't know any better! :)

Thanks again, also thanks for the tip on the USB lines, def will add SP0502BAJTGs for ESD protection in the next revision.


Latest: Added a couple more vias and fixed some artwork


In case anyone is interested, I'm starting to post project details here:

Serial to USB Keyboard/Mouse System
By Philba
I think that looks ok but if it was my design, I'd move the crystal even closer. Since this is only a 20 mhz design, the way you have it should be fine.

Out of curiosity, why did you position the pic and a lot of the passives at a 45 degree angle? I think it would fit fine without the rotation.

Thinking about your first design, I still think the problem is some sort of short or open. Even though it's suboptimal, it should at least run.
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]