สถาปัตยกรรมไมโครคอนโทรลเลอร์
แนะนำใหม่ในบทเรียนนี้
| English | ความหมาย |
|---|---|
| microcontroller/ˈmaɪkrəʊkəntrəʊlə/ | ไมโครคอนโทรลเลอร์ |
| bus/bʌs/ | บัส |
| fetch-decode-execute cycle/fetʃ dɪˈkəʊd ˈeksɪkjuːt ˈsaɪkl/ | รอบการดึงคำสั่ง-แปลผล-ดำเนินการ |
| program counter/ˈprəʊɡræm ˈkaʊntə/ | ตัวนับโปรแกรม |
| clock/klɒk/ | นาฬิกา (Clock) |
| memory map/ˈmeməri mæp/ | แผนที่หน่วยความจำ |
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.
จับคู่แต่ละส่วนของไมโครคอนโทรลเลอร์กับสิ่งที่มันจัดเก็บหรือทำงาน
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
ทั้งสี่ส่วนนี้อยู่บนชิปเดียวกัน ซึ่งเป็นสาเหตุที่ทำให้ไมโครคอนโทรลเลอร์มีขนาดเล็กและมีราคาถูก
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.

จัดลำดับรอบของคำสั่งหนึ่งให้เสร็จสิ้น
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
จากนั้นรอบการทำงานจะเริ่มซ้ำที่ค่า PC ใหม่ โดยทำเพียงครั้งต่อหนึ่งคำสั่ง
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 ที่ 0x0000_0000 และ SRAM ที่ 0x2000_0000 สามารถทับซ้อนกันได้หาก Flash มีขนาดใหญ่พอ
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
พื้นที่เหล่านี้แตกต่างกันที่บิตที่อยู่ด้านบน ดังนั้นไม่มีที่อยู่ใดที่จะเป็นของทั้งสองได้ ตัวถอดรหัสจะแยกพื้นที่ออกจากกันโดยใช้บิตเหล่านี้
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.
SRAM ขนาด 8 KB ต้องการสายที่อยู่จำนวนเท่าไหร่?
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
$8\,\text{KB} = 8192 = 2^{13}$ ไบต์ ต้องใช้สายที่อยู่ 13 เส้น; ครอบคลุมตั้งแต่ 0x2000_0000 ถึง 0x2000_1FFF
32 KB ของ Flash เริ่มต้นที่ที่อยู่ 0 ที่อยู่สุดท้ายของมันคืออะไร ในฐานสิบ?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
$32\,\text{KB} = 32\,768$ ไบต์ มีหมายเลข 0 ถึง 32 ซึ่งเท่ากับ 767 คือ 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.
At 84 MHz, one instruction per cycle, a 100-instruction routine takes about
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
$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.
CPU ความเร็ว 48 MHz ทำงาน routine ควบคุมที่มีคำสั่ง 240 คำสั่ง (ดึงหนึ่งคำสั่งต่อรอบ) สามารถทำงานได้กี่ครั้งในหนึ่งมิลลิวินาที?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
$48\,000$ รอบต่อนาที divided by 240 รอบต่อรอบทำงาน ให้ 200 รอบการทำงาน
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.
เกิดปัญหาอะไรขึ้น? เฉพาะทีมเว็บไซต์เท่านั้นที่เห็นข้อมูลนี้