Kiến trúc vi điều khiển
Đã giới thiệuTrong bài học này
| English | Ý nghĩa |
|---|---|
| microcontroller/ˈmaɪkrəʊkəntrəʊlə/ | vi điều khiển |
| bus/bʌs/ | |
| fetch-decode-execute cycle/fetʃ dɪˈkəʊd ˈeksɪkjuːt ˈsaɪkl/ | Chu kỳ lấy mã, giải mã, thực thi |
| program counter/ˈprəʊɡræm ˈkaʊntə/ | bộ đếm chương trình |
| clock/klɒk/ | đồng hồ |
| memory map/ˈmeməri mæp/ | Bản đồ bộ nhớ |
A computer the size of a grain of rice
- A thermostat, an anti-lock brake controller and a wireless earbud each contain a complete computer on one tiny chip, costing less than the postage to ship it.
- This lesson opens that chip: what is inside, how it runs a program, and how fast.
Three parts on one chip
- A microcontroller 微控制器 puts flash memory (the program), SRAM (the data) and a CPU on one chip, together with peripherals for the outside world.
- Every transfer between them travels on a bus 总线: address lines say where, data lines carry what, control lines say read or write.
Nối mỗi bộ phận của vi điều khiển với chức năng hoặc dữ liệu mà nó lưu giữ.
Độ khó 2/5 · 140 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Cả bốn thành phần đều nằm trên một chip, đó là lý do vi điều khiển có giá rẻ và kích thước nhỏ gọn.
Fetch, decode, execute
- The CPU repeats the fetch-decode-execute cycle 取指译码执行周期. The program counter 程序计数器 (PC) holds the address of the next instruction; the CPU fetches it, decodes it and executes it.
- Then the PC moves on, or jumps for a branch. The clock 时钟 paces every step.

Sắp xếp theo thứ tự chu kỳ của một chỉ thị.
Độ khó 3/5 · 200 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Chu kỳ sau đó lặp lại tại giá trị PC mới, một lần cho mỗi chỉ thị.
The memory map
- An $N$-bit address reaches $2^{N}$ locations, so a memory of a given size needs $N = \log_{2}(\text{size})$ address lines.
- Each region of the memory map 存储器映射 sits at its own base address. Regions whose top address bits differ can never overlap.
Flash tại 0x0000_0000 và SRAM tại 0x2000_0000 có thể trùng nhau nếu flash đủ lớn.
Độ khó 1/5 · 100 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Các vùng này khác nhau ở bit địa chỉ cao nhất, nên không có địa chỉ nào thuộc về cả hai; bộ giải mã tách chúng dựa vào những bit đó.
Worked example: sizing the map
- 64 KB of flash is $2^{16}$ bytes: 16 address lines, from
0x0000_0000to0x0000_FFFF. - 8 KB of SRAM is $2^{13}$ bytes: 13 lines, from
0x2000_0000to0x2000_1FFF. The top bits differ, so the two can never collide.
Which byte does this address select?
$address=base+offset,\quad N=\lceil\log_2(size\ in\ bytes)\rceil$
Compare the worked 64 KiB flash and 8 KiB SRAM regions. Move from the last mapped byte to the next address, separate the base from the offset bits, and explore why 96 KiB needs 17 offset bits but leaves 32 KiB unused in its address window.
8 KB SRAM cần bao nhiêu đường dẫn địa chỉ?
Độ khó 1/5 · 100 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
$8\,\text{KB} = 8192 = 2^{13}$ byte, vì vậy 13 đường; nó trải dài từ 0x2000_0000 đến 0x2000_1FFF.
32 KB flash bắt đầu từ địa chỉ 0. Địa chỉ cuối cùng của nó là gì, theo thập phân?
Độ khó 2/5 · 140 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
$32\,\text{KB} = 32\,768$ byte, được đánh số từ 0 đến 32 767, tức là 0x7FFF.
Worked example: the time per instruction
- At 84 MHz and about one instruction per cycle, one instruction takes $\dfrac{1}{84 \times 10^{6}} = 11.9\,\text{ns}$.
- A 100-instruction control pass takes 1.19 µs, so a 1 ms control period has room for about 840 such passes. This budget arithmetic returns in every later lesson.
Tại 84 MHz, một chỉ thị mỗi chu kỳ, một thủ tục gồm 100 chỉ thị mất khoảng
Độ khó 1/5 · 100 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
$100 \times 11.9\,\text{ns} = 1.19\,\mu$s.
Three common slips
- Address lines for data width. Address lines count locations; data lines set how wide each one is.
- Bits for bytes. Flash is sized in bytes; mixing them is a factor of eight.
- Assuming a boot address. The vendor fixes the map; the linker script must match it.
Một CPU 48 MHz chạy một chương trình điều khiển 240 lệnh (một lệnh mỗi chu kỳ). Nó có thể thực hiện bao nhiêu lần trong một miligiây?
Độ khó 2/5 · 140 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
$48\,000$ chu kỳ mỗi miligiây chia cho 240 chu kỳ mỗi lần thực hiện sẽ cho ra 200 lần thực hiện.
Recap
- Flash, SRAM and CPU on one chip, joined by the bus and paced by the clock:
| Flash | SRAM | |
|---|---|---|
| Holds | the program | the data |
| Size here | 64 KB: 16 address lines | 8 KB: 13 address lines |
| After power off | kept | lost |
- Fetch, decode, execute, advance the PC; repeat.
- $N$ address lines reach $2^{N}$ bytes; the clock turns instruction counts into time.
Đã xảy ra vấn đề gì? Chỉ đội ngũ trang web nhìn thấy thông tin này.