7
\$\begingroup\$

PCB image

Hi all,

I designed a PCB for a lock control. You can see the PCB on the image. Some explanation on the abbreviations:

  • Ext: exterior 12V power source
  • Batt: 12V battery
  • 1702: 12V to 5V power converter
  • Keypad: here comes a classic 4 by 3 keypad
  • MCU: Atmel Atmega 328P
  • IRL520N: transistor to drive the solenoid of the lock

Other components are not relevant for the discussion I think.

The program is as follows: you enter a code. When the code is correct, the transistor is activated, thus the lock opens. This for two seconds. Then locks turns off.

Everything works fine, except for... When the locks turns off again, circuit is starting to act strangely. Sometimes it blocks, sometimes the chip reboots.

I post the drawing of the PCB and not of the circuit, because I think the problem lies in the way the PCB is laid out.

Thank you very much for your help!


So, given all your answers, I redrew the circuit a bit (a lot):

  • Use of SMD components
  • Crystal is a lot closer to the MCU
  • Use of decoupling capacitor (C5)
  • Use of ground fill (pink area on bottom of PCB)

New PCB

Could you please tell me if this PCB would have the good performance wone would require? Or am I still getting it wrong?

Thanks a lot

\$\endgroup\$
  • 4
    \$\begingroup\$ Please add the schematics \$\endgroup\$ – PlasmaHH Sep 23 '15 at 15:00
  • 4
    \$\begingroup\$ Welcome to the world of electrical interference. \$\endgroup\$ – Eugene Sh. Sep 23 '15 at 15:01
  • 3
    \$\begingroup\$ Start out with decoupling capacitors at the MCU power pins. \$\endgroup\$ – Tut Sep 23 '15 at 15:08
  • 2
    \$\begingroup\$ @bunny - Whenever you're making any sort of digital system with a clock, and particularly if you're also driving any sort of load (like your solenoid), a ground plane should be on the top of your list. Well, right along with proper decoupling (which the ground plane helps enormously). It greatly reduces noise problems, and cuts down on weird interactions - like, for instance, what you're seeing. It's not a panacea, but you'd be amazed how much easier it makes your life. Any current spike in your ground will produce voltage spikes on your dinky little ground traces. \$\endgroup\$ – WhatRoughBeast Sep 23 '15 at 15:25
  • 2
    \$\begingroup\$ Minor comment about the PCB design: Don't draw straight point-to-point lines, it looks awfully unproffesional. go for rotations whose degrees are divisible by 45 and don't make sharp 90 degree turns, instead, turn them into a 45+45 bend. It looks a lot more orderly that way. (In some extremely rare cases, the point-to-point routing is best, however not in 99% of beginner boards) \$\endgroup\$ – Linards Sep 24 '15 at 7:15
7
\$\begingroup\$

Various folk, including me, have pointed out the need for a better ground and decoupling. But here's how I'd try to fix your board.

1) Get a couple of 0.1 uF 50V ceramic caps. Don't go for high voltage. On the bottom of the board, solder one from pin 7 to pin 8, and the other from pin 20 to pin 22.

2) Cut the ground trace between R3 and R4. Cut the trace between the source of Q1 and C2.

3) Using smallish wire (like #26 hookup wire) connect the ground pin of C1 to pin 22 of the MCU, using as short a wire as you can. No big loops - run it straight.

4) Using much larger wire, like #20, connect the R3/Q1 connection to the battery - pin. Again, make this as direct as you can while avoiding placing the wire on other soldered connections, and maybe use a dab of 5-minute epoxy or hot glue to keep it in place. Basically, I'd parallel your ground trace which runs under the MCU.

I make no guarantees, but I think this might give you a chance.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ What is the reason I can not use the same larger wire everywhere, exactly? \$\endgroup\$ – bunny Sep 23 '15 at 21:08
  • \$\begingroup\$ @bunny - Oh, you can, but you don't need to and the smaller wire is easier to work with. \$\endgroup\$ – WhatRoughBeast Sep 23 '15 at 21:16
  • \$\begingroup\$ @bunny - And one more thing. Add at least a 100 uF cap across the left-hand 10 uF cap. If possible, use tantalum rather than electrolytic. \$\endgroup\$ – WhatRoughBeast Sep 24 '15 at 0:35
  • \$\begingroup\$ @bunny - Does this mean it worked? \$\endgroup\$ – WhatRoughBeast Sep 26 '15 at 18:08
  • \$\begingroup\$ on a short term (with the first PCB I posted) I was able to correct the weird behavior by doing step 2, 3 and 4 of your answer. In the long term, I will redesign the PCB with the different comments people made. But at least everything is working fine now. Thanks a lot! \$\endgroup\$ – bunny Sep 26 '15 at 19:25
14
\$\begingroup\$

One major problem is that the solenoid current passes through the same conductor that is ground for the chip. You should run it back separately- that can be even better than just blindly throwing a lot of copper at it.

You may be able to salvage this layout by cutting the trace to the MOSFET source and bypassing it with a flying lead, and/or by adding series resistor to the gate of the MOSFET- that will slow the switching of the transistor and reduce that transient on the ground trace, at the expense of a bit of heating during the switching operation. Try something like several K and increase the shunt resistor if required to maintain most of the gate drive.

| improve this answer | |
\$\endgroup\$
13
\$\begingroup\$

PCB design good practise. Take a look at this first: -

enter image description here

There are 6 examples of how you can connect decoupling capacitors to the supply pins on a micro and note that all of them use a PCB with a power plane and a ground plane.

OK you've only got a double layer board and THE most important is the groundplane and you have tons of space on your PCB to make a really quite effective one. Don't skimp on it. Routing the power tracks on top doesn't have to be a problem but do what you can to make the GP as full as possible and make sure that different parts of the circuit that share a common supply do not pass heavy duty currents down shared power tracks - star pointing back to the battery is a good thing to consider.

In fact many designs need split ground planes just to avoid heavy-duty current (from say a motor) passing thru sensitive amplifier input components. Common practise these days.

Not having a ground plane is like having lots of individual loop antennas all over the PCB; some capable of transmitting energy and all capable of receiving energy.

If you use a ground plane the "effective" area of the loop antenna formed is defined by the thickness of your circuit board.

I have taken the liberty of copying your PCB picture and colouring in ground tracks blue and other tracks on the underside red: -

enter image description here

All the red tracks could be routed on the topside with just small use of the bottom layer to a much greater extent than what you have. This frees up the bottom layer for 95%+ coverage of blue.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ "Routing the power tracks on top doesn't have to be a problem". Why is that? Why a power plane isn't as important as a ground plane? (Should I post a separate question for this? :)) \$\endgroup\$ – Rafael Sep 25 '15 at 17:55
  • 1
    \$\begingroup\$ @Rafael it probably is a good question and too long to answer as a short comment. Simply put, you need one very good 0V reference mostly because this is also a signal reference whereas the power track can waggle up and down a bit without upsetting the signal forward and return currents from point A to point B. \$\endgroup\$ – Andy aka Sep 25 '15 at 17:58
10
\$\begingroup\$

No ground plane, no bypass cap, looks like you're getting expected results.

Given the bad design that is clearly evident, I'm guessing you also didn't put a flyback catch diode across the solenoid either.

Elaborating on all these things is pointless since they are really basic and already well covered here and other places. Add the flyback catch diode and a bypass cap for each power pin of the micro. That's the bare minimum necessary to fix this mess.

If you can use one layer mostly for ground with "jumpers" in it only to make routing work on the other layer, that would be good. I don't know why you're using all ancient thru hole parts, but since you are, I'd use the top layer for ground and put as much of the interconnects on the bottom layer as possible.

Added:

Others have pointed out that D1 is the flyback catch diode (as I said earlier, I hadn't looked and was guessing). That's one problem down, but still leaves the two major problems of missing bypass cap (or caps, you need one for each power pin), and bad grounding.

This also points out why you need to show the schematic. You can't expect the volunteers you are seeking a favor of to try to follow the layout to infer the circuit. A schematic would also have made the lack of decoupling capacitor obvious, and should show what type of diode D1 is.

On the flip side, grounding is a layout issue. I see you have meanwhile redone the layout using a mix of surface mount and thru hole parts. In this case I would use the bottom layer as a ground plane to the extent you can. Put the interrconnects on the top layer, going only to the bottom layer to make short "jumpers" for when things can't be routed in a single plane. Try to keep those jumpers as short as possible and away from each other. The metric to strive for is to minimize the maximum dimension of any island in the ground plane. That not only tells you to keep the jumpers short, but to not clump them together.

I see you got some bad advice in the comments to your question, which was unfortunately upvoted. Electrically, direct connections without any bends is best. What you had originally between the microcontroller and the keypad connector was perfectly fine, in fact even optimal. Don't let people tell you it should be different due to misguided and silly asthetic reasons. The electrons don't care how pretty you or anyone else thinks it looks. When you do need to make bends, the comment is correct in that you should try to avoid anything more than 45°. To make a 90° bend, use two 45° bends with a short straight segment between them. You actually did this just fine in your original layout.

Again though, you need to show the schematic to get more meaninful feedback.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ The flyback diode is there (D1). \$\endgroup\$ – Tut Sep 23 '15 at 15:12
  • 1
    \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$ – Nick Alexeev Sep 24 '15 at 18:55
7
\$\begingroup\$

The stored energy in the activated solenoid is creating voltage spikes on your supply line once turned off. Your microcontroller does not even has a decoupling capacitor on it's supply pins to buffer transients. You may want to add 1 or 2 100nF ceramic caps close to Vcc as an immediate improvement.

Please supply schematic for further analysis.

| improve this answer | |
\$\endgroup\$
4
\$\begingroup\$

All application notes I've come across so far stated that placing the oscillator as close as possible to the pins is basically a must.

Yours is basically miles away. If possible I'd place them between the MCU and the keypad connector.

The current return path should also be kept as short and direct as possible. Which could be routed that way when the crystal is placed between MCU and keypad.

I don't know the frequency the crystal runs at, if it is a 32kHz one, it might be okay, but still highly discouraged.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ @bunny then you really should try to get it as close as possible to the MCU, of course it's not a quick fix, it still might work (in fact it does until the solenoid switches off). A quick fix which might help is to use the internal RC oscillator instead (if you don't need a very precise timing). \$\endgroup\$ – Arsenal Sep 23 '15 at 20:02
1
\$\begingroup\$

Perhaps XTAL and C2 connected on the ground shared with transitor isn't good idea.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ In fact, the location of the XTAL, C1 and C2 are poorly located. They should be located (relative to the MCU) where the silkscreen reads "Keypad". \$\endgroup\$ – Tut Sep 23 '15 at 15:47
  • \$\begingroup\$ @Marko This is a bit thin for an answer on EE.SE. Please substantiate. [Fortunately, we have a fair bit of material on EE.SE about PCB layout of XTAL.] \$\endgroup\$ – Nick Alexeev Sep 23 '15 at 20:19
0
\$\begingroup\$

I don't see a kickback diode in the circuit to deal with the kickback from tuning off the solenoid. A solenoid is basically a large inductor and the current flowing through it will continue to flow until that energy is dissipated when the circuit tries to turn it off. To keep the current flowing the inductor will create large voltages. Think spark plugs in older model cars. This energy being kicked back into your circuit will create havoc and can eventually release the smoke. Put a large current diode and a small capacitor in parallel with your solenoid energizing circuit (diode, capacitor and solenoid in parallel) The capacitor will absorb some of the energy till the diode starts conducting and extend the life of the diode. Don't make it too big either.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ D1 appears to be a "kickback" diode. \$\endgroup\$ – Sam Sep 24 '15 at 15:26
  • 3
    \$\begingroup\$ ... and it might have been noticable in a real schematic. \$\endgroup\$ – Scott Seidman Sep 24 '15 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.