C12 · Midterm exam
Midterm exam: the board, inputs, timing, interrupts and analog
Twelve problems from the first half of the course: the board and its datasheet, blinking in MicroPython and C, bits and volatile, memory budgets, inputs and pull-ups, debouncing, debugging, timers, interrupts, input capture, the ADC and its input, fixed point, filtering, PWM and driving loads, sound and the DAC. The board runs at 10 MHz, one instruction per cycle; MicroPython hardware calls take about 40 µs. Give yourself two hours, work without the lessons open, and write out your reasoning before checking each answer. "Another set" deals a different exam.
Check
An LED with forward voltage 2 V is driven from a 3.3 V pin through 150 Ω.
(a)
What current does it draw?
Write units the way you normally would: 1.5 mA, 1500 µA and 0.0015 A are the same answer.
(b)
What's its average current with 40% PWM?
Check
A register sits at offset 4 from 40003000, and a program needs a mask for pin P12.
(a)
What's the register's address, in hex?
(b)
What's the mask, in hex?
Check
A MicroPython loop makes 4 hardware calls and sleeps 200 ms each pass.
(a)
How long is a pass?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
How far behind an exact grid is it after 1000 passes?
Check
A uint8_t register holds E7.
(a)
What's bit 1?
(b)
What does it hold after x ^= 1 << 1, in hex?
Check
A pull-up of 10 kΩ charges 30 pF of pin capacitance.
(a)
How long until the pin reads high after release? (kΩ × pF = ns)
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
(b)
What current flows while the button is held?
Check
A button bouncing 3 times each way is pressed 4 times; a debouncer samples every 4 ms and needs 5 equal samples.
(a)
How many falling edges would a naive counter see?
(b)
How long after settling does the debouncer accept a level?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
A timer has PRESCALE = 49 and TOP = 199.
(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's the length of one count?
Check
An ISR of 150 cycles, saving and restoring 16 registers inside that time, fires 4 thousand times a second.
(a)
What share of the processor does it use?
(b)
What share of the ISR's own time is saving and restoring?
Check
A loop reads an array of 20 2-byte elements at 1000, but its test is i <= 20.
(a)
How many elements does it read?
(b)
What address does the extra read come from, in hex?
Check
A thermistor divider (10 kΩ, B = 3950, under a 10 kΩ resistor) gives 1.4 V.
(a)
What's the thermistor's resistance?
Write units the way you normally would: 1.5 kΩ, 1500 Ω and 0.0015 MΩ are the same answer.
(b)
What temperature is that?
Check
The ADC reads 2111.
(a)
What does c * 3300 / 4095 give, in integers?
Write units the way you normally would: 1.5 mV, 1500 µV and 0.0015 V are the same answer.
(b)
And the rounded version, (c * 3300 + 2047) / 4095?
Check
PWM must run at 2000 Hz and 15% duty.
(a)
What's PERIOD?
(b)
And DUTY?
Check
A buzzer must play MIDI note 60.
(a)
What frequency?
Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.
(b)
With PERIOD rounded to a whole number, how many cents off is it?
Check
A DAC plays a 32-sample table at 10000 samples per second; separately, it's asked for 2.2 V.
(a)
What frequency does the table play?
Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.
(b)
What code gives 2.2 V?
Check
count is 12. Main runs count = count + 1 (load, add, store), and 1 ISR increments land between its load and store.
(a)
What is count afterwards?
(b)
What should it be?
Check
A relay coil of 50 mH and 50 Ω and a motor drawing 2 A are both switched from GPIO through low-side MOSFETs with 80 mΩ on-resistance.
(a)
With a flyback diode, what is the coil current's decay time constant at turn-off?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
What does the motor's MOSFET dissipate when on?
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
16 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.