|
|
|
Write your own PCB design rule checker |
|
|
Luke L. Chang
(09/05/2003 2:34 PM EDT) URL: http://www.eetimes.com/showArticle.jhtml?articleID=164900383 |
|
|
1.0 Introduction
This paper presents a systematic approach to writing a design rule checker (DRC) for PCB design. After a PCB design is captured in a schematic tool, a DRC must be run to find any design rule violations. This must be done before backend processing starts. Usually, the vendor of the schematics tool provides a DRC and most designers simply just use that.
However, vendor tools are general-purpose and may not always be flexible enough to handle certain unique requirements. Requests for new features to be added into the DRC may be sent to the vendor, but that would cost money and time, especially if this has to be done more than once. Fortunately, most tool vendors provide easy-to-use mechanisms for you to write your own DRC to better meet your unique requirements. Unfortunately, this powerful tool has not been widely recognized or utilized. In this paper, we provide some practical guidance on how to utilize it to your fullest benefit.
Because a DRC must walk through the entire schematics of a PCB design, including every symbol, every pin, every net, and every attribute, an unlimited number of useful "by-products" can be generated, if necessary. As Section 4.0 explains, they may very well flag subtle design rule violations. For example, one by-product file could contain all decoupling capacitors found in the design. If the number is much smaller or bigger than expected, this can raise a red flag for possible power line dv/dt problems [1]. These by-product files may very well be required, but they are definitely not generated by any commercially available DRC.
Another benefit of this DRC is that it can be easily and quickly updated to accommodate new design features, such as new attributes that affect design rules. Also, once enough experience has been gained in this area, then many other possibilities will present themselves.
For example, if you can write your own DRC, you can certainly write your own Bill of Material (BOM) generation tool, which again can better handle certain unique requirements, such as where to pick up a component's "extra hardware" (sockets, heat sinks, or screws) that is not part of the schematics database. Or you can write your own Verilog netlister that is flexible enough for your design environment, such as where to pick up the Verilog models or timing files for certain unique components. As a matter of fact, as the DRC walks through the design schematics, it can collect all necessary information to output a Verilog netlist for simulation and/or a BOM for PCB manufacturing.
It would be difficult to discuss these topics without providing some programming code. To do that, we need to use a schematics capturing tool as an example. In this paper, we use ViewDraw from Mentor Graphics, which is part of the PADS-Designer product line. In addition, we use ViewBase, which is simply a library of C routines that one can call to access the ViewDraw database. With ViewBase, you can easily write a complete and useful DRC in C/C++ [2] [3] for ViewDraw. Note that the principles that we discuss here are applicable to any other PCB schematics tool.
2.0 Starting out
2.0.1 Input Files
legal_pwr_net_name is optional because the configuration file of the backend packaging utility usually must contain the list of legal power/ground net names. If Allegro from Cadence Design Systems is the placement/layout tool, this file is called allegro.cfg for pcbfwd and it must have entries like these:
Grounds VSS CGND GND GROUND
It would be better (less chance of introducing errors) if the DRC can directly read allegro.cfg instead of legal_pwr_net_name.
Normally, power/ground pins are not brought out on a component symbol. Instead, the symbol has an attribute (which could be called SIGNAL) that specifies which pin is power or ground and specifies the name of the net this pin should be connected to:
SIGNAL = VCC:10
DRC can read this attribute and make sure that the net name is one found in the legal_pwr_net_name file. If not, this power pin will not be connected to the power plane, and this is a very serious error.
Some symbols must have the power/ground pins brought out, because they are not connected to normal power/ground plane. For example, an ECL part's VCC pin can be connected to either VCC or to GROUND; its VEE pin can be connected either to GROUND or to -5.0V plane. Also, a power/ground pin can be connected to a filter first before going to power/ground plane.
The net between this pin and the filter can have any name and DRC will have difficulty checking this. DRC can report this as an error and the user must screen it out, or add the net name to legal_pwr_net_name file only for this design. This is one reason that a file like legal_pwr_net_name may be required. Finally, legal_pwr_net_name will be read in by DRC to 1) find pull-up resistors, 2) check for the letter case of POWER net names in the design, and 3) detect any unused pins directly tied to POWER.
legal_gnd_net_name serves the same purpose as legal_pwr_net_name discussed above. In addition, it will be read in by DRC to 1) find pull-down resistors, 2) check for the letter case of GROUND net names, and 3) detect any unused pins directly tied to GROUND.
legal_lib_path_name is optional because for most schematics tools the library information is contained in an initialization file required for bringing up that tool. For ViewDraw, the file is called viewdraw.ini and is automatically created (by a script) when the tool is brought up. A library specification entry looks like:
DIR [r] /corp_lib/pcb/symbol_libraries/viewdraw/fct (fct)
fct is one of the many ViewDraw's sub-libraries from where symbols for fct (fast CMOS technology) parts can come. DRC can and should directly read this initialization file, if it exists, because new libraries can be added on the fly by the designer.
2.0.2 Design directory structure
A second condition for DRC to run is a fixed, single design directory structure that is shared by all PCB designs. Without it, DRC would not know where to find the schematics database and where to store the output files. This structure can be very complex and have many hierarchical levels in order to support all PCB design activities, such as design rule checking, BOM generation, Verilog simulation, static timing analysis, signal integrity analysis, placement/layout, PAL/FPGA design (synthesis and simulation), and document control. But for DRC alone, the following is sufficient, if ViewDraw is used:
Figure 1 -- Directory structure
The pcb_info directory should contain at least two files. The first is design_def and the other design_type. design_def should contain the PCB part (assembly) number and other required information, not just for DRC but for all other tools. design_type should contain design type information, which is PCB. If this design directory structure is shared by other types of design, such as ASIC or FPGA, then design_type should specify it so that design automation tools can take appropriate actions for different design types. If pcb_info directory is missing or empty, this means the design directory is not a standard one. In that case, DRC should exit and give an error message.
The schem directory contains the schematics database and is accessed directly by ViewBase, which our DRC uses. The sch sub-directory contains schematic files that describe symbol locations on a sheet and other information. The wir sub-directory contains the netlist of the design and all symbol attributes. ViewBase routines can access them directly.
The drc directory should store DRC's output files.
3.0 A PCB DRC
3.0.1 The wrapper program
sort +1n source_file > sorted_file
3.0.2 DRC development: the main() function
drc.c should first include all the C, ViewBase and user created header files, such as stdio.h, viewbase.h and hash_table.h. Now set up drc.c to receive input arguments, to declare variables and file pointers to both input and output files, to have ViewBase point to the ViewDraw database, and to create linked lists and hash tables to store the information read in from input files. A portion of its main() function is given below.
The input and output file names and the PCB design name are fed in by DRC's wrapper program (see Section 3.0.1) when it invokes the DRC. Data structures Str_list_elem and Hash_table are defined in the header files included by drc.c. GROUPS is a ViewBase data type.
Next, the main() function should make sure correct number of inputs are passed in by checking whether argc is equal to the expected number. If yes, assign input arguments to the variables:
At this time, main() function can initialize ViewBase data structures and make ViewBase pointer pcb_ptr point to the PCB design. If the design exists and is valid, then main() function should:
An outline of the C and ViewBase code inside main() that does this is:
Here, iwinit() and iw1level() are ViewBase routines. The former initializes all loader routines and it is required. The latter loads one level of the PCB design (the entire design). To load just one sheet, use the iw1sheet() routine (which is not used in our DRC). Note that correct design pointers, file pointers, linked lists, variable names, etc., must be passed into drc_net() and drc_inst() functions:
drc_inst(pcb_ptr, pcb_name, drc_error, list_legal_pwr_name, ...);
If your design is hierarchical and uses heterogeneous component symbols, then make sure DRC can handle them properly.
3.0.3 DRC development: the drc_net() function
Here, iggrpnet() and ignetnxt() are ViewBase routines for grabbing every net in the PCB design. ignetnam() is also a ViewBase routine for finding the name of a net. NETS, PINS, COMPONENTS, SYMBOLS, and ATTRIBUTES are ViewBase data types. drc_net() can look for the following design rule violations:
drc_net() should call a function legal_net_name() to perform this task. Regular expression matching/checking in C is greatly simplified in UNIX by the regexp.h header file, which must be included in the DRC program. drc_net() should pass the net name variable and the design rule violation file pointer into legal_net_name(), which looks like:
The backend packaging tool pcbfwd can also check for illegal net names, but its ability is limited to simple regular expressions. The code given above can handle just about any regular expression. Also, whether to find illegal net names before or after running pcbfwd is a trade-off issue. For simple net names, use pcbfwd.
Here, ignetpin() and igpinnnx() are ViewBase routines that grab each pin on a net. igpinown() routine returns pointer to the pin's instance (owner). Functions get_inst_attr(), get_pin_attr() and get_sheet_num() return the requested instance attribute (reference designator REFDES), pin attribute (PINTYPE) and sheet number the pin's instance is on, respectively. The outline of the get_pin_attr() function is given below:
The outline of the get_inst_attr() function is given below:
The outline of the get_sheet_num() function is given below:
3.0.4 DRC development: the drc_inst() function
Our previous discussion of the drc_net() function provides ample C and ViewBase code examples, which will not be repeated here. Below is a partial list of design rule violations that drc_inst() can check:
3.0.5 What DRC should not do
There is an overlap between what DRC and pcbfwd can check, and it is a trade-off issue to decide when to check what. DRC is usually run right after the design is completed and before pcbfwd is run. Ideally, pcbfwd should be run only to package the design, so the more DRC can check the better. But you should balance the efforts in developing a super powerful DRC with pcbfwd's existing capabilities that come for free. This section briefly discusses these issues.
pcbfwd is controlled by its configuration file, which is called allegro.cfg, if Allegro is the placement/layout tool. Its BeginChkRules - EndChkRules section can be used to check many errors, such as duplicate attribute on the same symbol, illegal net and net attribute names, bad heterogeneous package, conflicting attributes on heterogeneous symbols, and missing attributes. For example, to catch conflicting attributes on heterogeneous symbols, put the following line into allegro.cfg:
CHKBRD _HETERO_ATT ERR 0
There are things that neither DRC nor pcbfwd can check, such as intended redundancy in PCB designs. Suppose a component contains 4 identical parts and 2 are used on a design, then they can either be packaged into the same component or into 2 components for redundancy. If one component is required, symbols for both parts must have the same reference designator, such as U4. If 2 components are required, then the symbols must have different reference designators, such as U4 and U5, which must be conscientiously added by the designer. There is no known easy way to catch errors of this kind and a careful designer is probably the only guarantee.
Another example is that although DRC and/or pcbfwd can check whether a symbol has the required geometry attribute GEOM, they can not check whether its value matches the schematic symbol. One mismatch can be between the number of pins specified on the ViewDraw symbol and that on the Allegro footprint.
This particular error can be caught by Allegro's dev_check utility. First, run pcbfwd on ViewDraw schematics to create Allegro device files, which together with Allegro footprint files are fed into dev_check. Suppose pins 68, 69 and 70 are on Allegro footprint but not on ViewDraw symbol, then dev_check can catch this. These pins may be no-connect or mounting holes or even POWER/GROUND pins that are left out of the ViewDraw symbol by mistake. No-connect and/or mounting holes pins must be assigned to the NC attribute and POWER/GROUND pins to SIGNAL attribute. Modify the symbol in this way and re-run pcbfwd and dev_check.
Finally, the quality of DRC outputs depends on schematics' quality. For example, if pin type is wrongly specified to be OUT for an input pin, DRC will generate wrong error messages. Component symbol quality should be carefully and systematically controlled, since it affects all other tools.
4.0 Beyond DRC
In addition to checking for design rule violations, DRC can also generate useful by-product output files, as has been previously discussed. An input switch can tell DRC whether to generate them for each run. Although these files do not contain DRC error or warning messages, they can flag potential design problems. For example, one file can contain a list of all nets and the number of loads on each. If that number exceeds a reasonable value, it may cause signal integrity problems. PCB designer can quickly go over this file and look for such issues. The number of these by-product files can be as many as required. A partial list is given below.
Here, ignetatt() and igattnxt() are ViewBase routines to get every attribute on a net. igattnam() gets the attribute name. net_att is the file pointer to the output file.
Another important use of this list is in signal integrity and timing analysis of the PCB design [4]. Most tools in this area can automatically handle the so-called series elements by combining their effects into the transmission line analysis results but take them out of the output files. One such element is R1 in Figure 2, which is a series termination resistor. When a signal integrity tool reports the net delay, it will be from u1.z to u2.i with R1's effect included instead of from u1.z to R1.1 and continue on from R1.2 to u2.i. This is the correct thing to do for timing analysis.
Figure 2 -- Series termination resistor
However, in order for a signal integrity tool to automatically recognize a series element, some conditions must be met. For example, the reference designator of a resistor must start with letter R followed by numerical digits and that of a capacitor with letter C. Another condition is that each series element symbol must have a TYPE attribute with a value of DISCRETE. Without these conditions, these elements can not be handled correctly.
One common problem is with a template design that is copied by many other PCBs. In order to avoid possible reference designator conflicts, a resistors and capacitor in the template design are usually called XR1 and XC1. They must be changed to R10001 and C10001 (the number should be bigger than any possible reference designators used in the original PCB design) in the database of the signal integrity tool. One can find the XR and XC reference designators by using the discrete components list generated by our DRC.
5.0 Conclusion
Clearly, there are many advantages and necessities of writing your own PCB design rule checker. Although this effort is not trivial, it is not rocket science either and can be done by anyone with a good knowledge of existing programming or scripting languages. The benefits are unlimited and can greatly outweigh the efforts.
6.0 References
1. Luke L. Chang, "Transient Analysis of the VAX 9000 Memory Power Distribution System", Digital Power Systems, Fall/Winter 1990
2. Brian W. Kernighan & Dennis M. Ritchie, "The C Programming Language", 2nd Edition, Prentice Hall, 1988
3. Bjarne Stroustrup, "The C++ Programming Language", 3rd Edition, Addison-Wesley, 1997
4. Luke L. Chang, "Static Timing Analysis of High-speed Boards", IEEE Spectrum, March 1997
Luke L. Chang is a Senior Verification Leader in the Storage Component Division of Intel (Hudson, MA). Previously, he has held both engineering and management positions at several high-tech companies, in the areas of hardware design/verification and of electronic design automation (EDA).
|
|
|
All materials on this site Copyright © 2009 TechInsights, a Division of United Business Media LLC. All rights reserved. Privacy Statement | Your California Privacy Rights | Terms of Service | About |
|