A microcontroller, or MCU, controls hardware that is responsible for implementing device commands. It receives inputs from switches, buttons, sensors and other components and controls peripheral circuitry like displays and motors as per its set program instructions. Most modern electronic devices include at least one or two microcontrollers. For instance, they are used in cell phones, household appliances, washers, refrigerators and toys. The presence of microcontrollers in devices makes it easy to change operations in real-time as well as add new device functionalities.
A typical MCU is made up of a CPU, memory, and circuitry that work together to implement peripheral functionalities. The CPU thinks, the memory stores information, and the circuitry implements the inputs and responses.
The CPU: The Microcontroller’s “thinker”
The CPU’s operations are determined by a program or a predefined set of instructions that are stored in a memory. Being the MCU’s “thinker” does not mean that the CPU can carry out its independent line of thoughts or actions. The CPU is tasked to read and execute the instructions in a predefined order. A typical instruction tells the CPU to read data from a certain address within the memory or to multiply values and so forth. Though the instructions are simple, they are used to drive numerous and sometimes complicated device functionalities.
Components of a CPU include:
- A PC (program counter),an internal register that stores memory for the next instructions the CPU is required to execute. The PC value increases by 1 each time a CPU instruction is executed successfully. It starts at 0000 and advances to 0001 and so on.
- The instruction decoder decodes each of the instructions that are read from the memory and utilizes the results to drive the operational and arithmetic circuitry.
- The arithmetic and logic unit, a circuitry that handles logical and arithmetic operations. Arithmetic operations include multiplication and addition, while logical operations include bit shifts, OR and AND.
- CPU internal registers, which hold transient information.
Memory: Information Storage
The microcontroller’s memory is used to store program data and codes. There are two types of memory: ROM and RAM. ROM is the read-only memory that is capable of retaining content when power is disconnected and cannot be overwritten or erased. Therefore, it is mainly used to store start-up commands that are implemented immediately when power is restored and constant values that can be easily accessed by running programs.
RAM is the random access memory that can be rewritten freely but loses data once power is disconnected. Hence, it is ideal for storing program variables. MCU’s utilize static RAM for internal RAM because it offers faster access and does not require to be refreshed regularly.
Combined, the CPU, memory, and circuitry of a microcontroller allow it to efficiently control hardware and play a significant role in many electronics that we use every day.