Stupid beginner tricks, or, why did it take me so long to realize this? - Page 1
Forum section: electronics / general

author: rrinker
author_rank: Super Contributor
timestamp: July 01, 2019, 04:36:26 pm
content: So I've had a schematic drawn up for a microcontroller project I am working on, for some time now. Built it on a breadboard, write the code, and it works. Now comes PCB layout, because I need dozens of these and I'm not going to point to point wire them all.Having some trouble getting it laid out in a logical manner, minimal back and forth between layers with vias, keeping the power section short and away from data lines, etc.Then it hit me, lounging in the pull the other day. Why am I using the pin assignments on the micro that I am? I took another look at the pinout of the micro. Wait a second - if I just switch around some pin assignments, I can orient the micro such that almost no lines need to cross from one side of it to the other, and few traces have to cross . Why was I so stuck on the original pin assignments? There are no usage restrictions that made me chose the order I did, and the few that were driven by such things are able to remain unchanged in the new scheme of things. Anything flexible was moved around in a more logical layout order instead of some function grouping - I guess I was looking at it more as a programmer than a circuit designer. This will make layout of the board MUCH easier and keep the noisy bits like relays and servos far away from the inputs. Heck even the schematic should look cleaner, if I replace the micro model with one that uses the actual pinout instead of grouping all the IOs on one side of the block and the support stuff *VCC, GND, crystal, reset) on the other.And I envision most people looking at this and thinking "Well, DUH!"

author: MarkF
author_rank: Super Contributor
timestamp: July 01, 2019, 04:50:53 pm
content: Been there... Done that...I switched MCU pin assignments several times on one project alone.Eliminated many trace crossings by just re-assigning pins and only needed trivial code changes.

author: free_electron
author_rank: Super Contributor
timestamp: July 01, 2019, 04:54:34 pm
content: wait till you start playing with FPGA's.Do the layout first. then assign pins.I would really like to see processor makers make a totally capable pin mux so you can put anything anywhere. it doesn't cost that much logic.Only power , crystal and reset pin should be 'hard'. The rest should be programmable. ( with the exception of USB )Programming should be done using bootloaders over usb or over 2 pins that change operation (tx/rx or sclk / sdio ) ( only when reset is physically held down longer than 3 seconds. The loader kicks in)

author: rrinker
author_rank: Super Contributor
timestamp: July 01, 2019, 05:41:48 pm
content: Quote from: MarkF on July 01, 2019, 04:50:53 pmRight? And since all my pin assignments are in one well-commented block right at the top of the code - stupidly simple to fix.My next project should not have this issue, I'm using very few of the pins directly off the micro, the IO for that will come mostly from IO expanders. I can already see how to lay that out to give plenty of room for the IO connectors and not make a giant PCB with big unused areas. I'm learning! That's the good thing.

author: ataradov
author_rank: Super Contributor
timestamp: July 01, 2019, 06:14:27 pm
content: Quote from: free_electron on July 01, 2019, 04:54:34 pmIt unfortunately does. Newer Atmel/Microchip MCUs have pretty flexible multiplexing (but not any to any). And for smaller devices all multiplexing options are available. But for bigger devices (like SAM E54) SERCOM unit (UART/I2C/SPI) pins are assigned in groups, and the whole group must be multiplexed. The timing of the signals between the groups is not guaranteed. This probably is not a big deal for I2C or UART, but may be an issue for SPI running at 24 MHz.May be as technology used for typical MCUs improves, it will become a reality, but not right now

author: free_electron
author_rank: Super Contributor
timestamp: July 01, 2019, 06:42:06 pm
content: Quote from: ataradov on July 01, 2019, 06:14:27 pmThey do it on fpga's without problems. All that is required is is a pass gate (basically an 'analog switch' made from a fet)Let's assume 32 signals. Since it is 1 out of many you only need 5 control bits. So 5 flipflops. If you make a ladder mux you don't need a decoder so you are looking at 62 transistors .You chain the control flipflops in a long shift register. At reset the configuration gets 'shifted in' and done . The pass gates do not add any delay as it is not a logic gate , only an in-line switch.so for 32 signals you need 32 x (62 fets + 5 flipflops )That amount of transistors is nothing compared to what is already on the chip.

author: ataradov
author_rank: Super Contributor
timestamp: July 01, 2019, 06:48:52 pm
content: Overall FPGA and MCU design is different. It is not about actual multiplexing, that's really easy. But you now have to route each peripheral output to every pad. This is a lot of routing. In FPGA this happens naturally, but not in the MCU with fixed peripherals.A single shift register may not work as well, since MCU applications may want to control the assignment in run-time. Of course you may be able to accept this limitation.

author: Rerouter
author_rank: Super Contributor
timestamp: July 02, 2019, 10:22:52 am
content: In reality you can simplify your routing, for just about everything you do not need the mux anywhere near the I/O pins that see high current, its better to attack it near the registers. after all they are a hardware register that controls the pins at max clock frequency so you have your muxing back there for everything that is just a combo of input / output / pullup, you would swap all 3 (or more) registers bits that control a given pin to a different pinI obviously am only an armchair warrior when it comes to silicon layout, but I would assume this approach even if used without the muxing would reduce the amount of routing by not needing the peripheral control lines near the pins, seeing as they already run there for I/OThe analog stuff.. well I love the ATtiny1634, because it just made every bloody pin an ADC pin. and equally every pin able to use the analog comparitor.

author: langwadt
author_rank: Super Contributor
timestamp: July 02, 2019, 12:03:23 pm
content: Quote from: free_electron on July 01, 2019, 04:54:34 pmdon't do the layout before you have tried pinout in the fpga tool, there are some limitation to pin placement. from something as simple as what bank voltages are compatible withwhat io standards, sometimes depending on whether you need internal termination. And if you use things like serdes certain pins often pair up certain clk pins

author: asmi
author_rank: Super Contributor
timestamp: July 03, 2019, 06:11:44 pm
content: Quote from: free_electron on July 01, 2019, 04:54:34 pmThis is a recipe for a board respin. Always validate your pin assignment in FPGA toolchain before you commit to any layout and manufacture the board! There is a number of limitations for pin assignments, especially for high-speed interfaces, when you simply won't be able to close timing no matter what you do if you choose wrong pins.

author: Siwastaja
author_rank: Super Contributor
timestamp: July 05, 2019, 08:17:47 am
content: All of this is very easy if you mostly use the pins as GPIO. If you need, for example, an SPI, then you have to be aware of which pins can support the SPI. If you need, say, UART at the same time, you need to solve the puzzle if they share pins.See attached, I start by adding all relevant peripheral mapping possibilities to the schematic symbol.I like to work without the manufacturer's "tool of the year". This doesn't apply to FPGA designs: with them, using the manufacturer-supplied pin mapper is an essential part of PCB layout.

author: Psi
author_rank: Super Contributor
timestamp: July 05, 2019, 08:46:01 am
content: If using the ATMega328p watch out for the ADC only pins.Although it's less of an issue now, since there's the ATMega328pb