C1210 of 55
0 XP
  1. Hook
  2. Problems

C12 · Problem set 2

Problem set 2: inputs, debouncing and debugging

These problems use lessons 7 to 9: digital inputs and pull-ups, debouncing, and debugging. The board runs from 3.3 V; a pin reads 1 above 0.7 × 3.3 = 2.31 V and 0 below 0.3 × 3.3 = 0.99 V. It runs at 10 MHz, one instruction per cycle, and its memory is little-endian.

Check

A keypad has 8 buttons, each pulling its own 4.7 kΩ pull-up to ground when pressed. A user holds one down for 24 hours a day.

(a)

What current does a pressed button draw?

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

(b)

How much charge does that take from the battery each day?

(c)

What if all 8 were held at once?

Check

A 12 V logic signal must drive a 3.3 V pin through a divider: 10 kΩ in series, then a resistor to ground. Its high level should land at 3.0 V.

(a)

What resistor to ground?

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

(b)

What source resistance does the pin then see?

Check

An open-drain line has a 4.7 kΩ pull-up to 3.3 V and 50 pF of capacitance. It's released from 0 V.

(a)

How long until it reads 1?

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

(b)

If the line must be high at least half of each period and the rise takes up all of that half, what is the fastest square wave it can carry?

Check

A pin leaks up to 1 µA to ground, and its pull-up is 100 kΩ.

(a)

What voltage does the released pin sit at?

Write units the way you normally would: 1.5 V, 1500 mV and 0.0015 kV are the same answer.

(b)

Does it still read 1 (1 for yes)?

(c)

What is the largest pull-up that keeps it reading 1?

Check

A button discharges a capacitor of 0.1 µF through 47 kΩ as a hardware debouncer; the pin starts at 3.3 V.

(a)

How long after the press does the pin fall below 0.99 V?

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

(b)

If a bounce opens the contact once the pin has reached 0.1 V, how long must it stay open to recharge the pin past 0.99 V? (The pin then charges back toward 3.3 V through the same resistance.)

Check

A counter debouncer samples every 2 ms and accepts a new level after 4 equal samples. A switch bounces for up to 10 ms.

(a)

What is its worst-case delay after the bouncing ends?

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

(b)

And after the first contact?

(c)

If each sample is a 30-cycle timer interrupt, what share of the 10 MHz processor does it take?

Check

A button bounces 10 times on each press and each release, so each press and release makes 1+2k falling edges. A falling-edge interrupt of 40 cycles fires on every falling edge; it's pressed 6 times a second.

(a)

How many falling edges arrive per second?

(b)

What share of the 10 MHz processor do they use?

Check

An array of structs, each 12 bytes, starts at address 8192. A field sits at offset 8 in each struct.

(a)

What address holds the field of element 7?

(b)

A watchpoint covers aligned 4-byte words. What address does it watch?

Check

A conditional breakpoint if (j == 7) sits in an inner loop for j < 20 inside an outer loop for i < 10.

(a)

How many times does it stop?

(b)

How many times would an unconditional one stop?

Check

A memory view shows the bytes 52, 18, 7, 1 (in decimal, lowest address first) at the address of a uint32_t.

(a)

What value does it hold?

(b)

What does a uint16_t at the same address hold?

Check

A control loop has a 20 ms deadline. A debug print of 20 characters at 9600 baud is added to it, waiting for each character.

(a)

How long does the print take?

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

(b)

Does the print alone fit in the deadline (1 for yes)?

Check

A stack of 1024 bytes is painted at reset. After testing, 200 bytes at the bottom are untouched. The team wants a 50% margin over the high-water mark.

(a)

What is the high-water mark?

(b)

What stack size meets the margin?

(c)

How much RAM does resizing free (negative if more is needed)?

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.