Canonizing PCAD netlist files

This post was written by eli on July 20, 2010
Posted Under: FPGA,perl,Software

OK, so the board designer just sent me an updated schematics of the design. Are there any changes? Comparing the schematics itself is hopeless. So I’ll compare the PCAD netfiles (those with a .NET extension). I mean, they are simple text files, after all.

The problem is that Orcad feels free to change the order of the nets’ appearance in the file, and also the order of the pins connected to each net. So using diff to compare the two files gives a lot of false positives.

Solution: Sort the nets descriptions and the connections of both files. Diffing the outputs yields the true changes.

The Perl script is below. Even though the output looks OK to me, I wouldn’t think about using it for PCB manufacturing. But I suppose  it’s pretty safe to say that whatever turns up in a diff test sums up to the changes made.

#!/usr/bin/perl
use warnings;
use strict;

our @connlist;

local $/; # Slurp mode

my $netlist = <>;

my ($parts, $nets) = ($netlist =~ /(.*?)^(nets[ \t\n\r]*.*)/msi);

$nets =~ s/^([a-zA-Z_0-9]+)[ \t\n\r]*=[ \t\n\r]*(.*?);[ \t\r\n]*/canonize($1, $2)/gmse;

print ($parts, $nets);
print "%\n%Canonized nets below\n%\n";
print sort @connlist;

sub canonize {
  my ($net, $connections) = @_;

  my $out = $net;

  $out .= ' = ';

  my @conns = sort ($connections =~ /([a-zA-Z0-9]+\/[a-zA-Z0-9]+)/g);

  # Sanity check. Remove everything recognized and whitespaces.
  # We should be left with nothing.
  $connections =~ s/[a-zA-Z0-9]+\/[a-zA-Z0-9]+//g;
  my @bads = ($connections =~ /([^ \n\r\t]+)/g);

  foreach my $bad (@bads) {
    warn("Ignored token $bad for net \"$net\".\n");
  }

  $out .= join(' ', splice (@conns, 0, 5));
  while (@conns) {
    $out .= "\n       ".join(' ', splice (@conns, 0, 5));
  }
  $out .= ";\n";

  push @connlist, $out;

  return '';
}

To use it, go something like:

$ canonize_netlist.pl REV01.NET > canon01.net
$ canonize_netlist.pl REV02.NET > canon02.net
$ diff canon01.net canon02.net | less

Or use some GUI oriented diff applications (I use WinMerge on Windows, for example)

Reader Comments

Just wandered around your blog and saw this post.

I faced a similar problem 11 years ago when I needed to prepare a netlist with minimal changes for my PCB layout contractor.
This is what I came up with:
http://udif.netfirms.com/punto/punto.html

I haven’t touched the code since then.

#1 
Written By Udi on January 3rd, 2011 @ 00:24

Add a Comment

required, use real name
required, will not be published
optional, your blog address