What is a microcontroller?
What is a microcontroller, and how does it work?
Dear colleagues,
A microcontroller, commonly abbreviated to MCU, is a programmable integrated circuit designed to perform particular tasks within a device. It combines a processor core, memory and various peripherals on one chip. It reads inputs, applies rules defined by software and controls outputs. A temperature controller that measures a sensor, switches a fan and updates a display is a typical example.
The hardware alone does not know what action to take. Its behaviour depends on the embedded software, or firmware, stored in memory and on the surrounding circuitry. The same microcontroller can serve in a counter, a motor control board or a communication device when equipped with different software.
Microcontroller versus microprocessor
Both a microcontroller and a microprocessor execute instructions. A microcontroller generally integrates memory and peripherals needed for control on the same chip. Microprocessor-based systems may use larger external memories and additional supporting devices. Modern products blur these boundaries, so the category name alone is not enough to determine suitability.
A smartphone's main application processor should not simply be described as a microcontroller. However, a phone or another complex product may contain microcontrollers responsible for power management, sensing or auxiliary control tasks.
What is inside a microcontroller?
CPU — processor core: Executes instructions, performs calculations and manages program flow. Flash memory commonly stores the program, while RAM holds variables and temporary data during operation. Some devices provide EEPROM or other nonvolatile storage for settings. Ordinary RAM loses its contents when power is removed.
GPIO — general-purpose input/output: Used to read switches, change output states or control suitable interfaces. Timers, counters and PWM peripherals can measure intervals, count pulses and generate regular waveforms. The clock source may be an internal oscillator or an external crystal oscillator. Clock frequency influences execution speed, but does not describe the performance of the complete system by itself.
ADCs, DACs and communication interfaces vary between devices. Not every microcontroller includes a DAC, USB, CAN or wireless connectivity. Even members of the same product family may differ in memory capacity, pin count and available peripherals.
How does it read an analog sensor?
The voltage output from a suitable analog sensor can be converted into a digital code by an ADC — analog-to-digital converter. A current-producing detector such as a photodiode generally needs appropriate analog circuitry first. Not every sensor output can connect directly to an ADC pin.
For example, an ideal single-ended 12-bit ADC with a 0–3.3 V input range provides 4096 distinct codes, numbered from 0 to 4095. The ideal step size is approximately 3.3 / 4096 = 0.806 mV. A midrange input of 1.65 V corresponds to approximately code 2048. However, resolution is not measurement accuracy: reference voltage, noise, acquisition time and sensor errors also affect the result.
If the measured DC voltage exceeds the input range, suitable scaling and protection are required. The source impedance of a divider made from resistors, together with any filtering capacitors, can also affect ADC settling time.
Animation: following a sensor signal through an MCU
The red dot represents the sensor signal and the information processed from it. The ADC digitises the input, the CPU uses program instructions and data to make a decision, and the output peripheral controls the LED.
This is not a wiring diagram or a representation of actual processing times. Some peripherals operate independently of the CPU; the animation presents a sequence to make the explanation easier to follow. The LED's current limiting resistor is omitted from the illustration.
Can an output pin drive a motor directly?
A GPIO pin is not a power supply. A small LED may be driven with suitable current limiting and within the pin's ratings. Motors, powerful lighting and coils require a MOSFET, transistor or appropriate driver stage. Inductive loads also require consideration of a suitable diode or another energy clamping arrangement.
Not every pin on a 3.3 V device tolerates 5 V. Tolerance depends on the pin structure and selected operating mode. Analog input limits must be checked separately. A 24 V field signal must not be applied directly to an MCU pin. Use suitable level conversion, input protection and, where required, an isolation solution such as an optocoupler.
How are communication and control decisions handled?
Interfaces such as UART, SPI and I²C exchange data with other devices. In industrial communication, software alone may not be enough. For example, Modbus RTU over RS-485 requires protocol software and a suitable RS-485 transceiver. Wireless designs may use an integrated radio or an external RF module, depending on the selected device.
A simple temperature controller might convert sensor readings into temperature, switch a fan on at 55 °C and switch it off when the temperature falls to 50 °C. These separate thresholds create hysteresis, reducing repeated switching around a single boundary. An ADC code is not itself a temperature; conversion depends on the sensor characteristic and, where necessary, calibration.
Real-time operation means completing a required action within its deadline, rather than simply using a fast processor. Interrupt handling, timers and worst-case software execution times all matter. Long blocking delays and unnecessary processing can postpone the response to an input.