My First PCB Layout

It’s been a long time since I’ve done anything with circuits but wanted to get back into it. Making a Tachometer for my lathe as a simple first project.

Fairly simple standalone atmega328 in the middle with decoupling capacitors.
Power from dc 5.5x2.1 jack to a 7805 regulator
Bottom left is the hall effect comparator
Right side for connecting a 1602A LCD

Everything is through hole for now (since I have the components for it)

Next project will be building a reflow oven so I can do smd work easier.

Any tips on the layout would be welcome!

https://drive.google.com/drive/folders/1D7rVzM_aQmo_HUP1a4U0xfK2rpPcPlCc?usp=sharing

  1. It starts with that google drive thing… It’s all separate files, downloading a single .zip file would have been a bit easier.
  2. There was no schematic on that google site. So I renamed the [project].sch-bak to [project].sch.
  3. Good of you to include the [project]-cache.lib file. This is quite important in KiCad V5.1.
  4. You have included the netlist, this is not needed, as it can easily be generated by Eeschema if it is needed. Using a netlist file is also deprecated to get your netlist into PCBnew. Use Eeschema / Tools / Update PCB from Schematic [F8] instead.
  5. Hall sensor US5881 is open drain, which needs a pull-up at it’s output.
  6. Hall sensor US5881 has a schmitt-trigger, and is thus on/off, adding a comparator is not useful (Unless the sensor is another one then the datasheet links to?)
  7. D1 & R1. I do not find “always on” leds very useful. Blinking a LED after reset is more useful, but needs an I/O pin. With an 1k resistor a modern LED also gives a quite big amount of light. Maybe use 2k2 or 3k9. You can also add a “solder jumper” in between so you can adjust later without soldering on the components themselves. KiCad has “Normally Open” and “Normally Closed” solder jumpers. Yet another option is to use the extra (now unused) opamp to switch the LED. In this way the LED does not draw current from an I/O pin.
  8. Your voltage regulator U1 is standing vertically on the PCB. A TO220 is quite high, and is vulnerable. Over time it will get bent and the pins may break. It’s better to use a horizontal version here, or add a heatsink just for stability. With a horizontal version, you can use copper on the PCB as a (small) heatsink.
  9. Same for your resistors. You have used radial resistors which are also quite high on the PCB. Consider to replace them with radial resistors which lay flat on the PCB.
  10. Usually I try to orient capacitors in such a way that I can fold them flat to the PCB. Especially when they are thin and relatively high, and then also orient them in such a way that they are a bit protected by other nearby components.
  11. U2, the LM358 has an unused opamp (Pins5, 6, 7) but these should not be left open. This can lead to oscillations. Unused opamps should be “passivized”, one way of doing this is to tie the output to the inverting input (so it is a buffer) and then tie the non-inverting input to GND or Vcc. Some opamps need a different way to be passivized, and this should be in the datasheet.
  12. You have a lot of unused pins on you uC. If you route these to a connector, then it’s easier to use this board for other projects.
  13. I have a (personal) preference of placing all THT components on a 2.54mm grid. This makes it easy to line them up (which looks neater) and also helps when wanting to make modifications such as adding a piece of matrix board.
  14. You have two tracks routed on the bottom (D7 and +5V) Move these to the top as far as possible, to keep the GND plane on the bottom continuous. It is OK to add some via’s to the board for this. They are included for free if you order the board.
  15. With KiCad’s default settings, zones do not sneak in between pads of most THT footprints. I usually reduce the clearance in the zones, so they connect in between the rows of pads, or use oval and slightly narrower pads so the GND plane sneaks through with it’s default settings.
  16. You have not connected anything to the reset pin. This is officially allowed for the ATmega328 (It has internal pullup) but I’ve had some troubles with spurious resets. After that I always add a pullup resistor on the reset pin.
  17. I always add a programming connector (either 6pin or 10 pin) to my uC boards, and a reset button. I find those handy during development.
  18. At the moment you do not even have RxD and TxD available to re program with the bootloader. Taking the uC out of a socket or messin’ with loose wires is no fun.
  19. Have you checked the connection of your potentiometers? Maybe it’s better to swap pins 1 and 3. I usually connect them in such a way that the output voltage goes up if you turn them clockwise.
  20. Now you have “daisy chained” the Vcc net. Current consumption of the LCD therefore changes the supply voltage of the Opamp. Usually very wide tracks are used for the +5V net (you did make them a bit thicker, which is good, but can be improved) A “star distribution” is better, Then use the bulk capacitor on the +5V net as “reference” and give each IC it’s own decoupling capacitors near to their supply pins.
  21. Put a “Solder Jumper (NC)” between +5V and Aref, or else you can not use the 2.5V reference.
  22. I always put an inductor or ferrite core in the raw supply voltage (Vin). I’ve had some trouble with uC’s running unreliably because of very noisy wall warts or noise picked up by long power supply cables, which work as antenna’s.
  23. Are you sure your LCD fits on a 12 pin connector? Usually D0 through D4 are also present on the LCD itself and routing them 1 to 1 to your PCB is usually easier.
  24. Another option is to make the PCB a bit narrower, so you can put it directly on the back of the LCD without cables.
1 Like

Reposition the bypass capacitors and/or reroute the traces on the bottom to minimize the current loops through them and the microcontroller. A tight loop is essential for their proper function, as the current spikes that they are supposed to smooth out are quite fast. Inductance presents a resistance to current changes and a small loop corresponds to lower inductance.
Current loops are drawn in blue:

I also a few suggestions that don’t concern layout:

  • If you really need a comparator for this sensor, there is one already in the ATmega328. Check the datasheet.
  • Tantalum capacitors are expensive and explosion prone. If you’re certain that their characteristics are essential for the functionality of the circuit, be sure to pick ones that are rated for at least double the voltage that they will be used at.
  • I prefer plated through mounting holes. You can connect them to ground or leave them floating. Even floating plated through holes have the benefit of preventing unwanted connections of the copper under the screw in case the solder mask gets scratched.
  • There is more than enough space on your board to use horizontal resistos. It’s probably a more robust way of mounting them, but this is really just nitpicking …

Clicking there would solve both problems.

I do not have the “ALLES DOWNLOADEN” link on that google thing.
I did find the schematic though, so I would not have had to rename the backup to the schematic file.

I also agree with Radix’ remarks. Quite astounding that so many remarks can be made of such a simple board :slight_smile:

So maybe you have ArduinoRPM drop down > Download on your Google thingy :wink:

1-4) Yes I should have uploaded it as a zip. I would have done it directly here but since I havent posted enough couldnt do that just yet. I’ll make some of the suggested changes to the actual schematic and hopefully I can upload it correctly

5-6) Doh! You are very correct. I started this little rmp counter two years ago and it has sat ever since. Got motivated to actually finish it and I should have looked that the datasheet again. I’ll be implementing the three wire setup found in the datasheet us5881

  1. Led resistor values updated, they are indeed too bright. I’ll take a look into the solder jumper

  2. I have little project boxes that it will go in that will fit a board and components 75x60x30. I was going to originally have the TO220 stand up and put a heatsink on it. There is plenty of space on the board though so I could put it horizontal and not worry about the heatsink.

  3. I was originally worried about space so didnt lay the resistors flat. No need for that though.

  4. Good idea!

  5. I remember learning that in college now. Removed the op-amp so per previous points

  6. I have enough machining tools that this will be going on that I really was just going to have this be a dedicated build for the hall sensor

  7. I’m going to be redoing the layout and I’ll stick to a 2.45 grid for sure

  8. Sounds good

  9. I’ll play around with the ground plane some more and get it worked out better

  10. Definitely needs the resistor, its even on my bread board :grimacing:

17-18) I was planning on just programming all five atmega328’s on my breadboard then placing them in the pcb. Maybe I should rethink that plan, seemed like it would be easy and quick to swap through them all on the breadboard before placing them on the pcb.

  1. You are correct. Changed the pot pins

  2. Star distribution makes sense

  3. I dont understand why a solder jumper is needed. Whats the jumper used for vs just connecting the 5V trace to Aref. What does it have to do with 2.5V? (I’m sure theys are stupid questions, I’m reading thought the Aref in the datasheet in the meantime)

  4. Will do!

  5. I wasnt using D0-D4 on the1602A so thought a 12 pin header would be fine :man_shrugging:.

  6. Not a bad idea, I would change the 12 pin header to 16 for sure then… hmmm

Dang current loops. I’ll keep it in mind when I redraw it. Good tip on the atmega having an internal comparator.

The capacitors are actually electrolytic and ceramic, I’ll update that on the new drawing.

It’s a plastic box that it’s mounted in so didnt think the plated mounting hole was needed. still not bad to change to if I use a different box in the future.

Yes I will move the resistors horizontally

Aref is not always an input. It can be configured as an “output” for the internal reference (which is apparently 1V1 instead of the 2V5 I wrote earlier).

This is what the datasheet has to say about it:

24.5.2 ADC Voltage Reference
The reference voltage for the ADC (VREF) indicates the conversion range for the ADC. Single ended channels that exceed VREF will result in codes close to 0x3FF. VREF can be selected as either AVCC, internal 1.1V reference, or external AREF pin. AVCC is connected to the ADC through a passive switch. The internal 1.1V reference is generated from the internal bandgap reference (VBG) through an internal amplifier. In either case, the external AREF pin is directly connected to the ADC, and the reference voltage can be made more immune to noise by connecting a capacitor between the AREF pin and ground. VREF can also be measured at the AREF pin with a high impedance voltmeter.
Note that VREF is a high impedance source, and only a capacitive load should be connected in a system.If the user has a fixed voltage source connected to the AREF pin, the user may not use the other reference voltage options in the application, as they will be shorted to the external voltage. If no external voltage is applied to the AREF pin, the user may switch between AVCC and 1.1V as reference selection. The first ADC conversion result after switching reference voltage source may be inaccurate, and the user is advised to discard this result.

About the plated holes…
Plating of THT holes is standard, and some manufacturers charge extra for NPTH holes, as these are made in a separate step in the production process. NPTH is usually done at the end of the process, often combined with routing of the outline of the PCB. Routing of outlines is very common though these day’s. I’m not even sure if manufacturers still charge extra for it.

I didnt think it would be much to discuss lol

I’m really happy you all were willing to spend the time and give me some pointers.

Most of the electronics I deal with are with machine tools so VFDs, relays, contractors, and fuses. It’s been almost 15yrs since I’ve really had do my own pcb

The board as it is in the gdrive ATM can be totally rerouted in 5 or 10 minutes using only the top layer without a single extra via. I didn’t think about the quality otherwise, though.

Circuit:

Its normal practice to have rails pointing up and GND/reference pointing down. This is only a cosmetic thing

Q1 (US5881LUA-AAA-000-BU) is an open-DRAIN output and thus it needs a pullup resistor
This is more of an IC than a transistor and it requires a 100nF local decoupling

U1 what is this connected to ? a battery? you might want to include a reverse protection diode to protect the linear reg from latching and burning up when the input < output

U2 is a dual opamp but the other symbol isn’t placed and not terminated. You need to ensure you terminate unused OPAMPS correctly. This enables you to gain access to the unused easily but also if you do not terminate it correctly the unused can either oscillate like crazy (due to uV of error between the floating pins) or sit at a rail and heat itself to destruction.
Decoupling required

Layout
Consider moving R1: D1 (LED network) to the top-left hand corner. This free’s up some tracking area for what can just hang off the north side of U1

U3.7 this is a power-in pin but it has a convoluted path to get to the 5V. It would make sense to track between U3.21 -> U3.7 to provide a shorter run as possible.

5V power. Mak these traces as wide as you can. Lowers their impedance.

You have already committed to a 2layer card so why not flood the front with 5V

Something like this (including the missing decoupling and pullup)

Now this could be done single layer … maybe

@positrontime, do you mind if I take and share your board file in the issue database? I find some problems with the assisted router with it. (They would probably be found with another design but it would be easier to use this now when I know how to repeat the problem.)

I was looking at using JLCPCB so 2 layer is the same cost as single so might as well use 2 layer.

Yeah I should use a 5V pour/zone. I’ll rework it and post up Rev B :slight_smile:

U1 is connected to a wall wart.

For sure! Hope my silly board can help.

Check your board size and make sure it’s under 50x50mm as that’s commonly the smallest and cheapest size with many board makers. If they have a 50x50mm smallest size and your board outline is 51x49 you will be quoted for the next size up, 100x100. Still not expensive, but why pay more than you have to. Smaller boards are also easier to fit on a panel full of random designs, so might get done quicker, although that’s more just an argument not to waste board space - a mm here or there won’t matter. Just eyeballing it, it looks like your board outline is very close to or exactly 50x50 so worth double checking the dimensions.

Changed the board layout so that I can plug the 1602A into a 16 pin socket onto the board directly. This does have a couple design limits. The 16 pin connector vertical position is fixed so the LCD will be as close to center as possible in the enclosure.

I can remove the mounting holes which would allow me to make the board smaller.

I still need to add a mounting pins for a toggle switch at VIN so I can turn the board on and off, and decide on the inductor and diode protection at VIN.

How do you get the reference text to be on top of the F.cu Zone?

Attached is Rev B

ArduinoRPM.zip (52.9 KB)

You still need to fix those little things in the cct

  1. pull-up
  2. de-coupling
  3. un-used opamp

From a layout. U1 regulator, the tab is GND so you might as well flood all that with GND to provide heat-sinking.
Why not combine the hole of the reg with the mounting - assuming you can, mechanically and electrically since the screw will now be “GND” of the reg

I am not familiar with the ATmega but could you change your IO bank from the PD to say the PC? this could produce a better layout since the crystal would be on one side of the physical chip and your user-IO on the other edge. This should assist in routing around the crystal

I changed the layout to mount the LCD from the back so that all the components can be accessed and not covered by the LCD when mounted. The mounting holes match the 1602A mounting. This gives plenty of room so I didnt flood the top layer but ran traces.

The DRC gives is the overlap on the outlines of the 7805 and the mounting hole. Will this be a problem?

@Naib
Mounted the U1 Regulator to the mounting hole and flooded the back with some vias (why not).
The 5881 sensor I kept looking at the SE pin outs on the datasheet which was messing me up. Fixed to the correct UA pins. No longer have the op-amp.

@paulvdh
What choke/inductor do you use on your arduino projects? I added .33uF and .1uF ceramics to the 7805 per its spec sheet along with the 10uF electrolitics. Also have a 1N4004 across Vin/Vout

ArduinoRPM.zip (47.3 KB)

First, I do not do “arduino” I have a strong dislike for the whole platform for various reasons.

A bit of my history:
Some 20+ years ago I started programming with the Microchip PIC16F84, which was one of the first uC’s with flash, but I did not like it much. Just did a few small assembly projects. A bunch of years later Atmel started with the AT90S1200 (A bit too small, no RAM) and the AT90S2313, and somebody ported GCC to it. That was my first real taste of Open Source software and I liked it a lot. There were some other C compilers, but those were completely out of reach for hobbyists. This was all years before “arduino” even existed.

In those days my projects were just one-off hobby level projects, and soldering one prototype on matrix board is about the same effort as designing a PCB. I have not maintained m website for the last 10+ years or so, but you can get an idea of my old project when looking at: https://www.hoevendesign.com/

In those days I had some halogen lights and a FL lamp with an old fashioned inductor as ballast, and both of these generated nasty spikes on the mains power lines when switching them on or off. And these spikes went right through small (low frequency) transformers in wall warts and linear voltage regulator chips. I also started with some home automation, build around small uC boards which use both power and data through a CAT5 cable. and in that time I started experimenting with chokes and inductors to make my uC circuits run reliably even on breadboards and matrix board, which do not have any decent GND plane.

In my experience, every sort of choke or inductor in the power supply lines help with improving reliability, and bigger chokes work better then smaller chokes. Feeding your circuit from (small) SMPS modules also help with making uC circuits more reliable. The power supply cables that go to my breadboards have a split core ferrite around them, and I also had to use these on the long CAT5 cables. These were scavenged from old equipment, so I have no real data for them, but I have learned they do work, and if you can fit 2 or three windings through the core they work better.

If you want to get some hands-on experience with this, then first get some equipment that generates nasty stuff on mains power lines. I had a halogen light (with an old fashioned block transformer) and a halogen light. Any sort of equipment may work for this, especially if it has those block transformers, or ballast inductors such as for FL lighting. Also get a uC with a simple program that for example flashes a LED a few times after reset, so It gives feedback when it gets glitched, and then start experimenting with both generating stronger EMI and making your breadboard circuit more immune.

If you want to add some real inductors (that are not part of an SMPS) as filter components then make sure they can not start to oscillate, as this may very well make the problem worse. Putting a resistor of a few Ohms in series may be enough to lower the Q of the circuit.

I’ve also been curious for some time about treading the cable through a stack of steel washers instead of ferrite cores. Such washers both amplify the “inductance” and should also generate strong eddy currents on EMI events. I’ve been wondering for some time why this is not used instead of those ferrite chokes. It may be that they start “choking” at too low a frequency for data cables.

In times of deep communism in Poland (it could be around 1974 I think) there were really nothing you could buy. As we couldn’t get any bulb up to 100W we tried to use 200W, but they were too light for our eyes. I used diode in serie but then you see blinking (even it is 50Hz you see it). So I have done my first thyristor circuit switching on for second half of each half of sine wave. As a teenage designer, I knew nothing about the interference so I have used there no filters at all. The guy living two floors down came to ask if it is me who generates so high RF noise that he can’t listen to radio (he knew that I am the electronic fan).
About the same time I have designed my power supply having 100W trafo at the input (and of course no filter). Some time later (about 1990) we noticed that even uC was powered from 12V accu (we were designing taximeter) when 1m from it you switched off that supply, uC liked to hung-up (those time uC didn’t had watch-dog and brown-out circuits integrated) so we used that supply as our version of EMC resistance testing.

My first attempt was to use one C-L-C filtering stage. And I was surprised why the inductor manufacturers don’t offer 100uH with very low capacitance. So I ordered one according to my design. At the dimension they had 100uH/1A I had 100uH/150mA (different core) but according to my measurements with about 0.3pF. Now I just always use two stage filtering one with 100uH range choke and second with ferryte bead.