C1251 of 55
0 XP
  1. Hook
  2. Problems

C12 · Problem set 11

Problem set 11: languages, testing and whole-system design

These problems use lessons 49 and 50, comparing MicroPython and C and testing embedded code, and then draw on the whole course for design questions. MicroPython hardware calls take about 40 µs; C runs one instruction per cycle at 10 MHz; the board draws about 2 mA awake.

Check

A job makes 50 hardware calls, 10 times a second. In MicroPython each call takes 40 µs; in C each takes 10 instructions. The board draws 2 mA at 3.3 V while awake.

(a)

What average power does the MicroPython version spend awake?

Write units the way you normally would: 1.5 µW, 1500 nW and 0.0015 mW are the same answer.

(b)

How many times less awake time does C need?

Check

A chip has 512 KB of flash and 8 KB of RAM. MicroPython needs about 256 KB of flash and 16 KB of RAM before any program.

(a)

Can it run MicroPython (1 for yes)?

(b)

If so, how much RAM is left for the program and its heap (0 if not)?

Check

A chip with 256 KB of flash keeps a 16 KB bootloader and two equal firmware slots (A and B) for safe updates; 8 KB is reserved for a settings log.

(a)

How large can the firmware image be?

(b)

How long does writing a full image take, at 0.5 ms per 256-byte page plus 30 ms per 4 KB sector erased?

Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.

Check

A conversion function takes a 12-bit input; each test on the board takes 5 µs.

(a)

How long would testing every input take?

Write units the way you normally would: 1.5 s and 1500 ms are the same answer.

(b)

How many tests are 0, 1, the two values around the middle, and the two at the top?

Check

An intermittent bug shows up in each test run with probability 0.05.

(a)

How many runs give a 0.99 chance of seeing it at least once?

(b)

How many runs does it take on average to see it the first time?

Check

A test checks a Q-format result (with 12 fraction bits) against a floating-point reference after 1 rounding step(s), each off by at most half an LSB.

(a)

What tolerance should the test allow?

(b)

In units of the last bit?

Check

An ISR's cycle budget is 300 cycles, and the team wants 10% margin. A test measures it at 700 cycles.

(a)

Does it pass (1 for yes)?

(b)

What is the most it may take?

Check

In a MicroPython program, a fraction 0.8 of the time is spent in one loop, which is rewritten in C and runs 20 times faster.

(a)

What is the whole program's speedup?

(b)

What is the most it could ever gain, however fast the C?

Check

A logger stores 8-byte records 1 times a second in 4 MB of flash.

(a)

How many days does the flash hold?

(b)

Does it hold 365 days without wrapping (1 for yes)?

Check

A sensor event's path: acquisition (0.01 ms), conversion and filtering (0.5 ms), a main loop that may be away for up to 5 ms, and a UART report (2 ms).

(a)

What is the worst-case latency from event to report?

Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.

(b)

What share of it is the main loop's wait?

Check

A state machine with 4 states and 3 events is tested off the board in a simulation that runs each transition test in 10 µs, against 20 ms each on the board.

(a)

How many transition tests are there?

(b)

How many times faster is the simulation?

Check

A MicroPython program allocates 100 small objects a second; each garbage collection pauses it for 2 ms and happens every 16 KB of allocations, each object taking 32 bytes.

(a)

How often does it collect?

(b)

What jitter does that add to a periodic task?

Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.

Have paper and a calculator ready. Work each problem out by hand, then enter the answer. Your first try on each one counts toward your score.

Practice

Keep practicing

15 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.