Microcontrollers: a whole computer on one chip
لم يُترجم بعد؛ يُعرض باللغة الإنجليزية
A microcontroller packs a CPU core, flash for the program, SRAM for variables, timers, GPIO pins, an ADC and serial ports into one chip. Open one up, watch the CPU fetch from flash and store in SRAM, then run a tiny MicroPython loop that writes a register bit to blink an LED, reads a button through the input register, and finally sleeps to save power. Numbers come from the ATmega328P (Arduino Uno) and RP2040 (Raspberry Pi Pico) datasheets.
5 أسئلة سريعة
اختر إجابة لتعرف السبب. تُحفَظ نتيجتك مع تقدّمك.
01Which part of a microcontroller keeps the program when the power is switched off?
Flash is non-volatile: it keeps its contents without power, so the program is still there at the next power-up. SRAM loses everything when the power goes.
02The LED is on pin 5. What does led.toggle() change inside the chip?
Each bit of the output register drives one pin. Flipping bit 5 switches pin 5 between high and low, so current flows through the LED or stops.
03The button pin has a pull-up resistor and the button connects it to ground. What does btn.value() return while the button is pressed?
The pull-up holds the pin at 1 while the button is released. Pressing connects the pin to ground, so its bit in the input register reads 0.
04The ATmega328P has a 10-bit ADC. What range of numbers can one reading have?
10 bits give 2^10 = 1024 different values, from 0 to 1023. A 12-bit ADC, like the RP2040's, gives 0 to 4095.
05Why can a microcontroller run for months on a small battery?
Most of the time there is nothing to do, so the chip sleeps. An interrupt, such as a button press, wakes it to do a short job before it sleeps again.
المسرد
- Microcontroller
- A small computer on one chip: a CPU core, program memory, working memory and peripherals such as timers, pins and an ADC.
- Flash memory
- Non-volatile memory that keeps the program when the power is off.
- SRAM
- Static RAM: fast working memory for variables while the program runs; it forgets everything without power.
- GPIO
- General-purpose input/output: pins the program can drive high or low, or read.
- Register
- A tiny memory cell wired straight to hardware; in a GPIO register, each bit belongs to one pin.
- Pull-up resistor
- A resistor from a pin to the supply that holds an unconnected input at 1.
- ADC
- Analog-to-digital converter: turns a voltage into a number, for example 0 to 1023 for 10 bits.
- Sleep mode
- A low-power state in which the chip stops its clocks until something, such as an interrupt, wakes it.
الملاحظات والمصادر
- The figure is a generic microcontroller drawn as a teaching model: one chip with a CPU core, flash, SRAM, a timer, GPIO, an ADC and a UART, wired to an LED, a button and a dial. Real chips have more of each.
- Sizes, speeds and currents are the ATmega328P's (the Arduino Uno's chip) from the Microchip datasheet; the currents are measured at 1 MHz, 1.8 V and 25 °C, and grow with clock speed and supply voltage.
- The code card is MicroPython (machine.Pin and time.sleep_ms). It runs on larger chips such as the RP2040; on an Arduino Uno the same loop is usually written in C++.
- The output and input registers are shown as one 8-bit port with the LED on bit 5 and the button on bit 2; the other bits are unused here. The ATmega328P names them PORTB and PINB, the RP2040 GPIO_OUT and GPIO_IN.
- RP2040: 2 Arm Cortex-M0+ cores at up to 133 MHz and 264 kB of SRAM; its program flash is a separate chip on the board (up to 16 MB).
اختبار يتاح بعد الخطوة الأخيرة.