Saturday, 28 January 2012

Automatically Generate Quartus Pinning From Altium

The task of entering the pin mappings between FPGA I/O pins and signal names is both tedious and prone to errors. FPGA's with 484 pins are pretty common and this is by no means the largest. Typically you will have schematic drawings which you will need to reference to find out which signals are assigned to which FPGA pins. There are rumours that Altium Designer can export pinning information auto-magically however the consensus seems to be that this only works if you use Altium software for both schematic capture and HDL design entry. Since most people use Quartus/Xillinx tools for FPGA development, this is of limited use.

Fortunately, Altium - and just about any other EDA - can reliable export a netlist of you circuit. With this netlist you can readily extract the information you need. That is, the signal name and the FPGA pin number. If you have assigned sensible net labels in your design, it should be possible to convert this netlist file into a tickle script file for use with Quartus. The simplest method of conversion is with VIM text editor

From experience, I've found it best to save your design in the MultiWire (.NET file) format. I'm sure other netlist formats will work but this is the only one I've had success with.

The steps to follow are detailed below:

Step 1:

Open the FPGA schematic sheet(s) in Altium

Step 2: 

Extract a MultiWire Netlist from Altium: Design > Netlist for Document > Multiwire

Step 3: 

Open the netlist file in VIM, You should see a file like the following:

0V                U2                            T1
0V                U2                           T22
1V8               R9                             1
2V5               PL2                            1
2V5               RP36                           2
2V5               RP36                           3
2V5               RP36                           4
3V3               R7                             2
3V3               R8                             2
AUX_IN            U2                            B1
AUXTEST           J1                            11
AUXTEST           TP11                           1
AUXTEST           U2                            D2
CFCD1#            U2                            C3 
Step 4: 

Remove all components except the FPGA. You will need to replace "U2" with your chosen designator:


Step 5: 

Remove GND, VREF, VCCIO nets (feel free to add more nets to the blacklist):


Step 6: 

Convert netlist format to Quartus tickle assignments:

0,$ s:\(\p\+\)\s\+\(U2\a*\)\s\+\(\u\+\d\+\).*:set_location_assignment\tPIN_\3\t-to\t\1

Step 7: 

Check for any reserved pins you might have missed. You can always add these to the blacklist for the next time you use the script.

I have wrapped all of these operations into a single vim function which you can paste into your vimrc file (if you're not sure where this is, type :echo $MYVIMRC).

" Netlist to Quartus tcl assignment file conversion
" Author: 
" Function: Net2Pin 
" Parameters:
" #1 designator : string : (FPGA) component designator e.g. "U2" or "IC4"
" (case sensitive)
function! Net2Pin(designator)
    "Delete all Nets which aren't connected to specified component designator 
    let pattern = '/^\p\+\s\+' . a:designator . '\s\+.*/d'
    execute  "g!" . pattern
    "Delete reserved pins i.e. those used for power/ground/config/jtag
    let pattern = '/^\(GND\|0V\|1V2\|2V5\|3V3\|FPGAMSEL\|FPGATCK\|FPGATDI\|FPGATDO\|FPGATMS\).*/d'
    execute "g" . pattern

    "Convert netlist format to Quartus tcl assignments
    let pattern = '\(\p\+\)\s\+\(' . a:designator . '.*\)\s\+\(\w\+\d\+\).*:set_location_assignment\tPIN_\3\t-to\t\1'
    execute '0,$ s:' . pattern

Once you have saved your changes and reloaded your vimrc file (:source $MYVIMRC) you will be able to call the function as follows:
:call Net2Pin("U2") 

Replace "U2" with whatever designator you used for the FPGA in the schematic. The output of this function for the above example is:

set_location_assignment PIN_B1 -to AUX_IN           
set_location_assignment PIN_D2 -to AUXTEST          
set_location_assignment PIN_C3 -to CFCD1#           

License: GNU GPL

References - An essential resource for understanding vim regular expressions

:help vim-script-intro - A great starting point for understanding vim scripting

Wednesday, 18 January 2012

The Doobry Lab - Technical Reference App

This is a shameless plug for a colleague's recent venture into Android Application development:

"Nautilus [has been] developed to cover a broad range of technical subjects, without getting too bloated with details. It will never cover any one subject in great detail, but will provide the information most commonly requested at your fingertips."

For more information, visit The Doobry Lab or just go straight to the Android App Store

Monday, 16 January 2012

Vim Foo

My most advanced regular expression to date:

0,$ s:\(\d\+\)\s\+\(\w\+\d\+\):set_location_assignment PIN_\u\u\2 -to HdcSig[\1]

This takes a space-separated-value file of signal names and FPGA pin numbers and generates the tickle assignment statements required by the synthesis tool, Quartus.
0    aa1 
1    a4
2    b4
3    c9

set_location_assignment PIN_AA1 -to HdcSig[0]
set_location_assignment PIN_A4 -to HdcSig[1]
set_location_assignment PIN_B4 -to HdcSig[2]
set_location_assignment PIN_C9 -to HdcSig[3]
In Summary it:
  1. Extracts a numeric followed by alpha-numeric field and stores them in \1, \2 variables
  2. Adds a line prefix
  3. Capitalises coordinates
  4. Switches order of signal names vs coordinates
  5. Adds some braces
Result: feeling smug :D

Sunday, 15 January 2012

Peterborough in January

Today we made it to Peterborough (just) to watch the Peterborough Phantoms play the Sheffield Steeldogs in the English Premier Ice Hockey League.

Before the match game, we wondered around Peterborough city. Despite being generally quite ugly, there was one redeeming feature, it's Cathedral. Even on an overcast and freezing afternoon its walled grounds were inviting and its architecture both imposing and impressive. Enough words, here are my favourite photos from the Cathedral grounds.

This one isn't actually of the Cathedral or the grounds. It is the market square in the centre of the town. The sky looked too good to pass up the opportunity to photograph it.

You can view the Picasa album here

Saturday, 7 January 2012

Man Bench Transformation

For over a year, the affectionately named 'man bench' has been a bit of an eyesore in our flat. Its some old tool shelving that my Dad lifted from a building site at the end of a job. Our flat is quite small and storage space is at a premium, hence not throwing it out.

More recently I've begun playing the piano more regularly in an attempt to teach myself blues piano. Getting a keyboard stand has been out of the question because there just isn't the room to leave it up all the time. I've been using the ironing board as a temporary stand. It is however, rubbish; it wobbles and  cannot be adjusted to a suitable height for playing.

This afternoon I set about transforming the shelving into a sturdy keyboard stand. This involved lowering two of the shelves, sawing off the legs and cutting the top down to the right height.

Here's the before:

From Man Bench Transformation

Here's the during:

From Man Bench Transformation

And here's the after:

From Man Bench Transformation

From Man Bench Transformation