My open-source Altium component library contains hundreds of schematic symbols, supplying over 100,000 components for use. People are often surprised when I tell them it only takes a few minutes to make a schematic symbol using Altium, even if the part has a high pin count. In this article, I want to show you how you can leverage some of the tools in Altium to create your own symbols quickly.
Before we get started, you’ll need a couple of things:
To find a part to use for this article, I headed over to Digi-Key and looked in the Embedded - Microcontrollers category for an in-stock ARM Cortex M series microcontroller with onboard FLASH and more than 100 pins of GPIO. I then sorted by the quantity available, and the winner is an NXP MK64FN1M0VLQ12. It looks like a nice microcontroller in a LQFP-144 package. Copy and pasting the pin descriptions for every pin on this package would be time consuming, boring, and error-prone, so let’s not do that!
Looking at the datasheet for this part, the pin out table (5.1, Page 68) is not ideal for this process, but that’s OK—datasheets are rarely ideal for creating symbols.
Before going into detail on how to create this component, I ran through it myself to make sure I wouldn’t miss any steps as I wrote the article. It took me just over 7 minutes to create this 144 pin part which is a little slow for me. If the data in the datasheet didn’t need so much cleanup, it would have been around 4-5 minutes. However, I’ve created nearly 500 symbols like this, so I have a bit of experience that helps me get work done fast!
The first thing we’ll do in Altium is to create a new schematic library by going to File -> New -> Library -> Schematic Library.
Then, in the new component, we place a rectangle. By placing the rectangle for the component body first, it will save us having to move it behind the pins later, it just saves a little time. The size of the rectangle doesn’t matter. The one I’ve created will be far too small for the end component!
After the rectangle, we’ll create our first pin, which is going to be the seed for all the others.
It’s preferable to set the pin properties so it’s easy to use later, so I just set the pin number (designator) to 1, and the name to “P1”. The number portion of the name can be auto-incremented, and the letter P just lets me know in a later step that this is the pin name.
You should have something looking like this now:
We’re 143 pins short though, so let’s fix that. First, copy the pin.
Then, we are going to use the powerful Paste Array function from the Edit menu.
We need 143 more pins, so you can enter 143 for the item count, and make sure that vertical is set to -100mil. This will generate pins starting from where you click, going down (rather than way up).
As there are a lot of pins here, I’d suggest zooming out and clicking somewhere around 7000mil high on the schematic symbol!
I’ve arranged the pins into columns, but now we have 144 pins to use!
Having all these pins is not much use to the symbol, as we still need to add names to the pins. To do this, we’ll go to the datasheet.
Select the pin table, and copy and paste all of the data into a notepad++ document. It’s going to look awful, don’t worry!
As I mentioned earlier, this is not the most ideal datasheet, so before we can do anything more I want to clean up the pasted data a little. Primarily, many of the functions have been split over multiple lines in which they have a / or _ in the name. Having quality data for our starting point is going to make life easier later.
I’m going to use Find and Replace to look for _\r\n
, and replace it with _
. The extended search mode will find the names where the _
split the function into two lines and then replace it with just an _
. Click Replace All to just make all the changes in one hit.
Do the same for /\r\n
, replacing it with just /
.
The datasheet also has a lot of columns with the word ‘DISABLED’, so I’m going to find and replace ‘DISABLED ‘ with a space at the end, and replace that with nothing.
Now, we get to the Regular Expressions to sort this jumbled mess of letters and numbers into a nice table of pin numbers and descriptions. One thing we’re lucky to have is the package of interest as the first column in the pin table, this makes the regular expression a little easier.
I’m going to use the regular expression testing page at RegexStorm to process the pin list. You can also check their Regular Expression Reference or the Regex Cheat Sheet if you need to brush up on your syntax.
Before we go matching data, it would be nice to have all of the pin description items on a single row, rather than separated into multiple lines as they currently are. We can use a simple pattern on RegexStorm to fix up the text we’re working with.
I’ll use the pattern \r\n(\D)
to find any new lines that are not followed by a digit (\D
is the regex sequence for ‘not a digit’). The ‘not a digit’ that is matched needs to go into a group, which is done through the parentheses, so we can replace what is matched with just that character. Our replacement is then just $1
, as $1
specifies the first group that was matched.
After clicking replace, the context tab contains the fixed input data, so we can copy it from the context tab into the input to do some further work.
We’re not done yet though, there’s plenty (127) of places that the Pin Name, Default Function, and ALT0 function are all the same. We don’t want to create a pin 5 VDD VDD VDD, do we? Pin 5 being called VDD is sufficient.
We can use a regular expression to clean up these duplicate names too, using the pattern:
\b([A-Z\d/_]{3,})\s*\1\s*\1? *
This will find a word boundary with the \b, and then match a group of three or more capital letters, digits (\d
), slash or underscore characters with ([A-Z\d/_]
). Then, it looks for an optional number of whitespace characters with \s* followed by the same as the first group (\1
), another optional space, and finally, optionally (the ?) the first group again followed by any number of spaces. This way, it won’t match repeated pins like EE EE, but will match 2-3 of the same thing in a row such as VDD VDD VDD.
We can then replace this with ‘$1
‘, the same as last time, but with a space after the $1
. Finally, we can copy this back to the Input box.
Search Pattern
We’re looking to match a pattern that will find this:
115 C7 C6 82 PTC10 ADC1_SE6b
ADC1_SE6b
PTC10 I2C1_SCL FTM3_CH6 I2S0_RX_FS
FB_AD5
Or
89 F10 D11 — PTB8 PTB8 UART3_RTS_b
FB_AD21
The main difference between the two, as far as we are concerned, is the ‘—’ character present where that package doesn’t have the pin.
My match expression is:
(?:(?<Pin>\d{1,3})\s+(?:[A-Z\d—]{1,2}\s+){2}(?:[\d—]{1,3}\s+)
)
This is matching well in the table view. I now have a table for pins, and I have the entire pin number section of the data from the datasheet matched. This means anything else is going to be the description.
I’ve been using Regular Expressions since I used to program in PERL about 20 years ago as a teenager, so I’m fairly comfortable with them! Let’s break this first match down and explain it in case you’re new to regular expressions or need a refresher.
(?:\b(?<Pin>\d{1,3})\s+(?:[A-Z\d—]{1,3}\s+){2}(?:[\d—]{1,3}\s+))
(?:)
means it’s a non-capturing group. It allows me to group everything together without it ending up in the Table view on RegexStorm. Grouping things together is pretty important for getting what we want!
\b
is a word boundary eg: a new line, space, tab, etc. This prevents something like:
LPTMR0_ALT1
74 L12 J11 52
from matching the 1 at the end of ALT1, preventing the first 3 designators from being matched.
(?<Pin>\d{1,3})
captures a group named Pin through the ?<Pin> bit. Not all Regular Expression engines support named groups, which is one of the reasons I use RegexStorm. That group will match between 1 and 3 ({1,3})
digits (\d). Our pin number will always have between 1 and 3 digits (1 to 144), so that’s all we need to look for.
\s+
Matches any group of one or more consecutive whitespace characters. This way, if the data we copied from the datasheet has a space, a tab, or a line break between the pins, it will all be matched, even if there are multiple spaces or tabs.
Next, we want to match the two BGA package pin designators. (?:[A-Z\d—]{1,3}\s+){2}
does this, the quantifier at the end ({2})
says we want two of the non-captured group. That group is finding one to three of anything in the square brackets. The square brackets in regular expressions mean a match of ‘anything in here’. In our case, we have all capital letters (A-Z), all numbers (\d), and the emdash used in the datasheet to say the function isn’t in that package option. Finally, we have one or more spaces just like after the Pin match.
(?:[\d—]{1,3}\s+)
is matching our final pin number. It’s basically the same as our Pin match, but we need to allow for the emdash too, in case that functionality isn’t on the package.
If you’re not experienced with regular expressions, don’t worry, they stop melting your brain when you read them after just a few years!
Finding the Pin Description
To find match the description, we can add on to the current syntax so everything is in one group, this is now my pattern:
(?:\b(?<Pin>\d{1,3})\s+(?:[A-Z\d—]{1,3}\s+){2}(?:[\d—]{1,3}\s+)(?<Desc>[\w\d_/\s]+?\b(?=\d{1,3}\b)))
The added pattern to match just the description portion is:
(?<Desc>[\w\d_/\s]+?\b(?=\d{1,3}\b))
At last, we have a table containing 144 matches with relatively clean data. Now, I can copy and paste this into my Google Spreadsheet.
Back in Altium Designer, we can now get some data into the pin array we created. Select all of the pins (but not the rectangle) in the schematic symbol window.
Open the SCHLIB List panel by clicking the panels button in the bottom right window of Altium.
Now, you’ll see all of the selected pins in the schematic symbol.
If you right-click anywhere in the grid, you can choose to switch to edit mode.
Now, you can click on the grid and press Ctrl-A or right click and choose Select All.
After this, copy and paste everything into your spreadsheet a bit further below than the table you pasted from RegexStorm.
Now that we have the two tables in the spreadsheet, you can copy the pin number column from the data you copied from RegexStorm over the pin numbers from Altium Designer, and then do the same for the description column. This symbol happens to have all the pins for the package we are working on in order, but this won’t often be the case. It’s easier to just replace both columns so you don’t end up with description and pin name mismatches.
Before getting this data back into Altium Designer®, I want to quickly fix up the name column, to replace any spaces with / to follow the standard of my library. To do this, select the whole column in the Altium Designer table, then you can open the find and replace tool to search for a space and replace it with the forward slash. Hit ‘replace all’ after checking that the search is set to the specific range of the cells you selected.
Now, we have a table with all the pin names and designators ready to go back into Altium Designer. Just select the whole table and then paste it back into your SCHLIB List table. It will overwrite everything in the table, giving you a giant mess in your schematic symbol editor!
The most important thing is that we have the data in Altium Designer, and it was much less work and less error-prone than trying to copy all the details from the datasheet pin by pin.
I like to get all the pins grouped together around the schematic symbol sheet so I can decide if I want to keep the symbol as a single part, or whether I need to make a multipart symbol. For this 144 pin part, it’s going to have to be a multipart symbol but I’ll still group everything together nicely to give me groups of pins to copy and paste into each new part.
We can use the SCHLIB Filter panel to select mask groups of pins at a time. There isn’t a tool to quickly arrange pins together, but with all the pins selected it is easy enough to drag them all out to a free area of the schematic sheet and sort them manually.
To find all pins such as VSS or VSSA, I can use the filter: Name LIKE ‘VS*’ which will perform a wildcard match to select all those pins.
You can repeat this with filters like Name LIKE ‘VD*’ to grab the other power pins. The port pins on this component start with PTA/PTB/PTC etc, so you can use the same style of filter to find all the Port A pins and so on.
After a little bit of quick arranging, I now have all my pins grouped up.
I want all the ADC, DAC, voltage, ground, USB, and crystal pins on the main component part, so I moved them down to the rectangle I created as the first step in this process and then resized the rectangle to fit all the pins. I always place my VDD pins in the top left, and VSS/GND pins in the bottom left and will group pins by function rather than their position on the symbol. I feel this makes for a more usable symbol in a schematic than trying to copy the physical layout.
Now that the main part is finished, we need to add subparts to the schematic symbol. You add a new part to the schematic symbol by going to Tools -> New Part.
The new part will show up in the SCH Library panel, nested under your main component.
Once you have the subparts, it’s just a matter of creating a rectangle in each subpart then cutting and pasting the pins into it from the main part. Breaking a huge microcontroller into logical parts will allow the engineer using the symbol to create a cleaner, neater schematic than having his or her whole sheet dominated by a single giant schematic symbol.
The symbol created above might be perfect for your library, but I prefer to overdo things. I’ve put together a few more regular expressions you can refer back to if you want to clean up the names further or add active low bars to the functions that start with n_ or end with _b as the part we worked on has.
By having these patterns ready to hand, you can end up with higher quality symbol names and only a minute or two of additional work. Additionally, you could use them as the basis of your own cleanup patterns.
I manually removed duplicate functions on the pins in the screenshots above, but you can do it automatically if you find you have too many of them to remove the duplicates efficiently by hand.
First, remove the duplicates of the initial function, such as ‘PTA12’
. Use the regular expression:
^([A-Z\d/_]{3,})/(?<inbetween>(?:(?:[^/])+/){1,5})\1/?
With the Options -> Multiline option. This will treat each line in the Input field as its own entity for the ^ character to match the start of the line.
Replace the matches with:
$1/${inbetween}
Then replace any functions after the first function with the regular expression:
/([A-Z\d/_]{3,})/(?<inbetween>(?:(?:[^/])+/){1,5})\1/?
You can turn off the multiline option again, but leaving it on won’t stop the expression from working. Again, replace the matches with:
/$1/${inbetween}
Keep replacing the matches until no more are found. For this part, I had to run it 3 times to remove all the duplicates.
There are two expressions for replacing duplicates as the expression needs to know where to start looking for a match. You don’t want to replace /RMII0_RXER/MII0_RXER/ with just /RMII0_RXER/, as the second function is the same as the first except for the R. By having two functions, we can use the / as a starting character, or the beginning of the line.
Adding active low bars to the name of a function is more in line with Altium Designer’s standards than having n_ or _b on the function. You can do this by adding a \ after each character, and a regular expression can find those for you with look ahead groups.
For functions ending with _b, use the expression:
([^/](?=[A-Z\d_]*_b[/\r]))
And replace all matches with: $1\
Then use the expression:
\_b
And replace all matches with: \
For functions starting with n_, you can use the expression:
((?<=/n_[A-Z\d_]*)[^/])
And replace all matches with: $1\
After that, you will need to search using the expression:
n_(\w)
And replace with: $1
To remove the n_ from the start of the function name.
Regular expressions are a very powerful tool to have if you’re creating symbols in Altium Designer from datasheets. You can quite rapidly turn unintelligible copy and pastes from a PDF into a usable spreadsheet using just a few expressions. I’m told by new users that the syntax looks extremely intimidating, as it may appear at first glance to just be a jumble of symbols and numbers, but in reality, it is a very well defined syntax which is quite easy to learn. After just a few hours of cleaning up datasheet copied text into pin tables, you’ll find yourself getting comfortable with the syntax.
This particular part was essentially chosen at random to create this article. While the data did need a lot of cleaning up—and that can take more time than actually getting the data into Altium Designer—I hope it has shown you some new ways to work with schematic symbols.
If you have any suggestions for creating schematic symbols faster, leave a comment below with your suggestions so others can take advantage of your experience.
See more Altium Guides or read more by Industry Expert Mark Harris. Would you like to find out more about how Altium can help you with your next PCB design? Talk to an expert at Altium.