<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>my tech blog &#187; electronics</title>
	<atom:link href="http://billauer.se/blog/category/electronics/feed/" rel="self" type="application/rss+xml" />
	<link>https://billauer.se/blog</link>
	<description>Anything I found worthy to write down.</description>
	<lastBuildDate>Thu, 12 Mar 2026 11:36:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>KiCad notes: The one-timer PCB maker&#8217;s hints for the next time</title>
		<link>https://billauer.se/blog/2019/09/kicad-notes/</link>
		<comments>https://billauer.se/blog/2019/09/kicad-notes/#comments</comments>
		<pubDate>Sun, 08 Sep 2019 13:09:26 +0000</pubDate>
		<dc:creator>eli</dc:creator>
				<category><![CDATA[electronics]]></category>
		<category><![CDATA[kicad and pcb design]]></category>

		<guid isPermaLink="false">https://billauer.se/blog/?p=5858</guid>
		<description><![CDATA[Intro These are my notes to self for the next time I&#8217;ll have a PCB design to make. This is definitely not my expertise. My original intention was to start this post with some kind of apologize, saying I only needed to make a simple board, so KiCad was good enough for this purpose. However [...]]]></description>
			<content:encoded><![CDATA[<h3>Intro</h3>
<p>These are my notes to self for the next time I&#8217;ll have a PCB design to make. This is definitely not my expertise.</p>
<p>My original intention was to start this post with some kind of apologize, saying I only needed to make a simple board, so KiCad was good enough for this purpose. However it seems like KiCad is about to become the preferred tool many PCB designers quite soon, if it&#8217;s not there already. It&#8217;s surely handy and relatively easy to learn (at least for me, an experienced Electrical Engineer with no previous hands-on in board design). Does it match up with the expensive tools out there for a heavy and complicated design? I don&#8217;t know.</p>
<p>Everything in KiCad is text based in a simple manner. Important for version control, and using it to monitor my changes. Also very handy for fiddling with the files to get the things right on spot. In particular useful when creating footprints.</p>
<p>All said here relates to KiCad 5.1.4 under Linux Mint 19.</p>
<h3>Getting started</h3>
<ul>
<li>The KiCad version that went along with Mint 19 was heavily outdated. Compare what packages are available <a href="http://kicad.org/download/" target="_blank">directly from KiCad</a>.</li>
<li>When upgrading from 4.x to 5.x, be sure to uninstall the previous version and purge it (apt purge) before installing the new one. Also, delete .config/kicad/ as it contains the paths to libraries for symbols and footprints.</li>
<li>The &#8216;Footprint library path &#8220;&#8230;&#8221; does not exist&#8217; error may be a result of not cleaning up an old installation as mentioned in the previous item.</li>
<li>The <a href="http://docs.kicad.org/" target="_blank">official documentation</a>, in particular the Getting Started with KiCad guide, is definitely the right place to start and refresh memory.</li>
</ul>
<h3>EESchema</h3>
<ul>
<li>Before starting to work: Verify that the page size is correct and that the grid is 50 mils or so, no lower: View &gt; Grid Settings&#8230;  to ensure this.</li>
<li>Basic components: In the &#8220;Device&#8221; library.</li>
<li>Aiming the cursor on something accurately and right-clicking is usually the start for modifying virtually anything.</li>
<li>Better still: Note the hotkey and use it <strong>while hovering</strong> over the relevant place.</li>
<li>&#8220;Drag&#8221; keeps connections. &#8220;Move&#8221; doesn&#8217;t. Use &#8220;Drag&#8221;.</li>
<li>If wires don&#8217;t snap to the ports, and components are placed regardless to the grid, it&#8217;s most likely that the grid is too dense.</li>
<li>Useful hotkeys: Hover-Delete (well, delete), Hover-G (drag, think Blender) and Hover-C (duplicate).</li>
<li>&#8220;Value&#8221;: Each component has a value assigned to it. The value appears on the assembly layer (F.Fab or B.Fab) of the PCB. In other words, the person doing the assembly of the board will see this value in the component&#8217;s position, and select what to put there accordingly. For resistors and capacitors, it&#8217;s obviously the value of the component. For other components, a useful hint on the nature of the device should be there.</li>
<li>&#8220;Reference&#8221;: The symbol&#8217;s unique identifier in the schematics and netlist. U1, J15, C225 etc. By default, they&#8217;re C?, R? etc. until Annotate Schematic&#8230; is done.</li>
<li>Net names: Designated with &#8220;Place Net Label&#8221; or by pressing &#8220;l&#8221;. Makes things easier during layout, and differential pairs must be with &#8220;+&#8221; and &#8220;-&#8221; suffixes (or _p/_n), or PCBNew won&#8217;t play ball later on.</li>
<li>Footprints are assigned on each component&#8217;s Properties (and are not associated with symbols, unlike other tools), or more conveniently, with Tools &gt; Assign Footprints. The association affects the schematic (.sch) file, appearing as a string property consisting of the library name and the footprint&#8217;s name, separated by a colon. Don&#8217;t associate to library footprints, but copies of them, defined explicitly on a local library. Or upgrading KiCad may change the design. See below on footprints.</li>
<li>Plain holes are &#8220;virtual components&#8221;. Add a MountingHole symbol for each, and assign a matching footprint (hole only).</li>
</ul>
<h3>Symbol Editor</h3>
<ul>
<li>Read the <a href="http://kicad.org/libraries/klc/#_symbol_guidelines" target="_blank">Symbol Guidelines</a> in KiCad Library Convention document (KLC), after the daunting naming convention part (start at S3, maybe). It&#8217;s how to get it right.</li>
<li>Check the grid. 50-100 mils, or the wires won&#8217;t snap to ports when the symbol is used (official guideline is 100 mils).</li>
<li>Symbol Editor: When drawing a rectangle, click at the corner points, don&#8217;t hold the mouse button.</li>
<li>It doesn&#8217;t hurt setting the &#8220;Description&#8221; property for each symbol &#8212; it appears on the library&#8217;s list as well as the output netlist.</li>
<li>If a pin has multiple pads assigned to it, KiCad expects them to have track wires on the PCB connecting between them all.</li>
</ul>
<h3>Understanding footprints</h3>
<p>Footprints are a set of graphical shapes in different layers that serve several purposes, all of which much be addressed when setting up a custom footprint:</p>
<ul>
<li>Putting the pads in place: Front copper layer (F. Cu, and also B. Cu with thru pads) and solder mask (F. Mask). Actually, the solder mask layer is the hole in the solder mask. Even though the shape of these is the same, the solder mask is widened slightly when Gerber files are created.</li>
<li>Solder paste: When used, where the stencil holes should allow solder paste to be applied (F. Paste). As with solder mask, the shape is <em>usually </em>the same as the pads, but the datasheet may require a different pattern.</li>
<li>Holes (drilling): These are a side effect of thru-hole pads, and appear in the footprint layers as is there was copper there.</li>
<li>Silk Screen: Descriptive information on the board, in particular the component reference (F. SilkS)</li>
<li>Assembly: Mark the place where the device actually is (F. Fab). The placement&#8217;s origin should also be the footprint&#8217;s (x,y) origin for automatic placement. The reference designator (&#8220;%R&#8221;) is written inside the component&#8217;s boundaries, and its &#8220;value&#8221; (what it is) typically underneath.</li>
<li>Clearance: Ensure that nothing else is placed in the space that the device requires. This no-place space is called &#8220;courtyard&#8221; (F. CrtYd). The idea is simple: If, during layout (with PCBnew), the courtyards of two components overlap, it&#8217;s a DRC error at the very least, and possible also a refusal to generate Gerber files. So the courtyard should be the area that the component must occupy exclusively.</li>
</ul>
<div>
<p>The layer assignment assumes that the component is placed on the front. When placing on the back side, the Layout Editor flips the layer assignment as necessary.</p>
</div>
<div>
<p>Holes is a bit tricky, because they are an implicit result of pads with holes. In particular, NPTH is Non-Plated Thru Holes, and appear in the footprints as pads of this type.</p>
</div>
<h3>Footprints</h3>
<p>There&#8217;s <a title="KiCad PCB layout: Adapting the footprint’s pads to match track width" href="https://billauer.se/blog/2019/09/kicad-custom-pads-anchor-pad-selected-shapes/" target="_blank">another post of mine</a>, which discusses pads and footprint manipulation.</p>
<ul>
<li>Rule number one: Copy or imitate an existing library footprint rather than reinventing the wheel. Preferably imitate one that is likely to be heavily used.</li>
<li>Read the <a href="http://kicad.org/libraries/klc/#_footprint_guidelines" target="_blank">Footprint Guidelines</a> in KiCad Library Convention document (KLC). Skip the naming convention, and start at F4 (or so). This might be the best source on the planet for setting up a footprint. Odds are that these rules are tuned based upon real-life experience of a lot of people.</li>
<li>Never ever use a footprint directly from the libraries to a component in the design. That makes the outcome dependent on the KiCad version running.</li>
<li>Rather, create a project-dedicated footprint library (a directory with a .pretty suffix) in the Footprint editor, and put it in the Project&#8217;s library table. Then open the desired footprint in Footprint editor, and save it into the project&#8217;s library.</li>
<li>Note that the 3D model still points at a KiCad library even after this, but that&#8217;s less important.</li>
<li>Monitor the changes with git. It&#8217;s quite straightforward and allows a safe double-check.</li>
<li>Don&#8217;t hesitate editing the footprint file manually, in particular for nailing exact positions. Exit the Footprint Editor and re-enter it, and then load the footprint. Using &#8220;Revert&#8221; for updating changes won&#8217;t work.</li>
<li>To verify that a footprint is OK:
<ul>
<li>At the very least view each layer separately, and make sure it contains what it should. Drill holes are covered by absence of material in the copper layers.</li>
<li>Verify that SMT pads cover F.Cu, F.Mask and F.Paste (check each separately!). For thru pins, also on the back.</li>
<li>Read through the text file (with _mod suffix) and look for unexpected stuff (one pad having different dimensions for no reason etc.)</li>
</ul>
</li>
<li>Pads may not have a pad number. This is useful for e.g. stencil pattern not matching the shape of the pad.</li>
<li>If multiple pads have the same pin number assigned to them, track wires must be connected between them during the layout.</li>
<li>Pads and other elements may very well not be on the footprint nor layout grid. I find myself calculating their X/Y position rather than placing them, so any position goes.</li>
<li>For adding anything other than a pad, the drawing or text falls on the layer marked with a small arrow in the list of layers.</li>
<li>Text substitutions: %R is replaced with the reference, %V with the value.</li>
<li>Even though the name of the footprint is shown as the &#8220;value&#8221; in the Footprint Editor, it will be the component&#8217;s &#8220;value&#8221; field in Pcbnew. So it&#8217;s useful information during assembly of the board.</li>
<li>Right-click on a pad, select &#8220;Array&#8221; to produce several identical pads with equal spacing. In extreme cases, write a simple script to manipulate the footprint file directly (exotic positions or pad naming).</li>
<li>Use the measurement tool for assurance. It snaps to the grid.</li>
<li>Any line thickness is implemented as a filled circle drawing along the line. This makes rounded corners.</li>
<li>Pads can have arbitrary shapes. See <a title="KiCad PCB layout: Adapting the footprint’s pads to match track width" href="https://billauer.se/blog/2019/09/kicad-custom-pads-anchor-pad-selected-shapes/" target="_blank">this post</a>.</li>
</ul>
<h3>PCBnew (layout)</h3>
<ul>
<li>When starting a new project, remove the *.kicad_pcb file as well as .config/kicad directory, and start from scratch. KiCad&#8217;s defaults are usually good, so if a detail is overlooked, better have the default than some previous setting.</li>
<li>File &gt; Board Setup&#8230; and set the board&#8217;s thickness, trace parameters etc. It&#8217;s also a good idea to define the net classes (in particular high frequency nets).</li>
<li>PCBnew depends on the current netlist as well as the footprint libraries. They are updated only on explicit request, so each time the schematics or footprints in use are updated, the changes must be synchronized by user request. As for the schematics, there an &#8220;Update PCB from Schematics&#8221; button. Or export the netlist from EESchema in default format and load it into PCBnew. It&#8217;s fine to do this iteratively (and even finer when covered by version control to cover up for mishaps).</li>
<li>Grid: Pads may be off the grid, and there&#8217;s no problem selecting them as a start and end point for a route. The track itself will generally go on the grid, except for leaving it in order to reach a pad in a sane manner (usually with a 45-degree detour, not on a grid point). The grid pitch should hence be the approximately most used track width + the track clearance if a dense design is desired. Possibly make it in line with crucial footprints&#8217; pitch, to keep straight traces, aligned with the grid.</li>
<li>Ratsnest: Straight lines showing connections between pads. View all at  once with View &gt; Show Ratsnest (default on) or turn off, and view  individual lines with &#8220;Display local ratsnets&#8221; icon on the toolbar to  the right.</li>
<li>The origin&#8217;s position has no significance, expect that it places the grid. However the absolute position values appear in the Gerber files, but this can be fixed by adding an auxiliary axis (more on this below).</li>
<li>There are no 90 degree turns on tracks (except for power lines), only 45 degrees (and possibly smaller angles when aligning to the grid). Feels a bit awkward in the beginning but sharp turns are evil.</li>
<li>There is no dragging of components (footprints), only moving them, which results in disconnection of all tracks going to it.</li>
<li>While drawing tracks, press &#8220;v&#8221; for a via, press &#8220;/&#8221; to change  the posture (the position of the 45 degree detour, if present).</li>
<li>Always start and end a track by clicking at the center of a pad (the &#8220;anchor&#8221;), in particular if it&#8217;s off-grid.</li>
<li>Ground / power planes: Create a fill zone, which is a polygon which is designated to a net. After setting up the zone, select it, right-click and pick Zones &gt; Fill. This may not work unless there is already a track with the desired net going through the area. The track may remain, as it&#8217;s harmless. It&#8217;s probably the via, which connects the area to the net that does the trick. Once set up, a via is enough to connect to the plane.</li>
<li><strong>Repeat the zone fill after each change that may affect it.</strong></li>
<li>If the zone fill gets too close to a specific footprint&#8217;s pads, open the &#8220;Local Clearance and Settings&#8221; tab on the footprint&#8217;s Properties, and set a larger (actually, non-zero) clearance.</li>
<li>In the end, tracks are a sequence of segments with a start and end position, width, layer and net designation in the *.kicad_pcb file (with &#8220;segment&#8221; keyword), vias are elements with the &#8220;via&#8221; keyword etc. Everything is absolutely positioned. Therefore moving a component (actually, its footprint) disconnects everything. All in all, PCBnew is just a smart drawing program for geometric shapes.</li>
<li>Differential pairs: Route &gt; Differential Pair. Then Route &gt; Tune Differential Pair Skew / Phase, in order to check the skew and possibly tune it (or possibly move a component if that helps).</li>
<li><strong>Setting the parameters for track length and skew tuning:</strong> After selecting the track to tune, instead of moving the mouse to get those humps, right click and select Length Tuning Settings (or CTRL-L). The amplitude and length of these humps can be set, as well as the target length (instead of the default 100 mm).</li>
<li>There&#8217;s a measurement tool (&#8220;Add dimension&#8221;) which is handy to verify certain distances, in particular the dimension of the board. The tool shown an indication when it&#8217;s on a line end, so one can be sure the accurate measurement is made. Best done on a separate drawing layer.</li>
<li>Optionally, add an auxiliary axis origin to the layout, placing the (0,0) point of Gerber and drill files. This changes the aux_axis_origin parameter of the PCB design from (0 0) to whatever it was set to, and the coordinates in the Gerber files will have an offset relative to the layout files. Useful if the entire layout was drawn with some meaningless origin position. Then check &#8220;Use auxiliary axis as origin&#8221; when generating Gerbers and drill files.</li>
</ul>
<h3>3D viewer</h3>
<p>I didn&#8217;t understand the point of a 3D view at first, but it&#8217;s surprisingly helpful, in particular during PCB layout &#8212; even though it&#8217;s also handy with the Footprint Editor. There&#8217;s something reassuring seeing the silk screen as white text on a green solder mask, and the drill holes as see-throughs. Click the mouse&#8217;s middle button to move the scenery.</p>
<p>Launch with View &gt; 3D viewer (or Alt-3).</p>
<h3>Generate Gerber files</h3>
<p>You have reviewed the DRCs in EESchema and PCBnew, right&#8230;?</p>
<p>So to the final check before taping out. Export the files in PCBnew with File &gt; Plot&#8230; and as follows (for a two-layer design):</p>
<p style="text-align: center;"><a href="https://billauer.se/blog/wp-content/uploads/2019/09/makegerber.png"><img class="aligncenter size-medium wp-image-5859" title="Screenshot of dialog box for producing Gerber Files in KiCad" src="https://billauer.se/blog/wp-content/uploads/2019/09/makegerber-300x280.png" alt="Screenshot of dialog box for producing Gerber Files in KiCad" width="300" height="280" /></a><em>(click image to enlarge)</em></p>
<p>and then generate a drill file (click &#8220;Generate Drill File&#8221;, of course).</p>
<p style="text-align: center;"><a href="https://billauer.se/blog/wp-content/uploads/2019/09/makedrill.png"><img class="aligncenter size-medium wp-image-5860" title="Screenshot of dialog box for producing drill files in KiCad" src="https://billauer.se/blog/wp-content/uploads/2019/09/makedrill-300x232.png" alt="Screenshot of dialog box for producing drill files in KiCad" width="300" height="232" /></a><em>(click image to enlarge)</em></p>
<p>All the settings above are KiCad&#8217;s defaults, by the way. Changes in these settings are stored in the *.kicad_pcb file for the next time these windows are opened (and not KiCad-globally).</p>
<p>Note that <strong>two</strong> drill files are (usually) generated: One for plated holes (vias and pads) and one for non-plated holes (typically mechanical holes for mounting).</p>
<p>A component positioning file can be generated with Fabrication Outputs &gt; Footprint Position (.pos) file, however this file uses the internal footprints and their names. In particular, if the footprint&#8217;s origin isn&#8217;t where the automatic placement machine thinks it should be, the device may end up in the wrong place.</p>
<h3>Viewing Gerber files</h3>
<p>KiCad&#8217;s Gerber is fine, but it&#8217;s recommended to install gerbv as well (plain &#8220;apt install gerbv&#8221; on Mint 19). It&#8217;s part of gEDA, and it allows changing the order of the layers, but even more important, to export the current view to pdf. KiCad&#8217;s viewer prints one layer per page, and it&#8217;s hardly helpful. Use the export feature, don&#8217;t print &#8212; the latter generates a microscopic printout.</p>
<p>The main motivation for printing layers is to print the fabrication layer (preferably without values, KiCad has that option) on top of the edge cut and possibly a copper layer. For manual assembly, this gives a good indication of what goes where. To run it, just go</p>
<pre>$ gerbv &amp;</pre>
<p>For KiCad&#8217;s viewer, load both the Gerber files <strong>and the drill files</strong> into Gerbview, and take a close look. The layers are displayed in the order they were loaded, so load the drill files first. As they are usually loaded with multiple selection of files, that&#8217;s probably alphabetical order, putting the bottom layer above the front.</p>
<p>Right-click on the layer list and select &#8220;Sort Layers if X2 mode&#8221; (should be &#8220;in X2 mode&#8221;, I guess) for layers ordered in physical order.</p>
<p>The active layer is always visible (drawn last).</p>
<p><strong>Most important:</strong> Verify that the drill holes, plated and not, are in the correct places.</p>
<p>The DCodes are the aperture with which each line is drawn. An aperture is like a paintbrush, which is defined in each Gerber file for its own drawings. It&#8217;s usually a filled circle or rectangle with specific dimensions. The benefit of having these on the screen is to identify tracks with the same width and pads with the same dimensions, if they have the same DCode and are on the same layer. The same DCode on different layers (and hence Gerber files) has no meaning. For example, D10 and D11 are typically the DCodes of the first apertures defined in Gerber file, and are practically on every layer.</p>
<h3>Create assembly sheet</h3>
<p>If the design is going to be  hand-assembled, better have a simple drawing that tells what goes where.  To do this, plot the Gerber files as before, but uncheck &#8220;Plot  footprint values&#8221; (but keep &#8220;Plot footprint references&#8221; checked, of course). Check F.Fab layer for plotting.</p>
<p>Recall that PCBnew remembers this in the *.kicad_pcb file, so be sure to revert it (with git) afterwards.</p>
<p>Next, open the files with <strong>gerbv</strong> (not KiCad&#8217;s Gerber viewer). Display the F_Fab layer, which should have the component references printed small inside boxes, along with the edge cuts and a copper layer. Change the colors for convenience.</p>
<p>Then File &gt; Export &gt; SVG&#8230; and generate a file. Import that file into a Libreoffice Writer document, and export that document as a pdf. Why not directly as pdf? Because the output pdf is broken, and even when I managed to open it, turning it into a pdf with a decent size turned out impossible.</p>
<p>A similar SVG export can be done from PCBNew: Pick File &gt; Export &gt; SVG&#8230; and select  &#8220;Board area only&#8221; under &#8220;SVG Page Size&#8221;. For Pagination, pick &#8220;All  layers in a single file&#8221;. However I haven&#8217;t figured out how to get rid of the values, and they clutter everything.</p>
<h3>Manufacture</h3>
<ul>
<li>Holes: Manufacturers typically make the hole slightly larger than required, as commented on <a href="https://www.eevblog.com/forum/manufacture/do-pcb-manufacturers-normalise-hole-sizes/msg901321/#msg901321" target="_blank">this thread</a>. The difference is typically no more than 0.1mm, so it&#8217;s not a big deal.</li>
<li>PCB material: FR-4 is de-facto industry standard for rigid boards. 1 oz copper thickness is by far the most common. Pick thicker only for high currents. Board thickness: 0.6/0.8/1.0/1.2/1.6/2.0 mm. Tolerance is typically ±0.1 mm.</li>
<li>Drill size: 0.2 &#8211; 6.3mm (but don&#8217;t go lower than 0.4 mm = 16 mils for basic PCB)</li>
<li>Trace width: 6 mil seems to be a common minimal trace width, but Protel used to set 10 mil as the default (the latter seems to carry up to 1A, but check with a calculator). Unless there are current to carry, stick to these figures in general.</li>
<li>Minimal trace space: 3 mil seems to be possible, but 10 mils should be chosen unless there&#8217;s a reason to push it. Minimal trace to board edge clearance should be 0.3 mm, but standard edge connector footprints tend to take 0.5mm for their pads. So better go for the latter.</li>
<li>All in all, it seems like 10 mils for minimal trace width and space, and 0.4mm mils for vias are the sane choice. If the board gets tight, go smaller.</li>
<li>If the board has an edge connector (&#8220;Gold Finger&#8221;), it&#8217;s ENIG (Electroless Nickel Immersion Gold) surface finish (sometimes referred to as just Immersion Gold). This is required only at the edge connector itself, because the gold&#8217;s role is to ensure good contact. According to the <a href="https://www.ipc.org/TOC/IPC-4552wAm-1-2.pdf" target="_blank">IPC-4552 standard</a>, the default thickness of the gold layer is 0.05μm (sometimes referred to as 2U&#8221;). Sometimes ENIG is offered as the finish only for the edge connector, but this is relevant only for a large board. For a small board like mine, ENIG applies to the entire board.</li>
<li>The assembly is the expensive part. Manufacturing should be at around $5-10 for 5 copies for a small board.</li>
<li>HASL is not RoHS compliant, because of the use of lead. Lead-free HASL should be used instead (or any of the other, more expensive, options).</li>
</ul>
<div><strong>What to submit:</strong></div>
<div>
<ul>
<li>Gerber files in RS-274x format for board outline, copper layers, silk screen(s), solder masks and solder paste. NC drill sometimes required in Gerber format instread of Excellon.</li>
<li>NC Drill file, in Excellon format</li>
<li>For assembly, <a href="https://www.pcbway.com/smt_ordering_guide.html" target="_blank">this page</a> summarizes it well. An assembly sheet as described above is a good idea.</li>
</ul>
</div>
<h3>Finding a manufacturer</h3>
<p>My board involved small SMT components, so no chance to do the assembly myself. Actually, 10 simple components, on a plain FR4 53 x 22 mm board with two 1 oz layers and an edge connector (hence ENIG finish). The price for a turn-key project is at least $100. Don&#8217;t expect less.</p>
<p>And the minimal order quantity is 5. Everywhere.</p>
<p>The place to make a comparison is  <a href="https://pcbshopper.com/" target="_blank">PCB shopper</a>. I also suggest look at <a href="https://manufacturingreports.com/" target="_blank">Manufacturing Reports</a> for some painfully detailed reviews on PCB quality. If you need assembly (PCBA service, A for assembly), select service by assembly costs, as it&#8217;s going to be the dominant part.</p>
<p>So these are the estimated prices I got for a small board.</p>
<ul>
<li><a href="https://www.smart-prototyping.com/PCB-Prototyping.html" target="_blank">Smart Prototyping</a>,  assembly at $80.</li>
<li><a href="https://www.elecrow.com/pcb-manufacturing.html" target="_blank">Elecrow</a>, assembly at about $106.</li>
<li><a href="https://www.pcbway.com/orderonline.aspx" target="_blank">PCBWay</a>, assembly at $30 as a Turnkey project, $88 as kitted or partly kitted. Something tells me they&#8217;re going to charge a lot for the devices. They do send stuff with regular E-Packet = 16 days.</li>
<li><a href="https://www.shenzhen2u.com/PCB" target="_blank">ShenZhen2U</a>, assembly at $50 (pretty much fixed price), allowing plain mail shipping. Headquarters in Hong Kong, but apparently the factory is in Shenzhen (China).</li>
</ul>
<p>I have no affiliation with any of these companies, and this reflects the situation as of September 2019.</p>
<p>These costs didn&#8217;t change much when I changed the parameters of the assembly task. It&#8217;s sensible to assume it&#8217;s mostly the tooling cost (the cost for programming and setting up the automatic manufacturing equipment).</p>
<p>So I sent the files to PCBWay and ShenZhen2U. My personal impressions:</p>
<ul>
<li>PCBWay: Nice web interface, quick and professional response (an hour or so, during Chinese daytime). The price difference between the turnkey and the kitted was indeed a hint to their tendency to make up for the low assembly cost by adding fees everywhere: The components were 50-100% more expensive than Mouser (in low quantity prices). When I asked about it, I got some BS answer that it&#8217;s more expensive for them, taxes etc. PCB manufacturing at $39, which is pretty high. And they add $8 Paypal fee and $20 for shipping and handling with E-packet. And then there&#8217;s an &#8220;assembly promotion discount&#8221; of $30, ending up at $108 next to the &#8220;Confirm &amp; Pay&#8221; button.</li>
<li>ShenZhen2U: Slightly slower response (1 day each time), the website is slightly less useful. The flow was that I ordered the assembly first, then a few emails back and forth (I filled in their BOM form, where I also defined the PCB, and then got an accurate quote) and then the order at the website was updated manually to reflect their quote. They stood behind the $50 assembly cost. Their BOM costs are only slightly higher than Mouser, and they charge $10 for E-packet shipping. PCB manufacturing at $26, which is pretty low. All in all $110, when paid though Paypal (including a Paypal fee of $4.86, which they were clear about and is reasonable).</li>
</ul>
<p>So there we have it: Almost exactly the same bottom line. One company reached it after fiddling with the prices, and the second just listed them upfront. This is why I went for ShenZhen2U, even though <a href="https://manufacturingreports.com/shenzhen2u-pcb-review/" target="_blank">its review</a> on Manufacturing Reviews complained a lot about dirt and bad silkscreen. The parallel <a href="https://manufacturingreports.com/pcbway-pcb-review/" target="_blank">review for PCBWay</a> complained about traces being too thin, which is much more serious IMHO.</p>
<p>My experience with ShenZhen2U is overall good: Even though there was very little communication with them, they manufactured and shipped the boards fairly quickly (I selected very slow shipping and was explicit about the project not being urgent). The five boards arrived, one of which had a defective Micro-B USB 3.0 connector, which short-circuited two pins under a certain mechanical load. This issue showed only with a certain (wiggling) USB plug, so I can&#8217;t rule out that they actually tested this connector but didn&#8217;t spot the issue because they used a proper USB plug, and not what I have.</p>
<p>As a surprise bonus, they sent a bunch of unassembled boards along. Doesn&#8217;t hurt.</p>
<p>Other than the said connector, all boards were OK. As they were manually assembled, there were slight imperfections that are seen in a very detailed view, but the work was definitely good enough for functional purposes. So all in all, the work was good, the price very good, and there was a sense that they know what they&#8217;re doing &#8212; this is me appreciate that there were zero misunderstandings on those unspoken details. I&#8217;m probably going to stay with these guys, and not just because of the price.</p>
<p>I then followed up the same project, with a production of 110 pieces with the same company (ShenZhen2U). In June 2020, I got it done at $690, including everything and shipping with DHL &#8212; which is a reasonable price drop for the amount. They got it done quicker than promised, and the result was flawless. They did the panelizing in a sensible way (following my request on which part of the circuit must be smooth) and all cards except one passed a rather rigorous electronic QA test. The one that failed had the same problem with the connector, which might be my fault this time (I might have broken it while pushing the card into its place). Bottom line: They&#8217;re good at automatic assembly too.</p>
<h3>Finding a manufacturer reloaded (2023)</h3>
<p>Fast forward three years, and I needed to fill up the stock with another round of boards. I would have loved to go back to Shenzhen2u again, but they were not responsive, and probably out of business, even though their website was fully functional (but a running website means nothing, as we all know).</p>
<p>So the initial question is: Should I make a test round of 5 boards, and then go for the 110 boards, or jump to the second phase immediately? Back in 2019, the first 5 boards served the purpose of validating my own design, but this time there&#8217;s no need for that. So is a test run of 5 boards really worth its cost? I was in no hurry.</p>
<p>For a project with few components like mine, one can expect that the assembly of 5 boards will be done completely by hand, but for 110 boards a machine will be used. So these 5 boards don&#8217;t mean much in that respect.</p>
<p>Quality of PCB? It will probably be the same, if both manufacturing rounds are made at the same place. But I will not be surprised if there are several manufacturing facilities behind a PCB company, so each time I&#8217;d issue an order it may be handled by a different facility. So making a test with 5 units doesn&#8217;t necessarily mean anything about what will happen when I order 110 of them.</p>
<p>And then we have components. There are a lot of replacement components out there, and some of the companies offered these replacements upfront with a lower BOM cost. And they are indeed much cheaper. But what if they use these cheap replacements without telling me? If they do that with a USB plug, I can tell that by the marking on the component, but what about SMT capacitors and resistors? They can put whatever junk they have. How would I tell?</p>
<p>Fake components is a problem even with the most respectable dealers. I&#8217;ve actually had a client of mine receive an FPGA that was completely different and incompatible with the one ordered. Yet the marking on the chip was as the one requested. So it was a deliberate fake job, probably by the component dealer&#8217;s vendor. And that happened even before COVID-19 and the shortage of components that came with it.</p>
<p>So a 5 board test round probably gives me an idea of whether they put components that aren&#8217;t catastrophic and something about the PCB quality. Plus if there are some China-style unexpected surprises in store. Never underestimate the Chinese capability of doing something unexpected.</p>
<p>Whether this round is worth its cost depends, well, on this 5-board round&#8217;s price.</p>
<p>What I <a rel="noopener" href="https://billauer.se/blog/2018/10/blender-3d-printing/" target="_blank">learned from 3D printing</a>: The only thing I know for sure about is the price. Higher price doesn&#8217;t necessarily mean better quality. Returning to the same vendor doesn&#8217;t necessarily mean the same result. So go for the offer in terms of price, unless there are bad omens during the initial communication. The chance for failing is basically the same no matter who I choose, so the strategy is to reduce the stake.</p>
<p>There are plenty of reviews for several PCB related companies. Except for the obvious problem that reviews may not be authentic, there&#8217;s also a great difference between the needs and expectations of the person who writes the review. An unprofessional maker who builds a simple 2-layer board is not like a professional engineer who submits a super tight and super-complicated multi-layer board and expects the same quality as an expensive European-standard alternative. That said, I&#8217;ve also seen expensive manufacturers screwing up completely. The difference is that the latter speak better English.</p>
<p>Which brings me back to the same conclusion: There is really no bulletproof way to know who to work with. The only thing you know for sure is the price.</p>
<h3>Getting started, 2023 version</h3>
<p>Even today, <a rel="noopener" href="https://pcbshopper.com/" target="_blank">PCB shopper</a> was the best place to start. There are also reviews on this website, but I had to Google for them – there was no direct link from the homepage to these review pages (only along with price estimations for a specific board). Even though they are clearly affiliated with some of the manufacturers, it still offers some automatic quotes to start with. Then I used ChatGPT in order to get a few additional names. The question was &#8220;which manufacturers are often mentioned along with X?&#8221;.</p>
<p>Another starting point is to submit the manufacturing files to <a rel="noopener" href="https://www.pcbdirectory.com/" target="_blank">PCB Directory</a>. They forward the requirements to some manufacturers, and the quotes from these arrive through email. I got two quotes this way (from <a rel="noopener" href="https://hitechcircuits.com/" target="_blank">HiTech Circuits</a> and CanmTech). Needless to say, use a temporary email for this purpose (I get tons of PCB related spam only because of this page).</p>
<p>That said, I checked how much spam I received to email addresses that I used with PCB manufacturers. Surprisingly enough, absolutely none. Except for direct follow-up offers from the same companies, nothing. None of them disclosed my email to third parties. Maybe I shouldn&#8217;t be surprised: These are serious businesses, after all.</p>
<p>Speaking of which, of course I didn&#8217;t think about turning to all those companies that have been spamming me for years about their PCB factory. I actually checked all candidates, and none of them had ever sent me spam randomly (&#8220;your coupon will soon expire&#8221; mails is something I won&#8217;t consider spam for this purpose).</p>
<p>Elecrow and Seeed Studio did however send me a newsletter promoting their products after subscription, but with an efficient option to unsubscribe. PCB Directory also sent me a newsletter later on, and I unsubscribed.</p>
<p>As for <a rel="noopener" href="https://manufacturingreports.com/" target="_blank">Manufacturing Reports</a>, it doesn&#8217;t appear to have been updated since 2023, so it&#8217;s not relevant anymore.</p>
<h3>So: Picking a manufacturer, 2023 version</h3>
<p>Don&#8217;t ask me how and why, I ended up with 7 quotes. I asked them for a full turnkey project (including component sourcing) for 5 boards and 110 boards. These are the prices per board as I got them, in USD, including the lowest shipping option that each company offered and all kinds of weird extra fees. In short, these are the price per unit as it would actually cost me.</p>
<p>The table is sorted according to the price for 110 pcs. Keep in mind that this is a simple small board with two layers and 10 components. YMMV.</p>
<table style="border-style: solid; width: 492.984px;" border="0" cellspacing="0">
<colgroup width="323"></colgroup>
<colgroup span="2" width="85"></colgroup>
<tbody>
<tr>
<td height="17" align="left"><strong>Company</strong></td>
<td align="center"><strong>USD/board<br />
5 pcs</strong></td>
<td align="center"><strong>USD/board<br />
110 pcs</strong></td>
</tr>
<tr>
<td height="17" align="left"><a rel="noopener" href="https://www.elecrow.com/" target="_blank">Elecrow</a></td>
<td align="center">18.41</td>
<td align="center">4.34</td>
</tr>
<tr>
<td height="17" align="left"><a rel="noopener" href="https://hitechcircuits.com/" target="_blank">HiTech Circuits</a></td>
<td align="center">52.51</td>
<td align="center">5.01</td>
</tr>
<tr>
<td height="17" align="left"><a rel="noopener" href="https://www.pcbway.com/" target="_blank">PCBWay</a></td>
<td align="center">24.49</td>
<td align="center">5.24</td>
</tr>
<tr>
<td height="17" align="left"><a rel="noopener" href="https://www.allpcb.com/" target="_blank">AllPCB</a></td>
<td align="center">39.53</td>
<td align="center">5.42</td>
</tr>
<tr>
<td height="17" align="left"><a rel="noopener" href="https://www.pcbgogo.com/" target="_blank">PCBGOGO</a></td>
<td align="center">45.80</td>
<td align="center">5.84</td>
</tr>
<tr>
<td height="17" align="left">CanmTech</td>
<td align="center">32.04</td>
<td align="center">5.86</td>
</tr>
<tr>
<td height="17" align="left"><a rel="noopener" href="https://www.smart-prototyping.com/" target="_blank">Smart Prototyping</a></td>
<td style="width: 128.844px;" align="center">65.31</td>
<td align="center">6.19</td>
</tr>
</tbody>
</table>
<p>Don&#8217;t get upset if the price jumps up and down throughout the process, and that the estimate of the online calculated might have been too optimistic. Neither how the price is broken down into PCB, PCBA manufacturing, shipping and handling, possibly a separate cost for the stencil and whatnot. The only thing that counts is the total price in the final quote. The rest is just noise that comes from the company&#8217;s marketing guys, and they&#8217;re out of the way as soon as the order is made, no matter which company you choose.</p>
<p>It&#8217;s also fine that their component prices are higher than I can get from Mouser and similar component dealers. They probably get much better prices, yes, but they also add a fee for the work, risk and the extra amount that one has to buy in order to cover up possible mishaps during assembly. Actually, if the price is better that you can get yourself, ask if they didn&#8217;t give you a cheap Chinese replacement part, by any chance.</p>
<p>In short: Look at the bottom line only. Never mind how they got to it.</p>
<p>I wrote earlier that the only thing I know for sure is the price, and <a rel="noopener" href="https://www.elecrow.com/" target="_blank">Elecrow</a>, won with a margin in both quantities. The communication with them was brief, efficient and to the point (unlike several other companies that was between 10-22 mails, just to get the quoting done).</p>
<p>More about Elecrow below&#8230;</p>
<p>There were two companies that deserve a comment:</p>
<ul>
<li><a rel="noopener" href="https://jlcpcb.com/" target="_blank">JLCPCB</a> is maybe the most controversial manufacturer out there. Some love them, some say that they&#8217;re a disaster. They have a lot of reviews, for example in <a rel="noopener" href="https://www.trustpilot.com/review/jlcpcb.com" target="_blank">Trust Pilot</a> and in <a rel="noopener" href="https://www.facebook.com/jlcpcb/reviews" target="_blank">Facebook</a>. The reviews of all sorts appear legit, so no doubt there were unhappy people out there. On the other hand, maybe it&#8217;s a result of having a lot of customers? Not clear. Anyhow, seeing those reviews, I stayed away.</li>
<li><a rel="noopener" href="https://www.pcbway.com/" target="_blank">PCBWay</a>: Communication with them was really lame and somewhat worrying. I asked for 110 boards, and they said the can only manufacture 125 PCBs. Is that OK? Yes, of course, throw 15 boards to the trash. But then they asked if it&#8217;s OK to panelize the board, and if so, if they should depanel them. Even just mentioning the silly idea of not depaneling the boards is worrying. One can only hope that the silliness is limited to their sales, and that the engineering people know better. Regardless, obtaining a quote from these guys was relatively very slow. And tedious.</li>
</ul>
<h3>My experience with Elecrow</h3>
<p>They initially suggested a low-cost replacement for the most expensive part, and they were very upfront about it. When I refused, they gave a very reasonable BOM cost (not too low, but neither high).</p>
<p>Placing an order for a turn-key projects was a bit tricky, because their web interface doesn’t suggest how to do that. But I got instructions for that by email, which boils down to this: The idea is to request an online quote for a PCB Assembly, and that allows uploading Gerber files, BOM and files related to assembly. The quote is then found under My Account &gt; Service Orders, and once it has been made, it’s just a matter clicking &#8220;Check out&#8221; in order to put it in the cart, and then from there to submit an order. The issue of shipping is a bit messed up, because it’s included in the original quote, and then there are shipping options while checking out. So pick &#8220;free shipping&#8221; to prevent the price from increasing. All in all, their web interface for obtaining quotes and placing orders is not ideal, but once you get the principle it’s smooth.</p>
<p>I put an order for five pieces with Elecrow (92 USD). The Service Orders section in my web account got successively updated as the manufacturing went on, and they uploaded photos of an assembled PCB and even a small video. At some point, I got an email asking me to review the results and confirm shipment.</p>
<p>And this is where things got a little twist. I saw a small notch on the edge of the PCB, which was clearly going to be problematic. But since I only had the picture from one board, and this was a test round, I confirmed the shipment. In this situation, I preferred to see the situation as is, rather than having them fix the problem.</p>
<p>The shipping was quick and smooth, even though I selected a low-cost option:  It was a matter of just 10 days. Which is very quick from China.</p>
<p>Once the boards arrived, I tested them electronically, and they were all 100% OK. There were no surprises. The correct parts were used, no unsolicited replacements. As for the cutting of the boards, they all had this same notch, as shown in this picture that I&#8217;ve taken:</p>
<p><img class="size-full wp-image-6931 aligncenter" title="The notch on the board I received from Elecrow" src="https://billauer.se/blog/wp-content/uploads/2019/09/notch-on-elecrow-pcb.jpg" alt="The notch on the board I received from Elecrow" width="500" height="490" /></p>
<p>It&#8217;s important to reiterate: I saw this problem in the picture that was shown to me <strong>before</strong> confirming the shipment, and I had the opportunity to complain about it. So even though one can question their QA for passing through something like this, odds are that this would have ended well, had it not been for me insisting to get the boards as is.</p>
<p>I wrote a mail to them, asking for the reason to this notch. The answer I got was that the notch is between the cutting machine&#8217;s starting point and ending point, as it makes the trajectory to cut out this small board. They emphasized that this is something that happens only for small-volume orders, and that someone simply forgot to remove the notch manually. As for the rather odd position of this notch, I suppose they manufacture several small boards on the same PCB. So the position was convenient in the context of this larger PCB, I guess.</p>
<p>So the question was whether to continue with them or not. I decided to go on with them for the 110 pieces, mainly because everything was perfect, except for this notch thing. And even if this mishap would have happened on 110 boards, it&#8217;s not a big deal to remove the notches with a nail file. Silly, but not a big deal.</p>
<p>The results? Excellent. All 110 boards passed the electronic test with no issues at all. And there was no issue with any notch. I couldn&#8217;t ask for more.</p>
<h3>What to track with git</h3>
<p>For a project named projname, this is the list of files I found sufficient to track:</p>
<pre>.gitignore
fp-lib-table
projname.dcm
projname.kicad_pcb
projname.lib
projname.pretty/*.kicad_mod
projname.pro
projname.sch
sym-lib-table</pre>
<p>as for .gitignore itself, this is my somewhat bloated file, which eventually did the job.</p>
<pre>*-save.pro
*-cache.lib
*-rescue.lib
*-save.kicad_pcb
_autosave-*.*
*.kicad_pcb-bak
*.000
*.net
*.net~
*.bak
*.sch-bak
*.bck
*.gbr
*.drl
*.pos
*.wrl
*.csv
*.rpt
*.step
*.stp
*.svg
*.ps
*.pdf
*.dxf
*.plt
*.cad
fp-info-cache
*~</pre>
<p>This ignores files produced by KiCad as well as backups. Plus a lot of garlic against files that were never seen.</p>
]]></content:encoded>
			<wfw:commentRss>https://billauer.se/blog/2019/09/kicad-notes/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PCB layout: Selecting the track width and spacing for a differential signal</title>
		<link>https://billauer.se/blog/2019/09/coupled-microstrip-line-width-spacing/</link>
		<comments>https://billauer.se/blog/2019/09/coupled-microstrip-line-width-spacing/#comments</comments>
		<pubDate>Sun, 08 Sep 2019 12:03:39 +0000</pubDate>
		<dc:creator>eli</dc:creator>
				<category><![CDATA[electronics]]></category>
		<category><![CDATA[kicad and pcb design]]></category>

		<guid isPermaLink="false">https://billauer.se/blog/?p=5852</guid>
		<description><![CDATA[Introduction Even though this is definitely not my expertise, I made a simple adapter board carrying USB 3.0 signals. The name of the game with such boards is to make a minimal impact on the signals, which means, among others, selecting the attributes of these two pairs of differential lines (SSRX and SSTX) in a [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>Even though this is definitely not my expertise, I made a simple adapter board carrying USB 3.0 signals.</p>
<p>The name of the game with such boards is to make a minimal impact on the signals, which means, among others, selecting the attributes of  these two pairs of differential lines (SSRX and SSTX) in a way that minimizes the damage their very existence causes.</p>
<p>The other name of the game is to minimize the financial damage by ensuring that the board can be manufactured everywhere and by everyone, in particular those low-cost services.</p>
<p>There are a lot of things to be aware of, and I suggest reading application notes of devices that deal with the relevant type of signals. For example, TI&#8217;s board design guidelines for one of their SuperSpeed USB related devices, <a href="http://www.ti.com/lit/ug/sllu149e/sllu149e.pdf" target="_blank">sllu149e.pdf</a>.</p>
<p>This post focuses on selecting the track width (W) and spacing between the two differential pairs (S) of a coupled microstrip line. This is the widely recommended way to carry RF-frequency differential signals on a PCB, and it simply means that the two wires are routed at one of the exposed layers (top or bottom), and that there&#8217;s a ground plane layer immediately underneath it. See drawing at the bottom left of the image below.</p>
<p>Quite interestingly, there is little relation to the W and S of the differential pair in most application notes, so it&#8217;s not all that clear what considerations should be made. However, it&#8217;s well-known that W and S influence the differential impedance, and this is mentioned everywhere. The USB 3.0 specs requires the <em>differential characteristic impedance</em> to be  90Ω ± 7Ω in section 5.6.1.1.1. So there&#8217;s a start.</p>
<h3>Assumptions on the PCB</h3>
<p>These are the attributes of the most typical PCB one can find (and therefore hopefully low-cost to manufacture):</p>
<ul>
<li>Board material: 1 oz copper (0.035 mm thick) on FR4 resin</li>
<li>Minimal track width: 10 mil. I&#8217;m generous here, as several low-cost manufacturers offer as low as 4 mil, but 6 mil is often the minimum for the lowest price. Often there&#8217;s a remark saying &#8220;&gt;8 mil recommended&#8221;. So this indicates what&#8217;s considered easily manufactured.</li>
<li>Minimal spacing between tracks: 10 mils, exactly for the same reasons. Manufacturers tend to give the same figures for both.</li>
<li>Vias: I didn&#8217;t have any (on the differential pairs, that is).</li>
</ul>
<h3>The PCB calculator</h3>
<p>There are plenty of online calculators and other utilities for calculating the impedance of microstrip pairs. Since I used KiCad 5.1.4 for the PCB design, I also went for its PCB calculator (image of screenshot below). It&#8217;s not the easiest one however.</p>
<p style="text-align: center;"><a href="https://billauer.se/blog/wp-content/uploads/2019/09/final-0.8-0.2mm.png"><img class="aligncenter size-medium wp-image-5853" title="KiCad's PCB calculator screenshot on coupled microstrip line" src="https://billauer.se/blog/wp-content/uploads/2019/09/final-0.8-0.2mm-300x214.png" alt="KiCad's PCB calculator screenshot on coupled microstrip line" width="300" height="214" /></a><em>(click image to enlarge)</em></p>
<p>Quite obviously, the board&#8217;s parameters are on the left column, and the track&#8217;s data to the right. So let&#8217;s start with the board&#8217;s parameters. Note that the &#8220;&#8230;&#8221; to the right allows selecting materials instead of feeding numbers, and guess what, they&#8217;re correct (at least those related to my board).</p>
<ul>
<li>Er: Select FR4, and the dialectric constant is set correctly to 4.6.</li>
<li>TanD: Select FR4 here as well, and don&#8217;t bother that it&#8217;s not accurate (because of the frequency): It doesn&#8217;t influence the impedance, but the only the loss calculation.</li>
<li>Rho: Select copper. It&#8217;s resistivity is correct.</li>
<li>H: The height to the ground plane. In my case, it&#8217;s a dual-layer board, so the ground plane is the back side. Hence H is the thickness of the entire board, 1 mm.</li>
<li>H_t: The height to the ground plane (?) above the board. Luckily, doesn&#8217;t have much influence on the impedance unless it&#8217;s really small.</li>
<li>T: The strip thickness. 0.035 mm for 1 oz.</li>
<li>Conductor roughness: Irrelevant for impedance calculation, but will influence conductor loss calculations</li>
<li>Relative permeability of conductor: Set to 1 for copper. Copper’s relative permeability, <a href="https://en.wikipedia.org/wiki/Permeability_(electromagnetism)" target="_blank">according to Wikipedia</a>, is 0.999994, and this has no influence on impedance calculations.</li>
<li>Frequency: For a USB 3.0 link, I set it to 5 GHz. Its influence on the impedance is quite small, so no need to be worried about the idea that a digital signal isn&#8217;t really band limited and such.</li>
</ul>
<h3>OK, so now what?</h3>
<p>The goal is to find W and S.  To the right, there&#8217;s also L, the length of the trace. It has no influence on the impedance, so any positive number goes. Likewise, we don&#8217;t care about the electrical length (Ang_l) which basically says how much delay, in terms of sinusoidal phase of the given frequency, the conductor imposes.</p>
<p>So there are two input parameters, W and S, and two output parameters, Zeven and Zodd. As the signal is differential with no common mode component, we don&#8217;t care about Zeven at all: Since Zdiff = Zodd * 2, we just need to make Zodd = 45Ω, more or less.</p>
<p>Or in other words, there is one degree of freedom. There isn&#8217;t one pair of W and S for a given board and impedance, but we get to select one of them.</p>
<p>So the rather silly methodology is to pick some initial W and S, more or less at random, and click the down arrow (or &#8220;Analyze&#8221;). See what we got. Then set Zodd to 45, and click the up arrow (or &#8220;Synthesize&#8221;). And then some manual iteration, until the result is fine.</p>
<p>But that leaves us with the need to make a decision.</p>
<h3>What is a good pair of W and S?</h3>
<p>To make a long story short, as small as possible. These wires aren&#8217;t carrying any significant currents, so their size is only limited by the manufacturing process (or: How much we&#8217;re ready to pay for it). For low-cost manufacturing, consider that they sometimes make the trace thinner by a mil or two (this is the low-quality side of low-cost). So it&#8217;s important to be aware of how this would impact the impedance.</p>
<p>Why is small good? Mainly for crosstalk and noise immunity: The closer the wires are to each other,  the more do they behave as a differential pair. Being closer to each  other, noise signals are added more equally, leading to a smaller  differential noise signal. A common rule of thumb is that a differential  pair should have a clearance of 5W from any other conductor.</p>
<p>It&#8217;s also a matter of taking up less physical space on the board (in particular when respecting the 5W rule above).</p>
<p>As for signal losses, it doesn&#8217;t seem to make a big difference.</p>
<p>There is however no defined way to iterate with the calculator to obtain good values. One may select a minimal W and try out several S until Zodd is 45Ω, but it may be below the minimal S allowed.</p>
<p>In that case, start with the minimal S, and increase W until Zodd is 45Ω. If we want to follow the 5W rule, that is probably the best pair achievable.</p>
<p>As for my own choice, it&#8217;s the one shown in the image above: W = 0.8 mm, S = 0.2 mm. This makes S a bit smaller than 8 mils. Even though me original intention was not to go below 10 mils, this settings allows me to meet the 5W rule. And it should still be fine to manufacture virtually anywhere.</p>
<p>These rather bulky tracks weren&#8217;t easy to connect to the USB receptacle&#8217;s footprint, as discussed in <a title="KiCad PCB layout: Adapting the footprint’s pads to match track width" href="https://billauer.se/blog/2019/09/kicad-custom-pads-anchor-pad-selected-shapes/" target="_blank">another post</a>.</p>
<h3>Other calculators</h3>
<p>Given the importance of getting these figures right, it&#8217;s reassuring to feed the results into other calculators before etching them in metal.</p>
<p>Note that some calculate Zodd and some give you the differential impedance (plus, possibly some other figures). Don&#8217;t get confused, and no panic.</p>
<ul>
<li><a href="http://www.multek.se/index.php?page=differential-microstrip-impedance" target="_blank">Multi-Teknik&#8217;s calculator</a> is much simpler, and also shows the formula.</li>
<li><a href="https://www.everythingrf.com/rf-calculators/differential-microstrip-impedance-calculator" target="_blank">Everything RF</a>, also showing the formulas.</li>
<li><a href="https://www.eeweb.com/tools/edge-coupled-microstrip-impedance" target="_blank">EEweb</a> is more like the PCB calculator (i.e. requires some brain) and shown more math that you probably want to know about.</li>
<li><a href="https://www.allaboutcircuits.com/tools/edge-coupled-microstrip-impedance-calculator/" target="_blank">All About Circuits</a> is also on the heavier part with the math.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://billauer.se/blog/2019/09/coupled-microstrip-line-width-spacing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KiCad PCB layout: Adapting the footprint&#8217;s pads to match track width</title>
		<link>https://billauer.se/blog/2019/09/kicad-custom-pads-anchor-pad-selected-shapes/</link>
		<comments>https://billauer.se/blog/2019/09/kicad-custom-pads-anchor-pad-selected-shapes/#comments</comments>
		<pubDate>Sun, 08 Sep 2019 10:59:44 +0000</pubDate>
		<dc:creator>eli</dc:creator>
				<category><![CDATA[electronics]]></category>
		<category><![CDATA[kicad and pcb design]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">https://billauer.se/blog/?p=5834</guid>
		<description><![CDATA[Introduction It just so happened that I went for a pair of 0.8mm thick wires, with 0.2mm between them, in order to achieve 90Ω differential impedance on a 1 mm thick FR4 board. No wonder PCBnew (KiCad&#8217;s layout program) refused connecting these wires to a USB SuperSpeed receptacle&#8217;s footprint, with its 0.4 mm side pads, [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>It just so happened that I went for a pair of 0.8mm thick wires, with 0.2mm between them, in order to <a title="PCB layout: Selecting the track width and spacing for a differential signal" href="https://billauer.se/blog/2019/09/coupled-microstrip-line-width-spacing/" target="_blank">achieve 90Ω differential impedance</a> on a 1 mm thick FR4 board. No wonder PCBnew (KiCad&#8217;s layout program) refused connecting these wires to a USB SuperSpeed receptacle&#8217;s footprint, with its 0.4 mm side pads, spaced 0.65 mm apart: They simply can&#8217;t get squeezed in.</p>
<p>A similar problem occurred with the 0402-sized coupling capacitors in series with one of the differential pairs: Even though there was no problem connecting the differential wires to the capacitors (after reducing the clearance limit for the relevant tracks), the tracks ran over the capacitors&#8217; pads.</p>
<p>This post suggests manipulating the footprints to match the specific width and spacing of a differential pair. Not the easiest way out, but the result is clean and elegant.</p>
<p><strong>The quick and dirty solution</strong> is to draw the tracks until close to the footprint, and do the last segment with a thinner track width. Possible, works, but creates ugly discontinuities, and maybe even signal integrity issues due to reflections.</p>
<p>There is more than one way to do it, and I hope  it won&#8217;t be too confusing as I jump around between the different options. Each has its advantages and disadvantages.</p>
<p>As a side benefit, this post goes into the technique of making arbitrarily shaped pads.</p>
<p>All said below relates to KiCad 5.1.4, which is up to date as of September 2019. On Linux Mint 19, not that it matters.</p>
<h3>Footprints, pads, tracks</h3>
<p>Before getting into business, let&#8217;s talk a bit about pads and how wire tracks are connected to them.</p>
<p>First of all, the footprint: It&#8217;s a collection of graphic elements, each assigned to one or more layers, that are plotted on the PCB layout as a group. The relative position between some elements are fixed, and others can be moved (text labels in particular).</p>
<p>A well-known special element is the pad. Aside from the fact that it&#8217;s a useful shortcut to draw a shape on several layers at a time, there are three things that are exclusive for pads:</p>
<ul>
<li>Only a pad can be assigned a pin number</li>
<li>A pad is the final destination for a wire track (it has an &#8220;anchor&#8221;).</li>
<li>Drill holes (plated or not) can only be defined with pads.</li>
</ul>
<p>The first two relate to the capability to connect wires to the component&#8217;s pin: The pin number, with respect to the netlist, tells PCBnew which wire track to connect to the pad. The anchor tells where to, geometrically, the wire should be connected. Each wire track starts and end at an anchor point. For simple pads, it&#8217;s always at their center.</p>
<p>Remember that if you want to draw something on copper or some other layers, and don&#8217;t need any of the three exclusives listed above, just drawing filled polygons on the relevant layers might be a better idea.</p>
<p>And now to the wire track&#8217;s geometry.</p>
<p>The final product of the PCB layout is Gerber files. Without getting into the details, the way graphics is defined in these files is with straight lines or arcs (part of a circle, or the entire circle), which are given their thickness with an aperture. This aperture is a filled geometric shape, in most cases either a circle or a square with a per-aperture given size.</p>
<p>The circle aperture is apparently dominant in KiCad: When drawing a wire track on a copper layer, it&#8217;s effectively a line with a circular aperture. Think of painting the track&#8217;s with a marker having a circular shape, with the diameter of the track&#8217;s designated thickness.</p>
<p>Actually, it seems like any line thickness in KiCad is implemented with circular aperture. For example, when drawing filled polygons, there are rounded corners when the line thickness is non-zero, due to the circular aperture.</p>
<p>The conclusion of all this: If the pad is circular, with a diameter matching the wire track&#8217;s thickness, there will be a perfect overlap between the pad and the track&#8217;s end, no matter what direction the track came from. For a rectangular pad, this holds true only if the track comes straight in, and its edge length matches the thickness of the pad in the same direction.</p>
<h3>Modifying footprints</h3>
<p>We&#8217;ll start with the simpler, and less impressive example: The capacitors&#8217; 0402 footprint. The original 0402 footprint looks like this, with 0.59 x 0.64 mm rounded rectangle pads:</p>
<p><img class="aligncenter size-medium wp-image-5838" title="Original 0402 footprint" src="https://billauer.se/blog/wp-content/uploads/2019/09/original-0402-footprint-300x218.png" alt="Original 0402 footprint" width="300" height="218" /></p>
<p>The 0.8 mm thick tracks do connect to a pair of such capacitors, but only after reducing the minimal clearance to 0.15 mm (which is the wrong thing to do):</p>
<p style="text-align: center;"><a href="https://billauer.se/blog/wp-content/uploads/2019/09/post-too-close.png"><img class="aligncenter size-medium wp-image-5842" title="Tracks coming too close" src="https://billauer.se/blog/wp-content/uploads/2019/09/post-too-close-300x213.png" alt="Tracks coming too close" width="300" height="213" /></a><em>(click image to enlarge)</em></p>
<p>It&#8217;s quite evident that the tracks are all over the pads. This isn&#8217;t all that bad, because the solder mask is still correct (not visible on image above). And yet, the tracks get too close to each other, and they&#8217;re not supposed to extend the pads on the copper layer.</p>
<p>So this is what an extended 0402 looks like, with the beginning of a 0.8 mm track on each side:</p>
<p><img class="aligncenter size-medium wp-image-5839" title="0402 footprint with extensions" src="https://billauer.se/blog/wp-content/uploads/2019/09/extended-0402-300x220.png" alt="0402 footprint with extensions" width="300" height="220" /></p>
<p>Each pad actually consists of three elements: The original pad (without the pad number), a filled polygon and a circular pad, which has the pad number assigned to it.</p>
<p><img class="aligncenter size-medium wp-image-5840" title="0402 footprint with extensions, separated" src="https://billauer.se/blog/wp-content/uploads/2019/09/extended-0402-separated-300x208.png" alt="0402 footprint with extensions, separated" width="300" height="208" /></p>
<p>Moving these elements apart a bit for clarity, it looks like this:</p>
<p><img class="aligncenter size-medium wp-image-5841" title="0402 footprint with extensions, detailed" src="https://billauer.se/blog/wp-content/uploads/2019/09/extended-0402-exploded-300x199.png" alt="0402 footprint with extensions, detailed" width="300" height="199" /></p>
<p>But the real need for this technique came from the USB 3.0 receptacle&#8217;s footprint, having pads too small for the 0.8 mm tracks:</p>
<p style="text-align: center;"><a href="https://billauer.se/blog/wp-content/uploads/2019/09/post-microb-regular.png"><img class="aligncenter" title="Micro B receptacle's footprint" src="https://billauer.se/blog/wp-content/uploads/2019/09/post-microb-regular-300x144.png" alt="Micro B receptacle's footprint" width="300" height="144" /></a><em>(click image to enlarge)</em></p>
<p>To overcome this, extension were added, making pads 0.8 mm wide and 0.2 mm apart. The pad is square in this example, so the track can only arrive directly from above:</p>
<p style="text-align: center;"><a href="https://billauer.se/blog/wp-content/uploads/2019/09/post-microb-exploded.png"><img class="aligncenter size-medium wp-image-5843" title="Micro B receptacle's footprint, with extensions" src="https://billauer.se/blog/wp-content/uploads/2019/09/post-microb-exploded-300x178.png" alt="Micro B receptacle's footprint, with extensions" width="300" height="178" /></a><em>(click image to enlarge)</em></p>
<p>Pad 10 of the image above has been separated for the sake of demonstration.</p>
<p>This is what the result looks like in a PCB design using these:</p>
<p style="text-align: center;"><a href="https://billauer.se/blog/wp-content/uploads/2019/09/on-pcb.png"><img class="aligncenter size-medium wp-image-5844" title="Tracks on PCB" src="https://billauer.se/blog/wp-content/uploads/2019/09/on-pcb-300x173.png" alt="Tracks on PCB" width="300" height="173" /></a><em>(click image to enlarge)</em></p>
<p>Exaggerated perfectionism or the right thing for a 5 or 10 GHz signal, who knows.</p>
<h3>How to do this</h3>
<p>A pad with type Custom (having rectangular or circular anchor) can be merged with any number of geometrical shapes, turning it into a larger pad, with the shape of the union of all merged areas.</p>
<p>So:</p>
<ul>
<li>Draw a filled polygon (on the F.Silk for  example) and then change its line thickness to 0.</li>
<li>Create a pad with  &#8220;Shape&#8221; set to &#8220;Custom (Rect. Anchor)&#8221;, which will be the actual pad  that the wire will be connected to.</li>
<li>Select both, right-click, and pick  &#8220;Create Pad from Selected Shapes&#8221;.</li>
</ul>
<p>The attributes (which layers etc.)  are taken from the anchor pad, but the shape is the union of the pad and  the polygon. As mentioned above, a circular anchor pad with the diameter of the track width is easiest to work with later (but more difficult to match the polygon for).</p>
<div>
<p>In fact, getting the polygons just right is a bit of a headache. I found myself editing the polygons&#8217; coordinates manually in the footprint files to get exact positions. The   &#8220;Move Exactly&#8221; feature is also helpful for placing items accurately.</p>
</div>
<p>Note that the extra pad (actually, the anchor pad) should be designated for the copper layer only: No solder mask nor paste layers. We define it as a pad so a track will connect to it, but it&#8217;s not going to be soldered on.</p>
<p>What about the courtyard? Should it be extended? Well, no: There&#8217;s no problem having other components placed over the extended area, which is part of the wiring. PCBnew ensures no other copper traces get near by virtue of clearance requirements.</p>
<p>Having said all this, note that the trickery with &#8220;Create Pad from Selected Shapes&#8221; isn&#8217;t really necessary. It just makes it simpler to manipulate the shapes as one unit. It also moves the filled polygon from its original layer to the copper layer, but that can be done on the polygon&#8217;s own attributes. This way or another, the track connects to the anchor pad (in the merged version) or a simple pad. It doesn&#8217;t really matter if the extra geometry is linked to the pad or not.</p>
<h3>But now we have two pads</h3>
<p>There is the original pad, which is left in place, partly for laziness: It&#8217;s already at the right size and place, covering the correct layers (including solder mask and paste), so why mess with it? And then there&#8217;s the new pad, which is part of the extension, only for the copper layer.</p>
<p>The question is whether the original pad should also have the pin number, or if it should be pinless. There are basically three options:</p>
<ol>
<li>Keep the pin number, so both pads have the same number. In this case, PCBnew requires both pads to be connected (wires explicitly with tracks) or the original pad is considered unconnected, and will generate a DRC error. Signing off a PCB layout with unconnected nets errors requires a certain amount of courage. And drawing the internal wire without adding dirt may be tricky.</li>
<li>Remove pin number designation from original pad. But this will cause PCBnew to complain that the new and original pads are too close (in fact, they&#8217;re touching). They are considered two different pads, and generate a DRC error like the following:
<pre>ErrType(19): Pad too close to pad
    @(201.775 mm, 57.300 mm): Pad of J1 on F.Cu and others
    @(204.850 mm, 57.950 mm): Pad 9 of J1 on F.Cu</pre>
<p>Well, in some cases this can be solved by skipping the &#8220;Create Pad from Selected Shapes&#8221; part, and have two (non-custom) pads, with the filled polygon on the copper layer between them, and hence also making enough space between the pads. It&#8217;s a question of the size of the polygon vs. the required pad clearance.</li>
<li>Replace the original pad with plain graphics, drawing it as three distinct and overlapping polygons: One for the copper layer, one for the solder mask and one for the solder paste. Rounded corner are achieved with the polygon&#8217;s line thickness, if so desired. Haven&#8217;t tried this (it&#8217;s a bit tedious, after all), but it should work. Note that just merging the original pad&#8217;s geometry into the new pad will only cover the copper layer (as the new pad is defined not to cover the two other layers).</li>
</ol>
<p>I went for the second option, because I allow myself to ignore DRCs on pad-to-pad clearances, but not unconnected net errors. If pad-to-pad clearances are violated because of components placed too close, courtyards are there to prevent them. So making a habit of ignoring pad-to-pad DRC errors is fairly OK.</p>
<h3>Impact on signal integrity</h3>
<p>I started with this pad manipulation thing because I thought I had no choice, but then I asked myself what this does to the signals. Short answer: I don&#8217;t really know, because I haven&#8217;t run an electromagnetic simulation on this.</p>
<p>But the word is that any sudden change and discontinuity causes reflections, so connecting to a pad with a gradually changing track width should be better. Maybe, one day, there will be a KiCad feature making all or selected connections between pads and tracks adapting this way.</p>
<p>In fact, think of a thin wire connected to a thicker pad. Wouldn&#8217;t it be better if it became gradually thicker as it approaches the pad, so there&#8217;s no discontinuity there?</p>
<p>Or maybe it won&#8217;t make enough difference to care about this at all. Once again, I don&#8217;t know. I guess it&#8217;s something the RF guys care more about, and much less us dealing with digital signals.</p>
<p>I should also mention that the way that the pads go sideways on the receptacle shown above, creates a certain difference in the track length, which isn&#8217;t accounted for. One can measure the difference manually and feed it into &#8220;Pad to die length&#8221; in the pad&#8217;s attributes, but that was a bit too much for me.</p>
]]></content:encoded>
			<wfw:commentRss>https://billauer.se/blog/2019/09/kicad-custom-pads-anchor-pad-selected-shapes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>USB 3.0 device compliance test notes</title>
		<link>https://billauer.se/blog/2019/06/usb-if-compliance-test/</link>
		<comments>https://billauer.se/blog/2019/06/usb-if-compliance-test/#comments</comments>
		<pubDate>Sat, 15 Jun 2019 15:55:24 +0000</pubDate>
		<dc:creator>eli</dc:creator>
				<category><![CDATA[electronics]]></category>
		<category><![CDATA[FPGA]]></category>
		<category><![CDATA[USB]]></category>

		<guid isPermaLink="false">https://billauer.se/blog/?p=5758</guid>
		<description><![CDATA[Introduction While implementing Xillybus&#8216; USB 3.0 general purpose IP core for FPGAs, I found the USB Implementers Forum&#8217;s compliance tool handy, yet somewhat quirky, for verifying I got things right. It was USB3CV version 2.1.12.1, running on Windows 10 @32 bit. The 64 bit version works the same (I&#8217;ve tested it as well). A GPLed [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>While implementing <a href="http://xillybus.com/" target="_blank">Xillybus</a>&#8216; USB 3.0 general purpose IP core for FPGAs, I found the USB Implementers Forum&#8217;s compliance tool handy, yet somewhat quirky, for verifying I got things right. It was USB3CV version 2.1.12.1, running on Windows 10 @32 bit. The 64 bit version works the same (I&#8217;ve tested it as well).</p>
<p>A GPLed open-source version for Linux is something one could have wished for (and would probably improve things considerably), but that&#8217;s probably too much to expect when Microsoft is all over the USB standard.</p>
<p>These are my notes as I went along.</p>
<h3>Obtaining and installing</h3>
<p>Download USB3CV from <a href="https://www.usb.org/usb32tools" target="_blank">this page</a>. Installation went smooth on Windows 10 @32 bits (and 64 bits as well).</p>
<p>As suggested by the utility&#8217;s author, disable UAC completely on the system by invoking regedit, setting the EnableLUA to 0 on the following path:  HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System. And restart Windows. This seems to be a matter of convenience, and not something to do on anything else but an internal computer intended for testing only, as it&#8217;s a security hole.</p>
<p>A usbif.json file can be obtained from USB-IF for use by USB3CV. This only allows looking up the Vendor ID, so there&#8217;s no problem working without it. There will be two red lines in the log, but the relevant tests passes without this file as well.</p>
<p>Installing on Windows 7 (32 bit) failed on installing the Microsoft Visual C++ 2017 Redistributable (vc_redist.x86.exe) prerequisite. Despite removing everything installed on that computer (under Programs and Features), the problem remained &#8212; it&#8217;s probably because SP1 isn&#8217;t installed on that machine.</p>
<h3>The hijack</h3>
<p>When invoked, the USB3CV program replaces the original xHCI driver in Window&#8217;s I/O stack with  one it uses for testing, and returns the original one when exiting. This means that all USB devices that are  connected to the USB controller (possibly all USB devices on a  motherboard) become effectively disconnected. That includes USB 2.0 and USB 1.1 devices. To work around this, either use good-old  PS/2 keyboard and mouse, employ a remote session, or plug in an extra USB  board (possibly as low as USB 1.1) and plug the USB mouse and  keyboard there. Otherwise, well, no mouse and keyboard on a Windows  system.</p>
<p>Also, <strong>be sure to close USB3CV before shutting down Windows</strong>, or it may not have enough time to bring the original driver back. See more notes on this issue below.</p>
<p>USB3CV is kind enough to prompt for which USB controller to take  over, and it&#8217;s also fine if you accidentally knock out your own USB  mouse and keyboard (a second dialog box requires confirming the takeover  with a mouse click, or it times out and reverts it).</p>
<p>The immediate difference when plugging in a device when USB3CV is  running (and has taken over the relevant controller) is that nothing  happens &#8212; there is no enumeration nor descriptor fetching, as there  would usually be. This happens only later on, when requesting tests, in which case  the controller is scanned for devices. Several times, actually.</p>
<p>Another significant difference is that the test xHCI driver doesn&#8217;t  have these small workaround features that a usual xHCI driver has for getting unstuck from protocol bug deadlocks, and it doesn&#8217;t  attempt to smooth protocol errors. Which makes sense: A regular xHCI  driver&#8217;s goal is to make the device work. The test driver is there to  expose errors, so it should get stuck when things are done wrong. Hence it may expose bugs that were smoothed out when  the device was connected in a regular manner to a computer. For example,  a bug in the device&#8217;s LTSSM implementation may be smoothed out by a  regular driver by issuing a warm reset and starting all over again,  without any log message, but USB3CV&#8217;s driver will just fail.</p>
<p>So if weird stuff happens with USB3CV, check your own implementation, and don&#8217;t look for bugs in USB3CV. Reject the immediate &#8220;but it worked before&#8221; instinct to blame something else than your own design.</p>
<h3>Hands on</h3>
<p>Double-click the USB 3 Gen X CV icon. A dialog box with a list of USB controller(s) opens. Select the one that the device is attached to. All other USB devices on that controller, of all speeds, will be disconnected from the computer. Then the &#8220;Command Verifier&#8221; asks to verify this choice. If you just disabled your own mouse and keyboard you can&#8217;t click &#8220;Continue&#8221;, and that dialog box will time out, and the hijacked USB controller is released.</p>
<p>Then the main windows opens. Select &#8220;Chapter 9 Tests (USB 3 Gen X devices)&#8221;, Compliance Test (or Debug for individual tests), and click Run.</p>
<p>This is when USB3CV tries to find devices on the hijacked USB controller (it&#8217;s complete silence on wires until then). Sometimes this fails for no apparent reason &#8212; see below. A dialog box asking to select the device to work with appears, and is then followed by three dialog boxes asking for the number of retimers. If you don&#8217;t know what it&#8217;s about, you don&#8217;t have any, so select zero on all three.</p>
<p>When tests fail, the error messages may be misleading. For example, a problem with the device&#8217;s LTSSM made the GetDecriptor() test fail, spitting out the paragraphs in the spec that aren&#8217;t met, but on the wires there was no related SETUP packet sent (because the link wasn&#8217;t up, it turned out eventually). However the SET_SEL test went through OK nevertheless. So it may be really confusing.  This is easily mistaken for a bug in USB3CV.</p>
<p>Even worse, it seems like a test failure can lead to all kind of unexpected and unrelated errors in following tests.</p>
<p>The tool also complains when the device declares itself as USB 3.0 in the device descriptor rather than USB 3.2, considering it to be a test failure. What about USB 3.0 devices, not supporting anything related to SuperSpeedPlus? Why should they even mention USB 3.2?</p>
<h3>When things get stuck</h3>
<p>If weird things happen (in particular if the device isn&#8217;t found by USB3CV and/or otherwise) re-run USB3CV and exit it, so the original xHCI controller is brought back upon exit. That&#8217;s what USB3CV expects to see on invocation, and it doesn&#8217;t work properly otherwise. So just run the tool and exit immediately, and then run it again.</p>
<p>It&#8217;s better to start USB3CV with the device already plugged in. Moving it to another plug while USB3CV is running often helps.</p>
<h3>Crashes</h3>
<p>Unfortunately, USB3CV crashes quite a lot (mostly in relation with test failures, in particular failing tests related to low power states). The &#8220;Command Verifier Tool has stopped working&#8221; dialog box may appear. A rather ironic workaround seems to work: Clicking &#8220;Abort&#8221; as the tests run (towards the end, actually), and then clicking &#8220;No&#8221;, a bit before the end of the tests, in the dialog box asking if you really want to abort (so the test isn&#8217;t aborted, after all). Sometimes the enumeration test is done, sometimes it isn&#8217;t (and fails with some ugly error), so maybe that&#8217;s related.</p>
<p>Sometimes USB3CV just gets stuck in a test, and attempting abort the test doesn&#8217;t help. Closing the USB3CV windows brings up &#8220;Wait for a stack switch&#8221; after which Windows crashes with a &#8220;Your PC ran into a problem and needs to restart. You can restart&#8221;. Which probably means that it&#8217;s OK to recycle power (no other possibility left). Windows suggest searching online for &#8220;WDF_VIOLATION&#8221; too.</p>
<p>Whether the power recycle took place or not, USB3CV didn&#8217;t have the opportunity to return the original xHCI driver as it usually does upon a normal exit. Therefore, be sure to invoke and exit USB3CV as mentioned above to get the system back to its original state.</p>
]]></content:encoded>
			<wfw:commentRss>https://billauer.se/blog/2019/06/usb-if-compliance-test/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>+5V voltage feed on HDMI cables and a failing HDMI2AV converter</title>
		<link>https://billauer.se/blog/2017/12/hdmi-dvi-cable-hdmi2av/</link>
		<comments>https://billauer.se/blog/2017/12/hdmi-dvi-cable-hdmi2av/#comments</comments>
		<pubDate>Sat, 09 Dec 2017 11:44:42 +0000</pubDate>
		<dc:creator>eli</dc:creator>
				<category><![CDATA[electronics]]></category>
		<category><![CDATA[miscellaneous]]></category>

		<guid isPermaLink="false">https://billauer.se/blog/?p=5329</guid>
		<description><![CDATA[After quite a while of working perfectly well, the mini HDMI2AV module I have (in the picture above, mentioned in this post) started producing an unstable picture, and in the end a completely garbled one. It took some time to nail down this specific component in the foodchain, because there was also an HDMI splitter [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://billauer.se/blog/wp-content/uploads/2017/03/hdmi2av.jpg"><img class="aligncenter size-medium wp-image-5139" title="HDMI to AV converter  (Composite Video + Audio on RCA plugs)" src="https://billauer.se/blog/wp-content/uploads/2017/03/hdmi2av-300x240.jpg" alt="HDMI to AV converter (Composite Video + Audio on RCA plugs)" width="300" height="240" /></a></p>
<p>After quite a while of working perfectly well, the mini HDMI2AV module I have (in the picture above, mentioned in <a href="https://billauer.se/blog/2017/03/edid-hdmi2av-rca-cvbs/" target="_blank">this post</a>) started producing an unstable picture, and in the end a completely garbled one. It took some time to nail down this specific component in the foodchain, because there was also an HDMI splitter involved.</p>
<p>The problem, as it turned out, was that this module takes voltage from the HDMI plug, if such is available, instead of the dedicated power plug. In my specific setup, it seems like there was some voltage was available, but not enough to drive the device &#8212; because the HDMI plug was connected to the HDMI splitter. I suppose some internal power supply switch went into some not-here-not-there kind of situation, and eventually got some permanent damage. The other HDMI2AV unit I have didn&#8217;t work either in the same conditions, but probably didn&#8217;t reach the point of permanent damage (so it&#8217;s working right now).</p>
<p>On an HDMI connector, Pin 18 is +5V, minimum 55 mA, intended originally to feed the monitor with voltage even if it&#8217;s shut off, so its DDC (EDID) information can be obtained. Some devices (e.g. cheap HDMI splitters and HDMI to AV converters) might use this voltage instead of the supplied external voltage in some cases.</p>
<p><a href="https://billauer.se/blog/wp-content/uploads/2017/12/HDMI-connector.png"><img class="aligncenter size-medium wp-image-5330" title="HDMI connector pinout" src="https://billauer.se/blog/wp-content/uploads/2017/12/HDMI-connector-300x123.png" alt="HDMI connector pinout" width="300" height="123" /></a>Not all cables conduct this pin. It&#8217;s therefore advisable to check the cable before working with it, when the setup is more than just a direct connection. It&#8217;s not easy, even with a multimeter. Pushing a thin wire into the tiny holes at the front may give contact with the relevant pin, but this isn&#8217;t bulletproof. Possibly try with an HDMI/DVI adapter (pin 14 on a DVI connector is +5V). Or test with a device that is known to rely on this voltage (e.g. this HDMI2AV module).</p>
<p>The solution in my case was to replace the HDMI2AV module and all cables with such that don&#8217;t let the +5V wire through. In particular, it seems like the cable to the TV set (via HDMI) that went to the HDMI splitter (which connects to the HDMI2AV module on its other output) was the issue.</p>
]]></content:encoded>
			<wfw:commentRss>https://billauer.se/blog/2017/12/hdmi-dvi-cable-hdmi2av/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>EDID info from mini HDMI2AV module (HDMI to RCA CVBS)</title>
		<link>https://billauer.se/blog/2017/03/edid-hdmi2av-rca-cvbs/</link>
		<comments>https://billauer.se/blog/2017/03/edid-hdmi2av-rca-cvbs/#comments</comments>
		<pubDate>Sun, 12 Mar 2017 06:42:59 +0000</pubDate>
		<dc:creator>eli</dc:creator>
				<category><![CDATA[DVB]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">https://billauer.se/blog/?p=5138</guid>
		<description><![CDATA[This is the information obtained with xrandr from the HDMI to AV converter  (Composite Video + Audio on RCA plugs) shown above: Screen 0: minimum 8 x 8, current 1280 x 720, maximum 32767 x 32767 DP1 disconnected (normal left inverted right x axis y axis) DP2 disconnected (normal left inverted right x axis y [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://billauer.se/blog/wp-content/uploads/2017/03/hdmi2av.jpg"><img class="aligncenter size-medium wp-image-5139" title="HDMI to AV converter  (Composite Video + Audio on RCA plugs)" src="https://billauer.se/blog/wp-content/uploads/2017/03/hdmi2av-300x240.jpg" alt="HDMI to AV converter (Composite Video + Audio on RCA plugs)" width="300" height="240" /></a></p>
<p>This is the information obtained with xrandr from the HDMI to AV converter  (Composite Video + Audio on RCA plugs) shown above:</p>
<pre>Screen 0: minimum 8 x 8, current 1280 x 720, maximum 32767 x 32767
DP1 disconnected (normal left inverted right x axis y axis)
DP2 disconnected (normal left inverted right x axis y axis)
DP3 disconnected (normal left inverted right x axis y axis)
HDMI1 disconnected (normal left inverted right x axis y axis)
HDMI2 disconnected (normal left inverted right x axis y axis)
HDMI3 connected primary 1280x720+0+0 (normal left inverted right x axis y axis) 708mm x 398mm
 1280x720      60.00*+  59.94 
 1920x1080     60.00    59.94 
 1600x1200     60.00 
 1680x1050     59.88 
 1400x1050     59.95 
 1600x900      60.00 
 1280x1024     60.02 
 1440x900      59.90 
 1280x960      60.00 
 1280x800      59.91 
 1024x768      60.00 
 800x600       60.32 
 720x480       60.00    59.94 
 640x480       60.00    59.94 
VIRTUAL1 disconnected (normal left inverted right x axis y axis)</pre>
<p>And with &#8220;verbose&#8221; flag:</p>
<pre>Screen 0: minimum 8 x 8, current 1280 x 720, maximum 32767 x 32767
DP1 disconnected (normal left inverted right x axis y axis)
 Identifier: 0x43
 Timestamp:  919743
 Subpixel:   unknown
 Clones:   
 CRTCs:      1 2
 Transform:  1.000000 0.000000 0.000000
 0.000000 1.000000 0.000000
 0.000000 0.000000 1.000000
 filter:
 Broadcast RGB: Automatic
 supported: Automatic, Full, Limited 16:235
 audio: auto
 supported: force-dvi, off, auto, on
DP2 disconnected (normal left inverted right x axis y axis)
 Identifier: 0x44
 Timestamp:  919743
 Subpixel:   unknown
 Clones:   
 CRTCs:      1 2
 Transform:  1.000000 0.000000 0.000000
 0.000000 1.000000 0.000000
 0.000000 0.000000 1.000000
 filter:
 Broadcast RGB: Automatic
 supported: Automatic, Full, Limited 16:235
 audio: auto
 supported: force-dvi, off, auto, on
DP3 disconnected (normal left inverted right x axis y axis)
 Identifier: 0x45
 Timestamp:  919743
 Subpixel:   unknown
 Clones:   
 CRTCs:      0
 Transform:  1.000000 0.000000 0.000000
 0.000000 1.000000 0.000000
 0.000000 0.000000 1.000000
 filter:
 Broadcast RGB: Automatic
 supported: Automatic, Full, Limited 16:235
 audio: auto
 supported: force-dvi, off, auto, on
HDMI1 disconnected (normal left inverted right x axis y axis)
 Identifier: 0x46
 Timestamp:  919743
 Subpixel:   unknown
 Clones:   
 CRTCs:      1 2
 Transform:  1.000000 0.000000 0.000000
 0.000000 1.000000 0.000000
 0.000000 0.000000 1.000000
 filter:
 aspect ratio: Automatic
 supported: Automatic, 4:3, 16:9
 Broadcast RGB: Automatic
 supported: Automatic, Full, Limited 16:235
 audio: auto
 supported: force-dvi, off, auto, on
HDMI2 disconnected (normal left inverted right x axis y axis)
 Identifier: 0x47
 Timestamp:  919743
 Subpixel:   unknown
 Clones:   
 CRTCs:      1 2
 Transform:  1.000000 0.000000 0.000000
 0.000000 1.000000 0.000000
 0.000000 0.000000 1.000000
 filter:
 aspect ratio: Automatic
 supported: Automatic, 4:3, 16:9
 Broadcast RGB: Automatic
 supported: Automatic, Full, Limited 16:235
 audio: auto
 supported: force-dvi, off, auto, on
HDMI3 connected primary 1280x720+0+0 (0x11d) normal (normal left inverted right x axis y axis) 708mm x 398mm
 Identifier: 0x48
 Timestamp:  919743
 Subpixel:   unknown
 Gamma:      1.0:1.0:1.0
 Brightness: 1.0
 Clones:   
 CRTC:       0
 CRTCs:      0
 Transform:  1.000000 0.000000 0.000000
 0.000000 1.000000 0.000000
 0.000000 0.000000 1.000000
 filter:
 EDID:
 00ffffffffffff00328d000000000000
 2d170103e87341782aee91a3544c9926
 0f505421080081008140818090409500
 a9c0b300a940011d007251d01e206e28
 5500c48e2100001ef339801871382d40
 582c4500c48e2100001e000000fd001e
 551e6414000a202020202020000000fc
 0048444d493241560a202020002001d6
 02031841458403020110230907078301
 000065030c001000011d007251d01e20
 6e28550010090000001e011d007251d0
 1e206e28550010090000001e8c0ad08a
 20e02d10103e96001009000000180000
 00000000000000000000000000000000
 00000000000000000000000000000000
 0000000000000000000000000000001d
 aspect ratio: Automatic
 supported: Automatic, 4:3, 16:9
 Broadcast RGB: Automatic
 supported: Automatic, Full, Limited 16:235
 audio: auto
 supported: force-dvi, off, auto, on
 1280x720 (0x11d) 74.250MHz +HSync +VSync *current +preferred
 h: width  1280 start 1390 end 1430 total 1650 skew    0 clock  45.00KHz
 v: height  720 start  725 end  730 total  750           clock  60.00Hz
 1920x1080 (0x4b) 148.500MHz +HSync +VSync
 h: width  1920 start 2008 end 2052 total 2200 skew    0 clock  67.50KHz
 v: height 1080 start 1084 end 1089 total 1125           clock  60.00Hz
 1920x1080 (0x10b) 148.352MHz +HSync +VSync
 h: width  1920 start 2008 end 2052 total 2200 skew    0 clock  67.43KHz
 v: height 1080 start 1084 end 1089 total 1125           clock  59.94Hz
 1600x1200 (0x114) 162.000MHz +HSync +VSync
 h: width  1600 start 1664 end 1856 total 2160 skew    0 clock  75.00KHz
 v: height 1200 start 1201 end 1204 total 1250           clock  60.00Hz
 1680x1050 (0x115) 119.000MHz +HSync -VSync
 h: width  1680 start 1728 end 1760 total 1840 skew    0 clock  64.67KHz
 v: height 1050 start 1053 end 1059 total 1080           clock  59.88Hz
 1400x1050 (0x13b) 101.000MHz +HSync -VSync
 h: width  1400 start 1448 end 1480 total 1560 skew    0 clock  64.74KHz
 v: height 1050 start 1053 end 1057 total 1080           clock  59.95Hz
 1600x900 (0x13c) 108.000MHz +HSync +VSync
 h: width  1600 start 1624 end 1704 total 1800 skew    0 clock  60.00KHz
 v: height  900 start  901 end  904 total 1000           clock  60.00Hz
 1280x1024 (0x117) 108.000MHz +HSync +VSync
 h: width  1280 start 1328 end 1440 total 1688 skew    0 clock  63.98KHz
 v: height 1024 start 1025 end 1028 total 1066           clock  60.02Hz
 1440x900 (0x119) 88.750MHz +HSync -VSync
 h: width  1440 start 1488 end 1520 total 1600 skew    0 clock  55.47KHz
 v: height  900 start  903 end  909 total  926           clock  59.90Hz
 1280x960 (0x11a) 108.000MHz +HSync +VSync
 h: width  1280 start 1376 end 1488 total 1800 skew    0 clock  60.00KHz
 v: height  960 start  961 end  964 total 1000           clock  60.00Hz
 1280x800 (0x11b) 71.000MHz +HSync -VSync
 h: width  1280 start 1328 end 1360 total 1440 skew    0 clock  49.31KHz
 v: height  800 start  803 end  809 total  823           clock  59.91Hz
 1280x720 (0x11f) 74.176MHz +HSync +VSync
 h: width  1280 start 1390 end 1430 total 1650 skew    0 clock  44.96KHz
 v: height  720 start  725 end  730 total  750           clock  59.94Hz
 1024x768 (0x122) 65.000MHz -HSync -VSync
 h: width  1024 start 1048 end 1184 total 1344 skew    0 clock  48.36KHz
 v: height  768 start  771 end  777 total  806           clock  60.00Hz
 800x600 (0x126) 40.000MHz +HSync +VSync
 h: width   800 start  840 end  968 total 1056 skew    0 clock  37.88KHz
 v: height  600 start  601 end  605 total  628           clock  60.32Hz
 720x480 (0x129) 27.027MHz -HSync -VSync
 h: width   720 start  736 end  798 total  858 skew    0 clock  31.50KHz
 v: height  480 start  489 end  495 total  525           clock  60.00Hz
 720x480 (0x12a) 27.000MHz -HSync -VSync
 h: width   720 start  736 end  798 total  858 skew    0 clock  31.47KHz
 v: height  480 start  489 end  495 total  525           clock  59.94Hz
 640x480 (0x12e) 25.200MHz -HSync -VSync
 h: width   640 start  656 end  752 total  800 skew    0 clock  31.50KHz
 v: height  480 start  490 end  492 total  525           clock  60.00Hz
 640x480 (0x12f) 25.175MHz -HSync -VSync
 h: width   640 start  656 end  752 total  800 skew    0 clock  31.47KHz
 v: height  480 start  490 end  492 total  525           clock  59.94Hz
VIRTUAL1 disconnected (normal left inverted right x axis y axis)
 Identifier: 0x49
 Timestamp:  919743
 Subpixel:   no subpixels
 Clones:   
 CRTCs:      3
 Transform:  1.000000 0.000000 0.000000
 0.000000 1.000000 0.000000
 0.000000 0.000000 1.000000
 filter:</pre>
<p>This was done with the switch in &#8220;PAL&#8221; position, but I&#8217;m not sure it matters.</p>
]]></content:encoded>
			<wfw:commentRss>https://billauer.se/blog/2017/03/edid-hdmi2av-rca-cvbs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hierarchies in Orcad schematics: Please, don&#8217;t</title>
		<link>https://billauer.se/blog/2015/12/orcad-pcb-hierarchy/</link>
		<comments>https://billauer.se/blog/2015/12/orcad-pcb-hierarchy/#comments</comments>
		<pubDate>Thu, 10 Dec 2015 06:40:17 +0000</pubDate>
		<dc:creator>eli</dc:creator>
				<category><![CDATA[electronics]]></category>

		<guid isPermaLink="false">https://billauer.se/blog/?p=4868</guid>
		<description><![CDATA[It seems like hierarchies are to board designers what C++ is to programmers: It kills the boredom, but also the project. They will proudly show you their block diagrams and the oh-so-ordered structure, but in the end of the day, noone can really figure out what&#8217;s connected to what. Which is kinda important in a [...]]]></description>
			<content:encoded><![CDATA[<p>It seems like hierarchies are to board designers what C++ is to programmers: It kills the boredom, but also the project. They will proudly show you their block diagrams and the oh-so-ordered structure, but in the end of the day, noone can really figure out what&#8217;s connected to what. Which is kinda important in a PCB design.</p>
<p>Not to mention that it&#8217;s impossible to tell what&#8217;s going on looking at the pdf schematics: Try to search for the net&#8217;s name, and you&#8217;ll find it in 20 places, 18 of which are the inter-hierarchy connections of that net. One of which, is maybe wrong, but is virtually impossible to spot.</p>
<p>On a good day, everything looks fine and in order, and noone notices small killers like the one below. It&#8217;s easy (?) to spot it now that I&#8217;ve put the focus on it, but would you really see this on page 23 of yet another block connection in the schematics?</p>
<p>Click to enlarge (this is from a real-life design made by a serious company):</p>
<p><a href="https://billauer.se/blog/wp-content/uploads/2015/12/hierarchy.png" target="_blank"><img class="aligncenter size-medium wp-image-4869" title="Example of ORCAD schematics hierarchy design going horribly wrong" src="https://billauer.se/blog/wp-content/uploads/2015/12/hierarchy-300x166.png" alt="Example of ORCAD schematics hierarchy design going horribly wrong" width="300" height="166" /></a>So please, PCB designers, wherever you are: Look at any reference design you can find, and do the same: Just put the net names that belong to another page. Don&#8217;t try to show the connections between the blocks. They help nobody. If the net name is meaningful, we will all understand on which page to look for it. And if we don&#8217;t, we use our pdf browser&#8217;s search feature. Really.</p>
]]></content:encoded>
			<wfw:commentRss>https://billauer.se/blog/2015/12/orcad-pcb-hierarchy/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>When TI&#8217;s CDCE62002 fails to lock</title>
		<link>https://billauer.se/blog/2010/10/cdce62002-pll-vco-registers-ram-eeprom/</link>
		<comments>https://billauer.se/blog/2010/10/cdce62002-pll-vco-registers-ram-eeprom/#comments</comments>
		<pubDate>Tue, 05 Oct 2010 21:51:48 +0000</pubDate>
		<dc:creator>eli</dc:creator>
				<category><![CDATA[electronics]]></category>
		<category><![CDATA[FPGA]]></category>

		<guid isPermaLink="false">https://billauer.se/blog/?p=725</guid>
		<description><![CDATA[I really banged my head on this one: I was sure I had set up all registers correctly, and still I got complete garbage at the output. Or, as some investigation showed, everything worked OK, only the PLL didn&#8217;t seem to do anything: The VCO was stuck at its lowest possible frequency (which depended on [...]]]></description>
			<content:encoded><![CDATA[<p>I really banged my head on this one: I was sure I had set up all registers correctly, and still I got complete garbage at the output. Or, as some investigation showed, everything worked OK, only the PLL didn&#8217;t seem to do anything: The VCO was stuck at its lowest possible frequency (which depended on whether I picked the one for higher or lower frequencies).</p>
<p>At first I thought that there was something wrong with my reference clock. But it was OK.</p>
<p>Only after a while did I realize that the PLL needs to be recalibrated <strong>after </strong>the registers are set. The CDCE62002 wasn&#8217;t intended to be programmed after powerup, like the CDCE906. The by-design use is to program the EEPROM once, and then power it up. Doing it this way, the correct values go into the RAM from EEPROM, after which calibration takes place with the correct parameters.</p>
<p>Solution: Power down the device by clearing bit 7 in register #2, write the desired values in registers #0 and #1, and then power up again by setting bit 7 (and and bit 8, regardless) in register #2. This way the device wakes up as is the registers were loaded from EEPROM, and runs its calibration routine correctly.</p>
<p>What I still don&#8217;t understand, is why I have to do this twice. The VCO seems to go to its highest frequency now, unless I repeat the ritual mentioned above again 100 ms after the first time. If I do this within microseconds it&#8217;s no good.</p>
<p>I&#8217;ve written a Verilog module to handle this. Basically, send_data should be asserted during one clock cycle, and the parameter inputs should be held steady for some 256 clock cycles afterwards. As I&#8217;m using this module, there are constant values there.</p>
<p>This is not an example of best Verilog coding techniques, but since I didn&#8217;t care about either slice count or timing here, I went for the quickest solution, even if it&#8217;s a bit dirty. And it works.</p>
<p>Note that the module&#8217;s clock frequency should not exceed 40 MHz, since the maximal SPI clock allowed by spec is 20 MHz. And again, for this to really work, send_data has to be asserted twice, with some 100 ms or so between assertions. I&#8217;ll check with TI about this.</p>
<pre>module cdce62002
  (
   input          clk, // Maximum 40 MHz
   input 	  reset, // Active high

   output 	  busy,

   input          send_data,
   output reg     spi_clk, spi_le, spi_mosi,
   input          spi_miso,  // Never used

   // The names below match those used in pages 22-24 of the datasheet

   input  INBUFSELX,
   input  INBUFSELY,
   input  REFSEL,
   input  AUXSEL,
   input  ACDCSEL,
   input  TERMSEL,
   input [3:0]  REFDIVIDE,
   input [1:0]  LOCKW,
   input [3:0]  OUT0DIVRSEL,
   input [3:0]  OUT1DIVRSEL,
   input   HIPERFORMANCE,
   input   OUTBUFSEL0X,
   input   OUTBUFSEL0Y,
   input   OUTBUFSEL1X,
   input   OUTBUFSEL1Y,

   input  SELVCO,
   input [7:0]  SELINDIV,
   input [1:0]  SELPRESC,
   input [7:0]  SELFBDIV,
   input [2:0]  SELBPDIV,
   input [3:0]  LFRCSEL
   );

   reg [7:0] 	  out_pointer;
   reg 		  active;

   wire [255:0]   data_out;
   wire [255:0]   le_out;
   wire [27:0] 	  word0, word1, word2, word3;
   wire [27:0] 	  ones = 28'hfff_ffff;

   // synthesis attribute IOB of spi_clk is true;
   // synthesis attribute IOB of spi_le is true;
   // synthesis attribute IOB of spi_mosi is true;

   // synthesis attribute init of out_pointer is 0 ;
   // synthesis attribute init of active is 0 ;
   // synthesis attribute init of spi_le is 1;

   assign 	  busy = (out_pointer != 0);

   // "active" is necessary because we don't rely on getting a proper
   // reset signal, and out_pointer is subject to munching by the
   // synthesizer, which may result in nasty things during wakeup

   always @(posedge clk or posedge reset)
     if (reset)
       begin
	  out_pointer &lt;= 0;
	  active &lt;= 0;
       end
     else if (send_data)
       begin
	  out_pointer &lt;= 1;
	  active &lt;= 1;
       end
     else if ((spi_clk) &amp;&amp; busy)
       out_pointer &lt;= out_pointer + 1;

   always @(posedge clk)
     begin
	if (spi_clk)
	  begin
	     spi_mosi &lt;= data_out[out_pointer];
	     spi_le &lt;= !(le_out[out_pointer] &amp;&amp; active);
	  end
	spi_clk &lt;= !spi_clk;
     end 

   assign data_out = { word3, 4'd2, 2'd0, // To register #2 again.
		       64'd0, // Dwell a bit in power down
		       word1, 4'd1, 2'd0,
		       word0, 4'd0, 2'd0,
		       word2, 4'd2, 4'd0
		       };

   assign le_out = { ones[27:0], ones[3:0], 2'd0,
		     64'd0, // Dwell a bit in power down
		     ones[27:0], ones[3:0], 2'd0,
		     ones[27:0], ones[3:0], 2'd0,
		     ones[27:0], ones[3:0], 4'd0 };

   assign word0[0] = INBUFSELX;
   assign word0[1] = INBUFSELY;
   assign word0[2] = REFSEL;
   assign word0[3] = AUXSEL;
   assign word0[4] = ACDCSEL;
   assign word0[5] = TERMSEL;
   assign word0[9:6] = REFDIVIDE;
   assign word0[10] = 0; // TI trashed external feedback
   assign word0[12:11] = 0; // TI's test bits
   assign word0[14:13] = LOCKW;
   assign word0[18:15] = OUT0DIVRSEL;
   assign word0[22:19] = OUT1DIVRSEL;
   assign word0[23] = HIPERFORMANCE;
   assign word0[24] = OUTBUFSEL0X;
   assign word0[25] = OUTBUFSEL0Y;
   assign word0[26] = OUTBUFSEL1X;
   assign word0[27] = OUTBUFSEL1Y;

   assign word1[0] = SELVCO;
   assign word1[8:1] = SELINDIV;
   assign word1[10:9] = SELPRESC;
   assign word1[18:11] = SELFBDIV;
   assign word1[21:19] = SELBPDIV;
   assign word1[25:22] = LFRCSEL;
   assign word1[27:26] = 2'b10; // Read only bits   

   // word2 and word3 are both sent to register #2 in order to
   // restart the PLL calibration after registers are set.

   assign word2 = 28'h000_0100; // Power down
   assign word3 = 28'h000_0180; // Exit powerdown
endmodule</pre>
]]></content:encoded>
			<wfw:commentRss>https://billauer.se/blog/2010/10/cdce62002-pll-vco-registers-ram-eeprom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
