Monday, 16 May 2016

Don't forget you can re-assign pins with a microcontroller!

Microcontrollers - PICs and Arduino/AVRs in particular - are great for quick and (relatively) easy prototyping. Stick one onto a breadboard, shove in some wires, hack a bit of code together and... ta-da! A working "thing".

Taking it a step further, once you've got your prototype down, is making a PCB.
Now, at this stage, a lot of people dedicate an awful lot of time to copying the pin-connections from the breadboard onto a PCB layout. Though it's almost always preferable to draw out a schematic first; schematics help make sure you don't miss any connections or introduce any dead-shorts - though it's quite a bit more work than going straight to the PCB layout.

With an electrical schematic, laying out the PCB is simplified - the schematic and the PCB layout software usually work hand-in-glove and the schematics can help with the layout, either through auto-routing, or by highlighting which pin connections need to be joined together.

An electrical schematic....

...enables the software to help you with your pcb layout

After spending all that time and effort designing not only a schematic, but a PCB layout, it's very easy to become "committed" to the design, quite early on. And in being so committed, it sometimes results in quite convoluted routing - particularly if any problem traces are left until towards the end!

And after committing so much time and effort, it's easy to forget that quite often your pin numbers aren't actually set in stone. Sure, if you're using an Arduino and some pre-build library (or, indeed a PIC micro and a hardware peripheral) you might be limited to which pins you can use. But sometimes - quite often - the pins are chosen by you, the firmware writer.

And quite often you, the firmware writer, doesn't give much thought to which pin(s) might lead to a simpler pcb layout - quite often you just stick to the pins in the example you've just copied off the internet (come on, don't pretend that's how a lot of us cobble together code when we're looking for a quick win). Or stick to sequentially numbered pins (how many of us start with pin3 for inputs on an Arduino, or count back from 13 for outputs? More than you might realise....)

But it's important to remember which pins you actually assigned yourself, and which you've no control over. Because shifting a few pins around in software can quite often make the PCB layout much, much easier in the long run.

Sure, it's a bit more work.
And if you're the kind of person who doesn't mind long jumper wires, or bits of multi-core tack-soldered to pins on the microcontrollers, maybe just ignore this entire post. But if you're thinking about making a few PCBs yourself (homebrew etching) or even having the boards manufactured, spending that extra time swapping pins is almost always worth it.

It's just one of those things that we tend to forget about.
Or maybe it's just me.

No comments:

Post a Comment