matrix utility

## Overview

The scripts pcb-matrix and sch-matrix replicate PCB and schematic structures by copying an input file to an output file multiple times incrementing the (x,y) position of each copy. The copied structures are arranged in a matrix as specified in a configuration file.

N.B. These scripts may not work for all layouts. I wrote sufficient code to copy the schematic and PCB elements for one of my designs not for all possible designs. I am almost certain that sch-matrix will break for schematics with embedded symbols.

#### Conventions

 parameter Replace with the value of parameter verbatim text Verbatim text when associated with a command or contents of a file. sch-matrix The current version of the schematic matrix program. pcb-matrix The current version of the PCB matrix program. sch-matrix_version Version version of the schematic matrix program. pcb-matrix_version Version version of the PCB matrix program.

### Creating a Design

To create a design:
1. create an input schematic    Create a schematic that contains the structure to be replicated.
2. create an input PCB    run gschpcb on the input schematic and create a PCB layout (which will be the input PCB layout).
3. add the marker line to the input PCB    using your favorite editor (EMACS) add the marker line to the input PCB.
4. create configuration files    create configuration files for sch-matrix and pcb-matrix.
5. create an output schematic   run sch-matrix
6. create an output PCB   run pcb-matrix
If all of the reference designators are assigned in the input schematic and that schematic is used to create the input PCB file then all of the reference designators in the output schematics and PCB files will be in-sync. sch-matrix and pcb-matrix use the same algorithm to update reference designators.

## sch-matrix

### Usage

sch-matrix_0 <configuration filename>

### Description

The sch-matrix script creates a new layout by coping each component, text value, net, line and circle to an output file multiple times. Each structure is positioned as defined by the parameters in the configuration file. For each component the reference designator is updated to maintain unique reference designators in the output file.

### Creating the Schematic

Schematics are created in the usual manner using gschem. Prior to running sch-matrix all of the reference designators (refdes's) must be assigned. sch-matrix dies if the refdes does not match an alphabetic string followed by integer (which is the regular expression [A-Za-z]+\d+).

#### Connecting the Replicated Schematics

The replicated schematics can be connected by naming nets or by placing nets so that they will physically connect after replication. Naming the nets produces less clutter on the schematic but does not show connectivity. Using continous nets shows connectivity but can be messy when there are many nets or nets in many directions (such as when groups of components are arranged in a matrix). If the groups are all in a row (or all in a column) then a continous horizontal (or vertical) net can be placed. By choosing the appropriate length for the net and the proper xoffset and yoffset a single continous net will be created in the output file. For a matrix a combination of net names and continuous nets may be best.

#### Adding Circuitry to the Output Schematic

Usually additionaly circuitry will need to be added to the output schematic to complet a design. However, everytime sch-matrix is run the output schematic is overwritten. If you embed the output schematic in your design using a heirachical block then this problem is eliminated. Since connections to the block are by net names no changes are required when sch-matrix is re-run.

## pcb-matrix

### Usage

pcb-matrix_0 <configuration filename>

### Description

The pcb-matrix script creates a new layout by coping each Element, Polygon, Via and Line from an input file to an output file multiple times. Each layout, from the input file, is positioned as defined by the parameters in the configuration file. For each Element the reference designator is updated to maintain unique reference designators in the output file. In a PCB file there is a variety of data prior to the start of the layout ({\em e.g.} user interface settings, character symbols) . It does not seem desirable to replicate all of that data. Rather than try to guess where the layout starts the pcb-matrix program requires a marker line in the input file to indicate the start of the layout. The marker line is a line containing only the string #####__PCB__##### which is a legal PCB comment line. This marker line has to be reinserted each time you save the PCB layout. The start of the layout seems to reside after all of the symbol declarations and before the vias. pcb-matrix will copy all of the lines prior to the marker to the output file verbatim. After the marker line is read the remaining lines will be output r x c times in a matrix (where r is the number of rows and c is the number of columns specified in the configuration file).

### Adding Circuitry to the Output PCB Layout

Usually additionaly circuitry will need to be added to the output PCB layout to complet a design. However, everytime pcb-matrix is run the output layout is overwritten. If you embed the output layout in your design using the load layout data to paste-buffer command then you can reload it if changes need to be made. Since the output layout is self-contained only the peripheral connections will need to updated. To reload an output layout into your design:

1. Delete the peripheral connections that connect the output layout to your design.
2. Delete the output layout.
3. Use load layout data to paste-buffer to add the output layout

## Creating Configuration Files

The configuration file format is the same for sch-matrix and pcb-matrix. Each file can contain comments, empty lines and lines that set parameters. Comments start with a # and proceed to the end of the current line. Comments and empty lines are ignored by the parser. The lines that set parameters are in the format:

name | parameter value where parameter name is one of the names listed in parameter table.
 Name Type Description  x0 Integer the x coordinate (in mils) of the starting position in the output file  y0 Integer the y coordinate (in mils) of the starting position in the output file  xoffset Integer the center-to-center column spacing (in mils)  yoffset Integer the center-to-center row spacing (in mils)  last_col Ordinal the ordinal of the last column (column ordinals start at 0)  last_row Ordinal the ordinal of the last row (row ordinals start at 0)  input_filename String the name of the file containing the structure that will be replicated  output_filename String the name of the file that contains the replicated stuctures

### Example

Occasionally a circuit design consists of a group of elements, a cell, that needs to be replicated multiple times. One example is an electronic load. An electronic load is a circuit that sinks current and is an essential instrument in power supply test. Typically an electronic load consists of multiple load-cell circuits in parallel. Creating a load using multiple cells increases the total current sinking capability of the load. A schematic of a simplified load-cell circuit is shown in Figure 1. The circuit consists of an op-amp, an N-channel MOSFET and current sensing resistor.

When creating the load-cell schematic the nets that are to have cell-to-cell connections need to have sufficient length so that they overlap after replication. The ground net and the net from the drain of Q1 are long enough so that an xoffset value of 3200 in the configuration will overlap the nets in the output file. Prior to running sch-matrix all of the reference designators need to be assigned. sch-matrix will uniquely number all of the components in the output file based upon the assigned values in the input file. The configuration file for sch-matrix is shown here. xoffset defines the cell spacing for columns and yoffset defines the cell spacing for rows. The lastcol and lastrow values define a 1x4 matrix. The output schematic shown in Figure 2 is the result of running sch-matrix using the schematic configuration file. Notice that the horizontal nets have been connected and the reference designators of the copied cells have been uniquely assigned.

After creating the schematic for the load-cell run gsch2pcb and create a layout for a single load-cell. An example load-cell layout is shown in Figure 3. In the load-cell layout the two high current traces are running parallel on the component side of the board along the top of the cell. The op-amp power and positive-input traces are running parallel on the solder side of the board at the bottom of the cell. All of the parallel traces are ≈950 mils long. Setting an xoffset of 900mils will create an overlap between the cells in the output file. Running pcb-matrix with the PCB configuration file produces the layout in Figure 4.

#### Schematic Configuration File

# x0        the x coordinate of the starting position in the output file
# y0        the y coordinate of the starting position in the output file
# xoffset   the column spacing
# yoffset   the row spacing
# last_col  the ordinal of the last column (column ordinals start at 0)
# last_row  the ordinal of the last row (row ordinals start at 0)
# input_filename  the name of the file containing the schematic
#                 that will be replicated
# output_filename the name of the file that contains the schematic matrix

x0       | 500                   #%\label{lst:cfg-sch x0}%
y0       | 100                   #%\label{lst:cfg-sch y0}%
xoffset  | 3200                  #%\label{lst:cfg-sch xoffset}%
yoffset  | 0                     #%\label{lst:cfg-sch yoffset}%
last_col | 3                     #%\label{lst:cfg-sch lastcol}%
last_row | 0                     #%\label{lst:cfg-sch lastrow}%



#### PCB Configuration File

# x0        the x coordinate of the starting position in the output file
# y0        the y coordinate of the starting position in the output file
# xoffset   the column spacing
# yoffset   the row spacing
# last_col  the ordinal of the last column (column ordinals start at 0)
# last_row  the ordinal of the last row (row ordinals start at 0)
# input_filename  the name of the file containing the PCB layout
#                 that will be replicated
# output_filename the name of the file that contains the PCB matrix

x0       | 500
y0       | 100
xoffset  | 900
yoffset  | 0
last_col | 3
last_row | 0