Is it needed (or is it a good idea) to have resistors in MCU's digital I/Os? - Page 1
Forum section: electronics / general

author: xtv
author_rank: Contributor
timestamp: March 12, 2021, 02:50:46 pm
content: Hi,First, I'm sorry if I've opened up this discussion in the wrong topic. I see that loads of comments here are very specific to each MCU family, and this is more like a general electric design question.I've been playing around with an Arduino micro (Atmega 32u4) and other external components, mostly interacting over SPI.I'm wondering, in a professional circuit, is it a good practice to have resistors between these digital communication lines and for CS pins and the shared MOSI/MISO lines?Or it is assumed to be safe enough to hard wire these components?Many thanks.

author: ajb
author_rank: Super Contributor
timestamp: March 12, 2021, 03:51:57 pm
content: There are two main reasons to put series resistors on lines like this: signal integrity and overcurrent protection.Signal integrity comes into play when you have very high speed signals, which in this context does not refer to the clock frequency, but how sharp the edges are when the line transitions from low to high and from high to low. Very fast edge rates can cause ringing on the line, or reflections, which can cause spurious clock transitions, induce noise in adjacent signals, or even cause potentially harmful stress to components. Adding a series resistor to the pin driving the line can help with this, although a lot of modern MCUs have IO pins with programmable drive strength which can accomplish the same thing without an external component. An Atmega part may or may not have fast enough IO pins for this to be a concern, but a zero-ohm resistor is cheaper than respinning a board, so if you're not sure that it won't be a problem it's often better to err on the side of designing the footprint in until you can test to verify.Overcurrent protection can apply to two main scenarios: more than one device attempting to drive the line at once, and wiring faults. Any time you have a line that more than one device may want to drive, it's a good idea to include a series resistor to reduce the amount of current that will flow if one device is trying to drive the line high and the other low. This might only be a problem during firmware development, once you have things stable maybe you can be sufficiently confident that everything will work correctly and only one device will ever try to drive the line at once, but again, resistors are cheap, and a failure in the field is expensive. Wiring faults mainly apply when you have a connector going off-board, especially if that connector is exposed to the board. You don't want a miswired cable that shorts a signal line to ground to damage the device that drives that signal, so again a series resistor will reduce the current flow and reduce the stress on the device. Connectors that serve long signal wires will introduce additional signal integrity concerns, and a series resistor may help with that, but that's a larger topic. Series resistors, in combination with clamping/TVS diodes, make for a good start at more robust protection for things like ESD and overvoltage, which are again especially important on any external connectors, but also a larger topic.So to circle back to your SPI scenario, if a signal is only ever driven in one direction (like MOSI and CS lines in most cases), you probably don't need a series resistor unless the signals are fast enough and/or the lines are long enough that you want series termination. If a signal may be driven by multiple devices at once (like MISO on a multi-device bus), series resistors on each device that may drive that signal are a good idea.

author: Siwastaja
author_rank: Super Contributor
timestamp: March 12, 2021, 05:13:07 pm
content: If you want to bring out the signals to external pins / etc., relevant for modules, the series resistor is, by far, the simplest, cheapest, and most bang-for-the-buck way to add protection. The level of protection is not great, but it's so simple and cheap to do it's a no-brainer.Properly sized resistor(1) allows LED to be connected directly,(2) allows capacitive loads like large MOSFET gates to be driven, slowly though,(3) series-terminate digital communication, removing overshoot.(4) protects from overcurrent damage caused by accidental short(5) limit the current flowing into internal protection (clamp) diodes in case external voltage outside the power rails of the chip are accidentally injected, widening the non-damaging range of external voltages.(6) increase the robustness against ESD by limiting ESD current and burning part of the voltage; not by much, though, but worth mentioning for completeness.These goals have different resistance targets, though, but from 33R to 100R would be typical.For on-board digital signals, series resistors are not often used by default. In a very noise-sensitive application, or in case of poor routing or very long traces, series termination may still be beneficial.

author: rstofer
author_rank: Super Contributor
timestamp: March 12, 2021, 08:08:24 pm
content: In the FPGA world, Digilent tends to use resistors in series with every pin that can leave the board.Personally, I found them to be REQUIRED to eliminate reflections when I had an FPGA talking to a Compact Flash device. I used 330 Ohms, copying another Digilent board.There are situations where one size doesn't fit all (like driving MOSFETs) but, when driving other CMOS kinds of things which have very low current requirements, the voltage drop across the resistor is essentially 0V.On the Basys board, Digilent reduced the resistors to 200 Ohmshttps://reference.digilentinc.com/_media/reference/programmable-logic/basys-3/basys-3-sch-public-rev-d.pdf

author: ejeffrey
author_rank: Super Contributor
timestamp: March 12, 2021, 08:26:41 pm
content: Quote from: xtv on March 12, 2021, 02:50:46 pmWell, in a professional setting most often the microcontroller and the SPI peripherals would be on the same PCB. In that case, it is definitely not standard practice to add current limiting resistors for something like SPI. And in a professional setting you most often would not use SPI off-board, you would use something like RS232/RS485/CAN/ethernet.In the case that you do take SPI off board or for any other low speed digital IO, it is reasonable to consider protection circuits, what exactly is appropriate will depend on the environment. It could just be ESD diodes or a TVS, series resistors might be used either to limit short circuit current or to slow down the rise time and provide termination. It could go all the way up to opto-couplers.If you are talking about just making an arduino shield with some SPI chips where the total trace length is only a few inches max, I wouldn't bother with any of it. Just wire it up. If you are trying to run over a cable, I would add more protection.

author: MikeK
author_rank: Super Contributor
timestamp: March 12, 2021, 08:32:15 pm
content: Sometimes you can get away with no resistors. I have used PIC microcontrollers to drive LED displays with no current limiting resistors, relying instead on the internal FET "on" resistance. I have done it to minimize parts count, board size, and simplify the layout. And multiplexing the LED segments limits overall current as well.The reasons noted in favor on using them are appropriate, though.

author: Siwastaja
author_rank: Super Contributor
timestamp: March 13, 2021, 06:34:56 am
content: Quote from: MikeK on March 12, 2021, 08:32:15 pmOMG, don't do that.

author: AndersJ
author_rank: Frequent Contributor
timestamp: March 13, 2021, 06:41:08 am
content: Quote from: Siwastaja on March 13, 2021, 06:34:56 amApart from loosing control of current limit resistance, and EMC, please motivate, for clarity.

author: josip
author_rank: Regular Contributor
timestamp: March 13, 2021, 08:50:01 am
content: Quote from: ajb on March 12, 2021, 03:51:57 pmSome micros (for example Silicon Labs ARM family) have rise/fall speed for pin programmable configuration in multiple levels. Very useful thing, fine tuning of signal shape without external resistor.

author: Siwastaja
author_rank: Super Contributor
timestamp: March 13, 2021, 09:08:00 am
content: Quote from: AndersJ on March 13, 2021, 06:41:08 amObviously, uncontrolled current and very likely overcurrent, which affects not only the IO cell transistor, but also can cause internal Vdd node to ripple beyond what it was designed for.Just do not exceed Absolute Maximum Ratings.Remember LEDs havea lotof unit variation in Vf. IO output resistance varies even more. Additionally, LED Vf drops when temperature rises. You easily exceed some 40mA absolute maximum rating even if your single unit on lab table happens to fall below that.A 0402 resistor for an SMD LED doesn't cost basically anything compared to the LED. I'm all for getting rid of "excess" parts but controlling the LED current isn't "excess", the resistor is the simplest way to guarantee maximum LED current for both the LED and the IO port.

author: peter-h
author_rank: Super Contributor
timestamp: March 14, 2021, 08:32:54 pm
content: Resistors in series with signals are used- to reduce the risetime and thus control reflection with very fast signals (e.g. SPI clock) and these need tweaking on the final PCB, with a fast scope and a 1pF active probe; one often uses 22R for this- to reduce EMC (when doing the lab test, if there is a spike rising up through the limit line, just increase the resistor on the offending clock signal or even hang a small cap (few pF) from the signal to GND, close to the driver of course. This is an old trick; EMC compliance is often not pretty- to enable the selection of options at production-time, where otherwise multiple outputs would be driving each other, unless the resistors are selectively populated, and resistors at ~0.1p are a cheap way to install what are basically links (and you can get 0R resistors)- to limit current (I think this reason is very much over-cooked)

author: xtv
author_rank: Contributor
timestamp: March 15, 2021, 01:05:47 pm
content: Quote from: ajb on March 12, 2021, 03:51:57 pmThanks so much for such a detailed explanation

author: kimlanbu
author_rank: Newbie
timestamp: March 16, 2021, 01:20:35 pm
content: Sometimes even resistor is not enough for EMC tests. Some ferride bead needed. You can check AD411 ADC reference design files.

author: SiliconWizard
author_rank: Super Contributor
timestamp: March 16, 2021, 05:54:29 pm
content: Quote from: rstofer on March 12, 2021, 08:08:24 pmJust one obvious thing to consider when using series resistors with digital I/Os is the low-pass filtering they will introduce.A 200 ohm series resistor, if the load has a typical 10 pF capacitance, that's an Fc of ~80 MHz. So that will significantly limit your bandwidth. Of course, for low bandwidth purposes (for instance, IOs typically broken out to PMOD connectors are not meant for high-speed stuff), that's fine.