KiCAD Tutorial: How to Route USB Differential Pairs
It can be challenging to route differential pair lines in PCB layout software. Thankfully, KiCad provides a few tools to make the task easier. In this article, we'll show you how to determine the differential impedance and use the results to build two USB data lines for a project. It can be challenging to route differential pair lines in PCB layout software. Thankfully, KiCad provides a few tools to make the task easier. In this article, we'll show you how to determine the differential impedance and use the results to build two USB data lines for a project.
Do Some Research
It's a good idea to do some research into the signal requirements before routing any high-speed signal buses or differential pairs.
As with any good research, it's best to start at the beginning. I recommend downloading the USB 2.0 Specification to use as a reference because I'm using USB 2.0 high speed as an example. Because it is a rather large and intimidating manual, we will use it as a reference while we read some other guides with simple language. I recommend reading the following guides to better understand how to route USB 2.0 high-speed data lines:
- https://www.silabs.com/documents/public/application-notes/an0046-efm32-usb-hardware-design-guidelines.pdf
- https://www.ti.com/lit/an/slla414/slla414.pdf?ts=1605978923732&ref_url=https://www.google.com/
- https://octavosystems.com/app_notes/osd335x-design-tutorial/osd335x-lesson-2-minimal-linux-boot/osd335x-lesson-2-usb-circuitry/
Here are some good discussions by engineers about how to do USB data line routing:
- https://electronics.stackexchange.com/questions/325721/do-usb-data-wires-d-d-have-90-ohm-differential-impedance-and-single-ended-45
- https://electronics.stackexchange.com/questions/41851/how-critical-is-the-layout-of-usb-data-lines-how-does-my-layout-look
- https://electronics.stackexchange.com/questions/311310/understanding-usb-differential-and-single-ended-impedance-requirements
- https://electronics.stackexchange.com/questions/446692/routing-long-usb-2-0-high-speed-traces-microstrip-or-stripline
We can deduce a few requirements from these:
- The impedance difference between the data lines should be 90 +/- 15%.
- Each data line's single-ended impedance (for GND) should be 45 +/- 15.
- The difference in the total length of the data lines should not exceed 0.150 inches (3.81 mm). In other words, try to keep D+ and D- the same length.
- Data lines should be routed across an uninterrupted ground plane.
- When possible, avoid 90° bends in traces (this includes vias)
- Stubs should be avoided (traces that branch and go nowhere)
Determine Your PCB Properties
Go to the website of your preferred PCB manufacturer and look up the specifications of the board you want to make. I'll be using OSHPark's 1 oz. copper prototyping service in this example.
- 1-ounce copper (1.4 mils or 0.036 mm thick traces)
- Board thickness of 1.6 mm
- The FR4 core
- two layers
- 6 mil (0.1524 mm) (0.1524 mm) 6 mil is the minimum trace width (0.1524 mm) smallest trace spacing
Please keep in mind that this is a two-layer board! Routing differential pairs on a 2-layer, 1.6 mm thick board can be challenging because the data lines must be wide to reach the desired impedance. You can use much thinner traces for the differential pair on a thinner board (e.g., 0.8 mm thick dielectric material between copper layers). Thin dielectric materials (e.g. FR4) are commonly found between copper layers on 4+ layer boards.
Net Naming in KiCad
- +/- (e.g. D+ and D-)
- _P/_N (e.g. D_P and D_N)
Making Use of the KiCad Impedance Calculator
KiCad includes an impedance calculator! Select Tools > Calculator Tools from the project manager window. Navigate to the TransLine tab.
The transmission line calculator tab provides several impedance calculation options. For our differential pair, we want to use the Coupled Microstrip Line option. Fill out the Substrate Parameters section first.
You can choose your material by clicking on the "..." button next to some of the parameters. We are using copper as the conductor and FR4 as the dielectric material for these.
- Er (dielectric constant): 4.5
- TanD (dielectric loss factor): 0.02
- Rho (conductor’s specific resistance): 1.72e-08
- H (distance between traces and bottom ground plane): 1.6 mm (board thickness)
- H_t (distance between traces and top ground plane): 10000 mm (we want this to be large to approximate infinity, as we are using an external layer for our differential pair--set this to the FR4 thickness if you are routing your USB lines on an internal layer sandwiched between two ground planes)
- T (copper thickness): 0.03556 mm (corresponds to 1 oz. copper)
- Rough (roughness of surface): 0 (not needed for our calculations)
- mu Rel C (relative permeability of conductor): 1 (not needed for our calculations)
Board Configuration
Go to File > Board Setup in the PCB layout tool (pcbnew). Check that your Design Rules > Constraints correspond to what your manufacturer can produce. Then navigate to Project > Net Classes.
Create a new Net Class with the name of your differential pair (I called mine "USB Data"). Set the Clearance to the minimum recommended by your manufacturer, and the Track Width (single track routing) to the width of your default class. Change the DP Width to the calculated trace width (0.77 mm), and the DP Gap to the calculated separation (0.1524 mm).
Highlight the two differential pair net names in the bottom-right corner. Select your differential pair net class name ("USB Data" for me) and click Assign To Selected Nets in Assign Net Class. Your differential pair lines will now adhere to the net rules we just established.
Route Differential Pair
To enter routing mode, click the trace routing tool (or press the 'x' key). Because the footprint pads are so small in this case, we must first route away from them before using the differential pair tool. Select one of your differential pair lines by clicking on it.
If your DP widths are large, as they are for this 2-layer board, KiCad will most likely refuse to route the lines. So, while the routing tool is still open, right-click > Select Via/Track Width > Use Custom Values... Set the trace width to your preference (e.g. 0.2 mm for me).
Left-click once more to begin routing the trace. Avoid 90° bends by fanning away from the pads evenly.Navigate to Route > Route Differential Pair. When you click on one of the traces, the tool should begin routing the two traces with the parameters you specified.If your tracks are too far apart, move your "fanout" traces closer together, as the differential pair needs to maintain the exact separation distance as much as possible. You could also have the differential pair start moving in a different direction so that the tool can match the separation (as I did in my example).
Continue to connect your components by routing the traces. If you need to stop along the way (for example, pull-up/down resistors), try to avoid stubs by routing through those pads (as I have done with the ESD suppression IC in the example below).
Make the traces as straight as possible, avoiding bends wherever possible. In my case, I needed to route the traces to the board's outside edge for the connector, so I had to gradually curve the traces with 45° bends.
Matching Trace Length
When it comes to high-speed buses, you almost always want all of the segments on each bus line to arrive at their destinations at the same time (or as close as possible to the same time). Bits may arrive at different times if the traces are of different lengths! This is referred to as "bit skew," and it can cause havoc on communication buses.
Here's a good article on dealing with bit skew.
Select one of the differential pair lines with the selection tool and look for the Length measurement field. This is the total length of the net. (not the highlighted track segment)
Click on the second net and subtract its length from the first. For me, I get 21.1484 mm - 18.0616 mm = 3.0868 mm. This is within the USB data line's allowable mismatch of 3.81 mm, so I should be fine.
Please keep in mind that I have not yet tested this board, and I do not have a good enough oscilloscope to ensure that my routing was successful. If you have an oscilloscope capable of measuring 480 MHz, you should perform this test using an "eye diagram" or "eye pattern." Here's a good video of a similar demonstration.
You can use the Route > Tune Skew of a Differential Pair tool to correct mismatched lengths. Launch the tool and select the trace segment with the shortest net length. To access the tuning options, right-click and select Length Tuning Settings...
In most cases, the skew should be zero. Other parameters can be changed to meet your PCB manufacturing needs. Select OK.
Move the mouse along the trace you want to tune to see jogs (or serpentine paths) appear as the tool tries to figure out how to lengthen the shorter trace.
Note that in the preceding example, I'm assuming a 0.8 mm thick PCB with 0.003 inches (0.0762 mm) trace spacing. Because the tool did not work well with the super wide traces on my actual board, I was able to use thinner data traces for the demonstration.
In general, the serpentine parts should be added closer to the point where the mismatch occurred (for me, this is closer to the Hirose connector, as the paths are generally straighter near the USB connector). The tool will also tell you whether or not the addition corrects the skew (you want it to say something like "Tuned: skew 0.000 mm").
Click to accept the path modification.
If you're working with a large parallel bus (more than two data lines), you can use the Route > Tune Length of a Single Track tool to add serpentine routing to your shorter lines individually to make their lengths add up to the longest data line's length.
If you would like to see this process in action, see the first part of this video:
Conclusion
I hope this has assisted you in using the built-in KiCad tools to route differential pairs, particularly those pesky USB data lines! Make the tracks as short and straight as possible when in doubt.