Resistance Is Futile
I last talked about how our usual abstraction for the simplest circuit component — wire — can cause problems in certain designs. The problem isn't limited to just wires. Every electronic component you use in an embedded system (or any circuit, really) has differences from its ideal abstraction we use to make life simpler.
Consider an ordinary resistor. Nothing could be easier than that, right? That depends. One common mistake I see, on occasion, is not accounting for power dissipation of a resistor.
Consider a 2-volt LED and a 5-volt supply. The dropping resistor has to drop 3 volts (5-2), so a 60-ohm resistor would set the LED current to 50mA. There are two things to think about. First, the power through the resistor is .05 times 3 or 0.15 (150 mW). That's fine for a 1/4W (0.25W) resistor. But for a 1/8 (0.125) watt resistor, you'll exceed its rating.
The other thing to consider is where the resistor will be used. A high ambient temperature, or a confined area, can require you to derate the resistor quite a bit. Resistor vendors offer guidance on exactly how to pick a resistor that will be confined or in a hot environment (for example, see this document from Ohmite).
Usually you want some margin, too. Ideally, you should look at the lowest possible value for the resistor to look at the power dissipation. For example, if you are using 10% tolerance resistors, you can't really get a 60-ohm resistor. What you can get is a 56-ohm resistor (or a 68 ohm, but let's stick with 56 for now).
The real value of the resistor will be between 50.4 ohms and 61.6 ohms. In fact, since most manufacturers "cherry pick" higher tolerance resistors, it is almost certain that none of them will really be 56 ohms because if they were, they'd be marked as 1% resistors or better. So the maximum current will occur at 50.4 ohms (59.5mA). That's more than 20mW power (0.178W).
So even a simple resistor needs more care than meets the eye. What's worse is that many common things we think are resistors are really resistors with something else added in. For example, many power resistors are constructed of resistive wire wound around an insulating core (a wirewound resistor). This is great for getting a long length of wire into a small space. It also makes an inductor.
Inductors can create large voltage spikes based on how fast the current through them changes. That's how ignition coils in a car work, for example. If you've used a relay, the electromagnet in the relay is an inductor, and the "flyback" diode prevents the voltage spike from damaging the other circuits. This same effect can be a problem with wirewound resistors. You can find "non-inductive" wirewound resistors where the windings are constructed in such a way that the unintended inductance is reduced.
In general, most materials have a higher resistance as they get hotter. Passing current through a resistor makes it hotter, so the resistance will increase as it warms up. For a standard resistor, the effect is fairly small, but for some components made to run hot, the effect is magnified. For example, light bulbs or heaters can draw several times their rated current until they reach operating temperature (this is known as inrush current). A drive circuit that can handle 100mA load might fail if that load draws many times that amount of current until it gets warm.
Abstractions make things simple, but sometimes you have to dig under the abstractions and understand what really happens so you can design an embedded system that works.