Tet_hardware_PCB_developent_TutorialFull
Tet_hardware_PCB_developent_TutorialFull
Tools to be used
There’s a ton of design tools out there, most of them for hobbyists.
At Tet la’ngech we focus on mainly two most Industrial standard advanced PCB
tools; Altium and Cadence orCAD
However, we shall be using Altium for our sessions.
Block Diagram
Below is the block diagram that we’ll be working on.
A block diagram should include a block for each core function, the
interconnections between the various blocks, specified communication protocols,
and any known voltage levels (input supply voltage, battery voltage, etc.).
Later, once all of the components have been selected and the required supply
voltages are known, we can add the supply voltages to the block diagram.
Including the supply voltage for each functional block it allows you to easily
identify all of the supply voltages you’ll need as well as any level shifters.
In most cases when two electronic components communicate they need to use
the same supply voltage. If they are supplied from different voltages then you’ll
usually need to add in a level shifter.
**We shall focus on blocks in yellow for our basic development and design
Now that we have a block diagram we can better understand the necessary
requirements for the microcontroller.
NOTE: Until you’ve mapped out everything that will connect to the
microcontroller it’s impossible to select the appropriate microcontroller.
Select Microcontroller
When selecting a microcontroller (or just about any electronic component), you
can use an electronics distributor’s website like mouser.com, digikey.com and
Newark.com. Doing so allows you to easily compare various options based on a
variety of specifications, pricing, and availability. It’s also an easy way to quickly
access the components’ datasheets.
Tet la’ngech focuses on ARM Cortex-M microcontrollers.
Arm Cortex-M microcontrollers are easily the most popular line of
microcontrollers used in commercial electronic products.
They have been used in tens of billions of devices.
Microcontrollers from Microchip (including Atmel) may dominate the maker
market but Arm dominates the commercial product market.
Arm doesn’t actually manufacture the chips directly themselves. They instead
design processor architectures that are then licensed and manufactured by other
chip makers including STMicroelectronics, NXP, Microchip, Texas Instruments,
Silicon Labs, Cypress, and Nordic.
The ARM Cortex-M is a 32-bit architecture that is fantastic choice for more
computationally intensive tasks compared to what is available from older 8-bit
microcontrollers such as the 8051, PIC, and AVR cores.
One of the biggest advantages of Arm Cortex-M processors is their low price for
the level of performance you get.
In fact, even if an 8-bit microcontroller is sufficient for your application you
should still consider a 32-bit Cortex-M microcontroller.
The STM32 line can be broken down into several subseries as shown in Table 1
below.
Whereas with a leadless package, like a QFN, the pins are hidden away
underneath the package making access impossible without test points.
A leaded package also allows you to more easily swap out the microcontroller if it
were to become damaged. Finally, leadless packages cost more to solder on to
the PCB so they increase both the prototyping and manufacturing costs.
This is a fairly entry-level STM32 microcontroller with only 32 pins, but with a
wide variety of features. More advanced versions come with as many as 216 pins
which would be quite overwhelming for an introductory tutorial.
Schematic Circuit Design
Now that we have selected the microcontroller it’s time to design the schematic
circuit diagram.
We shall practically design this schematic using Altium.
Figure 3: Schematic circuit diagram for the STM32 microcontroller, linear regulator, USB
connector, and programming connector.
Capacitors
Next, we’ll place all of the various capacitors. For the most part you can think of
capacitors as tiny little rechargeable batteries that hold electrical charge and help
to stabilize the voltage on a supply line.
We’ll start by placing a 4.7uF capacitor on the input pin of the linear regulator.
This is the 5VDC input voltage supplied by an external USB charger. This voltage is
fed into a TLV70233 linear regulator which steps the voltage down to 3.3V since
the microcontroller can only be supplied by a maximum of 3.6V.
Another 4.7uF capacitor is placed on the output of the regulator as close to the
pin as possible. This capacitor serves to store charge to supply transient loads and
it acts to stabilize the internal feedback loop of the regulator. Without an output
capacitor most regulators will begin to oscillate.
Decoupling capacitors must be placed as close as possible to the microcontroller
supply pins (VDD). It’s always best to refer to the microcontroller datasheet in
regards to their recommendations for decoupling capacitors.
The datasheet for the STM32F042 recommends a 4.7uF and a 100nF capacitor be
placed next to each of the two VDD pins (input supply pins). It also recommends
1uF and 10nF decoupling capacitors be placed near the VDDA pin.
The VDDA pin is the supply for the internal analog-to-digital (ADC) converter and
must be especially clean and stable. We’re not using the ADC in this first tutorial
but we will in a future one.
Note: that you’ll commonly see two capacitor sizes specified together for
decoupling purposes. For example, 4.7uF and 100nF capacitors.
The larger 4.7uF can store more charge which helps stabilize the voltage when
large spikes in load current are required. The smaller capacitor serves mainly to
filter out any high-frequency noise.
Microcontroller pinout
Although the STM32F042 offers a wide variety of functions such as UART, I2C, SPI,
and USB communication interfaces, you won’t find any of these functions labeled
on the microcontroller pinout. This is because most microcontrollers assign a
variety of functions to each pin so as to reduce the number of pins required.
Figure 4: Pinout for the STM32F042 microcontroller in a 32-pin LQFP leaded package.
For example, on the STM32F042 pin 9 is labeled as PA3 which means it is a GPIO
pin. Upon startup this function is automatically assigned to this pin. But it also
has alternative functions that can be specified in the firmware program.
Pin 9 can be programmed to serve the following functions: receive input pin for
UART serial communication, an input to the Analog-to-Digital Converter (ADC), a
timer output, or an I/O pin for the capacitive touch sensor controller.
Refer to the pin definition table in the microcontroller datasheet (page 33 for the
STM32F042) which shows all of the various functions available for each pin.
Always be sure to confirm that two functions required for your product don’t
overlap on the same pins.
Clock
All microcontrollers require a clock for timing purposes. This clock is just an
accurate oscillator. Microcontrollers execute programmed commands
sequentially with each tick of the clock.
The simplest option, if available on the selected microcontroller, is to use the
internal clock. This internal clock is known as an RC oscillator clock because it
uses the timing characteristics of a resistor and capacitor.
The major downside to an RC oscillator is accuracy. Resistors and capacitors
(especially those embedded inside a microchip) vary significantly from unit to unit
causing the oscillator frequency to vary. Temperature also significantly impacts
the accuracy.
An RC oscillator is fine for simple applications, but if your application requires
accurate timing then it won’t be sufficient. For more accurate timing and
complex application, we do use external crystal-based oscillator.
Programming Connector
Programming an STM32 is done via one of two protocols:
JTAG or Serial Wire Debug (SWD). More advanced versions of the STM32
(STM32F1 and higher) offer both JTAG and SWD programming interfaces. The
STM32F0 subseries offers only the simpler SWD programming interface so that is
what we will focus on for this tutorial.
The SWD interface requires only 5 pins. They are SWDIO (data input/output),
SWCLK (clock signal), NRST (reset signal), VDD (supply voltage) and ground.
We shall be using an ST-Link programmer to upload code onto our custom board.
Power
The last part of the schematic we’ll cover is the power section. The STM32
microcontroller can be powered with a supply voltage from 2.0 to 3.6V. Unless
you have a variable power supply, you’ll need an on-board regulator to provide
the appropriate supply voltage.
For this design we’ll power the board using an external USB charger which
outputs 5 VDC. This voltage will then feed into a linear voltage regulator
(TLV70233 from Texas Instruments) which steps it down to a stable 3.3V.
The STM32 requires a maximum of only 24mA assuming none of the GPIO pins
are sourcing any current (each GPIO pin can source up to 25mA). The absolute
maximum current the STM32 will ever require is 120mA assuming various GPIO
pins are sourcing current.
The TLV70233 is rated for up to 300mA which should be more than sufficient for
this this particular design.
You can as well improve the power circuit design by adding in a rechargeable
lithium battery that can be recharged via the USB port.
Component Placement
Although all of the components have been inserted, it’s your job to determine
exactly where each component is placed on the PCB.
For this sample project, component placement is pretty simple. Place the
microUSB connector next to the linear regulator with its output as close as
possible to the input supply pins (VDD) on the microcontroller. Finally, place the
programming connector anywhere that is convenient.
Figure 1 - Placement of the critical components in this initial design: the microcontroller (U1),
the regulator (U2), the micro USB connector (J1), and the programming connector (JTAG-1).
Once all of the core components are properly placed, your next step is placing all
of the passive components (resistors, capacitors, and inductors).
One key aspect of designing electronics that you need to learn is the concept of
Parasitics.
Parasitics are passive components (resistors, capacitors, and inductors) that you
don’t intentionally design into your circuit. But, nonetheless, they are there and
impact performance.
For example, although a signal trace is intended to be a perfect short, it in fact has
some finite resistance, capacitance, and inductance all of which become more
significant as the trace length increases, and as the number of bends and vias
increase.
Figure 2 - Placement of all critical components (U1, U2, J1, and JTAG-1) and passive
components (capacitors).
So this means that if a voltage source is located far away from the load, which is
the STM32 microcontroller in this case, there is essentially a resistor between the
load and the source (neglecting any capacitance and inductance).
If the microcontroller all of a sudden requires a fast spike of current then it will
cause a voltage drop across this trace resistor.
So even though the voltage regulator’s output may be a perfect 3.30V, the voltage
at the microcontroller pin will be lower during this current surge.
Decoupling capacitors are used to solve this problem.
Remember, capacitors are like little batteries that store electrical charge. Placing
them right at the microcontroller’s supply pins allows them to supply any fast,
transient current needs of the microcontroller.
Once the transient load disappears the capacitors are recharged by the power
supply so they are ready for the next transient increase in load current.
We’ll start with a 2-layer board to keep things simple. But as the circuit complexity
increases you’ll find it necessary to add additional layers.
The number of conducting layers is always an even number, so you can have a
board with 2,4,6,8,10,12 conducting layers. Most designs will require 4-6 layers,
and more advanced designs may require 8 or more layers.
Routing
Once all of the components have been properly placed it’s now time to perform
the necessary routing. There are two options for routing: manual and automatic.
DON’T!! Another hobbyist feature is the Auto-routing feature, NEVER use this
feature at Industrial level not even during your practice.
Figure 3 – Routing the PCB (black traces on the top layer, gray traces on the bottom layer)
When routing on a PCB you want to minimize the length of each trace as much as
possible. You also want to minimize the number of vias and avoid any 90 degree
bends in the traces. These recommendations are especially critical for high power
traces and high speed signals.
A via is a hole between layers with conducting material that allows you to connect
together two traces on different layers. Most vias are what are known as through
vias which means the via tunnels through all layers of the board.
Through vias are the simplest type to manufacture because they can be drilled
after the entire PCB layer stack-up is assembled.
Figure 4 - Via #1 is a classic through via, via #2 is a blind via, and via #3 is a buried via.
Vias that only tunnel through a subset of layers are known as buried and blind
vias. Blind vias connect an external layer to an internal layer (so one end is
hidden inside the PCB stack-up). Buried vias connect two internal layers and are
completely hidden on the assembled PCB.
Blind and buried vias allow you to pack a design more tightly. This is because they
don’t take up space on the layers not using them. Through vias on the other hand
consume space on all layers.
However, be aware that blind and buried vias drastically increase the prototype
cost for your board. In most situations you should restrict yourself to only using
through vias. Only exceptionally complex designs, that must fit in an
exceptionally small space, should likely ever require these more advanced via
types.
When routing any high current power lines you need to ensure the trace width is
capable of carrying the necessary current. If you run too much current through a
PCB trace it will overheat and melt causing the board to become defective.
To determine the necessary trace width, we can use a PCB trace width calculator.
To determine the required trace width you need to first know the trace thickness
for your specific PCB process.
For example, to handle 120mA we only need a trace width of 0.635 mils!
The minimum trace width allowed by most processes is 4-6 mils. The minimum
width traces can be easily used for the supply lines in this design. That being said,
the wider the trace the less the resistance and the more stable the supply voltage
at each component.
Unless space is extremely tight you should always over design the power supply
traces. In fact, in many cases you’ll want the power supply routing on its own
layer so you can maximize the routing width.
Finally, in the calculator you’ll notice the requirements are different for internal
layers versus external layers. For this simple, 2-layer design both layers are
external so the “Results for External Layers in Air” is what we need to use.
Internal layers can carry much less current because they don’t get the cooling
effect of being exposed to air so the traces will overheat with much less current.
Figure 5 - The completed Printed Circuit Board (PCB) layout.
Verification
Once all of the routing is done it’s time to perform verifications to ensure
everything is correct. This is where automation really works. Perform an
Automatic Verification.
The DRC verifies that all PCB process design rules have been followed. This
includes rules such as the minimum allowed trace width, the minimum spacing
allowed between traces, the minimum spacing between a trace and the board
edge, and so on.
In order to run a DRC verification its necessary that you first obtain all of the
design rules for the specific PCB process you will be using.
Each PCB prototyping process has slightly different rules so you must have the
correct rules before proceeding.
After you have verified that your PCB layout adheres to all of the process design
rules, it’s now time to verify that your PCB design matches your schematic
diagram.
In order to do this you’ll need to convert your PCB layout design (which is
currently stored in a proprietary file format) into the industry standard file format
known as Gerber.
The Gerber format outputs each layer of your PCB design as a separate file. The
generated layers are much more than just the conducting layers of your board.
Some of those layers include:
You will also need to generate what is known as a Pick-and-Place file which
includes the coordinates and orientation for all of the components. This file is
used by the manufacturer’s automatic component placement machines.
Finally, you need to output a drill file that provides the exact location and size of
any holes such as vias and mounting holes.
Once you have the Gerber, the Pick-and-Place file, and the drill file you are not
ready to manufacture the board.
Summary
You have now learned how to design a system-level block diagram, select all of
the critical components, design the full schematic circuit diagram, design the
Printed Circuit Board (PCB) layout, and the board of your completed
microcontroller PCB design.
This tutorial has purposefully kept the circuit itself rather simple so as to not
overwhelm you with circuit complexity. That being said, a microcontroller
without any additional functionality isn’t very useful.
In the future, you can personally expand on this circuit by adding lots of additional
features including battery charging, a display, Bluetooth, Wi-Fi, GPS, USB, and
various sensors.
www.tetlangech.com
@tetlangech