C12 Embedded systems in MicroPython and C · Practice
Comparing MicroPython and C
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
A MicroPython job makes 1000 hardware calls at 40 µs each. How long do they take?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
A C loop makes 1000 hardware accesses at 5 cycles each, at 10 MHz. How long do they take?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
A hardware access takes 40 µs in MicroPython and 7 cycles (100 ns each) in C. How many times faster is C?
Check
A chip has 256 KB of flash, and the MicroPython interpreter needs 256 KB. How much flash is left for everything else (negative if it doesn't fit)?
Check
A job runs 10 times a second, awake 0.5 ms per run in MicroPython or 0.05 ms in C, at 2 mA awake. How much more average current does the MicroPython version draw (sleep current aside)?
Write units the way you normally would: 1.5 mA, 1500 µA and 0.0015 A are the same answer.
Check
A job makes 1000 hardware calls: about 40 µs each in MicroPython, or 10 instructions each in C on the 10 MHz board.
(a)
How long does it take in MicroPython?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
How many times faster is the C version?
Check
A sensor job runs 10 times a second and takes 1 ms in MicroPython.
(a)
What share of the time is MicroPython busy?
(b)
Does it fit at all (1 for yes)?
Check
Time for 500 MicroPython hardware calls?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
Time for 300 C accesses at 6 cycles?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
Speedup of C at 4 cycles per access over 40 µs?
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in C12