C1214 of 55
0 XP
  1. Hook
  2. Problems

C12 · Problem set 3

Problem set 3: inputs, timers and interrupts

These problems use lessons 7 to 13: inputs and pull-ups, debouncing, debugging, timers, interrupts, and input capture and encoders. The clock is 10 MHz; the timer counts every PRESCALE + 1 cycles and wraps after TOP + 1 counts.

Check

A button to ground has a 40 kΩ pull-up; the pin and its wire have 20 pF.

(a)

What current flows while it's pressed?

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

(b)

After release, how long until the pin crosses 70% of 3.3 V?

Check

A button's contacts bounce 2 times on every press and on every release; it's pressed 5 times.

(a)

How many falling edges does a fast program see?

(b)

How many does a correct debouncer count?

Check

A debouncer samples every 2 ms and accepts a level after 4 equal samples; the bounce lasts 8 ms.

(a)

How long does it take to accept a settled level?

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

(b)

About how long after the first contact does it report the press?

Check

An array of 16 elements of 2 bytes starts at 1000, and a loop runs from 0 to 16 inclusive.

(a)

What address does its last pass read, in hex?

(b)

How many bytes past the end of the array does that read start?

Check

A timer has PRESCALE = 99 and TOP = 499, and a pin toggles at each wrap.

(a)

How long between wraps?

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

(b)

What frequency is the pin's square wave?

Check

A pin must square-wave at 1000 Hz from a timer with PRESCALE = 0.

(a)

What TOP comes closest?

(b)

What frequency does it actually make?

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

Check

An ISR takes 300 cycles and fires 2 thousand times a second.

(a)

What share of the processor does it use?

(b)

What rate would use all of it?

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

Check

An ISR saves and restores 6 registers and takes 3 cycles to reach its first useful instruction after that.

(a)

How many cycles from entering the ISR to its first useful instruction?

(b)

And in microseconds?

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

Check

count is 19. While main does count = count + 1 (load, add, store), 2 ISR increments land between its load and its store.

(a)

What is count afterwards?

(b)

How many increments were lost?

Check

A 32-bit cycle counter read 4294966000 at one event and 300 at the next, wrapping in between.

(a)

How many cycles passed?

(b)

How long is that?

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

Check

A debug print sends 30 characters over the UART at 9600 baud, waiting for each.

(a)

How long does it take?

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

(b)

How many clock cycles is that?

Check

A breakpoint sits in the innermost of three nested loops of 3, 10 and 4 passes.

(a)

How many times does it stop the program?

(b)

And a breakpoint in the middle loop's body, outside the inner loop?

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.