C126 of 55
0 XP
  1. Hook
  2. Problems

C12 · Problem set 1

Problem set 1: the board, blinking, bits and memory

These problems use lessons 1 to 5: the board and its datasheet, blinking in MicroPython and in C, the C habits of fixed-width types, bit operations and volatile, and budgeting flash, RAM and the stack. The board runs at 10 MHz, one instruction per cycle; each MicroPython call into the hardware takes about 40 µs.

Check

An LED with a 2.1 V forward voltage must carry 2 mA from a 3.3 V pin.

(a)

What series resistor does it need?

Write units the way you normally would: 1.5 Ω, 1500 mΩ and 0.0015 kΩ are the same answer.

(b)

Each on its own pin, how many such LEDs fit within the 50 mA package limit?

Check

A delay must last 400 µs, built from a loop of 4 cycles per pass.

(a)

How many clock cycles is that?

(b)

About how many passes does the loop need?

Check

A peripheral starts at 40002000; a register sits at offset 4 (decimal).

(a)

What's the register's address, in hex?

(b)

Counting from 0x4000_0000 in 4 KiB blocks, which block number is the peripheral in?

Check

A program drives P2 and P5.

(a)

What mask selects both pins, in hex?

(b)

What's ~mask & 0xFFFF, the mask of every other pin, in hex?

Check

A C loop toggles a pin once per pass, 4 cycles per pass; a MicroPython loop toggles it with 2 hardware calls per pass.

(a)

What frequency does the C loop make?

Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.

(b)

And the MicroPython loop?

Check

An LED blinks at 4 Hz with a 10% duty cycle.

(a)

How long is it on each period?

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

(b)

And off?

Check

A fixed-sleep loop sleeps 250 ms and makes 3 hardware calls (40 µs each) per pass.

(a)

How long is each pass?

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

(b)

Compared with an exact 250 ms grid, how far behind is it after an hour of passes?

Check

A uint8_t holds 230; 90 is added to it.

(a)

What does it hold?

(b)

What would a uint16_t hold?

Check

A register holds C3F0.

(a)

What's the 4-bit field at bit 4, in hex?

(b)

What's the register after writing 9 into that field, in hex?

Check

A field is 10 bits wide.

(a)

What's the largest value it holds?

(b)

What's that value times 1?

Check

A table holds 50 values of 2 bytes each, and the board has 60 KiB of RAM.

(a)

How many bytes does it take?

(b)

What percentage of the RAM is that?

Check

A C register write takes 3 instructions; a MicroPython one takes 40 µs. A task makes 20 thousand writes.

(a)

How long does it take in C?

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

(b)

And in MicroPython?

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.