MicroPython¶
1. Blink in 1 core¶
main.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 |
|
2. Blink in 2 core¶
Note
This code doesn’t work in Wokwi, and not tested in a board
main.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
3-1-1. Blink in PIO¶
Ref. Recitation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
Note
nop()
is a “No Operation” instruction that does nothing.
[31]
specifies that the instruction should wait for 31 cycles after execution.
If the PIO state machine clock is 2000 Hz (2 kHz), then one cycle takes:
$$
\frac{1}{2000} = 0.0005 \text{ seconds (0.5ms)}
$$
Waiting for 31 cycles results in:
$$
0.5 \times 31 = 15.5 \text{ ms}
$$
→ This creates a delay of approximately 15.5ms.
nop()
は 「何もしない (No Operation)」命令
[31]
は 「この命令の実行後に 31 サイクル待機する」 という指定
PIO ステートマシンのクロックが 2000 Hz (2 kHz) なら、1サイクルは
$$
\frac{1}{2000} = 0.0005 \text{ 秒 (0.5ms)}
$$
31 サイクル待機すると
$$
0.5 \times 31 = 15.5 \text{ ms}
$$
→ 約 15.5ms の遅延 を作れる。
3-1-2. Blink in PIO¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
3-2. Blink in 2 state machines of PIO¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
3-3. Blink in 3 state machines of PIO¶
Note
This code doesn’t work in Wokwi, and not tested in a board
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
4. Blink in 1 core and 2 state machines of PIO¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|