For the longest time I have been instructed to put on 100nF decoupling capacitors between the VCC and GND pins whenever I lay out a board involving an MCU. I could not find the exact reason as to why they are needed. However, after some research online I did find a few reasons for their use. Below I explain the main reason, as I understand it, why decoupling capacitors are needed. I would like some feedback and would also like to know if this explaination is satisfactory or not.
Consider a pin of an MCU which has a single LED connected to it through a resistor. Lets say that the pin toggles from low to high, that is it turns the LED on. Now with the LED on, it will draw current which the MCU will have to provide. In return, the MCU draws more current (i.e power) from the power supply i.e. its VCC and GND pins. However, a sudden current draw by the power pins causes a voltage drop across the resistance of the power traces. Since the power supply is slow as compared to the microcontroller, it senses the drop in voltage after a little time and then changes the voltage back to its constant value again ( since it is to behave as a constant voltage source). That is where the decoupling capacitors come in. Whenever the MCU draws in a current pulse, the capacitor makes sure that the voltage across the power pins remain essentially constant till the power supply voltage stabilizes again.
That is all I have understood. Now I do not know how to calculate the exact value of the decoupling capacitor but have been told that 100nF or any value in that neighbourhood is pretty safe to use.
I am waiting for your comments.