C12 Embedded systems in MicroPython and C · Practice
Problem set 5: analog in and out
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
A sensor puts 1.9 V on an ADC pin.
(a)
What code does the ADC report?
(b)
What does (code * 3300 + 2047) / 4095 give, in integers?
Write units the way you normally would: 1.5 mV, 1500 µV and 0.0015 V are the same answer.
Check
The thermistor divider reads code 2700.
(a)
What's the thermistor's resistance? (V cancels: .)
Write units the way you normally would: 1.5 kΩ, 1500 Ω and 0.0015 MΩ are the same answer.
(b)
What's the temperature?
Check
Single ADC readings scatter with a standard deviation of 8 codes; the program averages 16.
(a)
What's the scatter of the average, in codes?
(b)
How long do the conversions take, at 10 µs each?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
A value 2.6 is stored in a Q format with 8 fraction bits.
(a)
What integer stores it?
(b)
What's the format's resolution?
Check
A table maps code 1357 to 100 tenths of a degree and 1817 to 200.
(a)
What does code 1500 interpolate to, in integer arithmetic?
(b)
What's the largest intermediate product the calculation can reach in this segment?
Check
A motor runs from 12 V through a transistor switched by PWM at 1000 Hz and 30% duty.
(a)
What average voltage does it see?
Write units the way you normally would: 1.5 V, 1500 mV and 0.0015 kV are the same answer.
(b)
What DUTY register value gives that, with PERIOD set for 1000 Hz?
Check
PWM must run at 20000 Hz.
(a)
What PERIOD does it need?
(b)
How many bits of duty resolution does that leave?
Check
A tune needs MIDI note 67.
(a)
What's its frequency?
Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.
(b)
What PWM PERIOD plays it?
Check
A melody at 80 beats per minute has a note of 0.25 beats, followed by a 40 ms gap that's part of the note's time.
(a)
How long is the note's whole slot?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
How long does the tone actually sound?
Check
A 64-sample waveform table is played at 8000 samples per second.
(a)
What frequency results?
Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.
(b)
With PRESCALE = 0, what timer TOP sets that sample rate?
Check
A phase accumulator updates at 10000 Hz.
(a)
What 32-bit step gives 261.6 Hz?
(b)
What's its frequency resolution?
Write units the way you normally would: 1.5 µHz, 1500 nHz and 0.0015 mHz are the same answer.
Check
The DAC must output 1650 mV.
(a)
What does (m * 4095 + 1650) / 3300 give, in integers?
(b)
What voltage does that code actually produce?
Write units the way you normally would: 1.5 mV, 1500 µV and 0.0015 V are the same answer.
Check
A 47 kΩ source drives an ADC that samples onto 10 pF through 1 kΩ, with 10 µs of acquisition time.
(a)
What acquisition time does 12-bit settling need?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
(b)
Is 10 µs enough (1 for yes)?
Check
An NPN switches a 12 V, 50 Ω solenoid from a 3.3 V pin with a forced β of 20; the pin may source 8 mA.
(a)
What base current does it need?
Write units the way you normally would: 1.5 mA, 1500 µA and 0.0015 A are the same answer.
(b)
Can the pin supply it (1 for yes)?
Check
Readings with 5 codes of rms noise pass through either an 8-sample moving average or a smoother with .
(a)
How much noise does the moving average leave?
(b)
And the smoother?
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in C12