C12 Embedded systems in MicroPython and C · Practice
PWM: dimming LEDs and driving motors
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 pin switches between 0 and 5 V at 15% duty. What's the average voltage?
Write units the way you normally would: 1.5 V, 1500 mV and 0.0015 kV are the same answer.
Check
What PWM PERIOD, in clock cycles, gives 20000 Hz?
Check
With PERIOD = 500, how many bits of duty resolution does the PWM have?
Check
With PERIOD = 1000, what DUTY value gives 12.5%?
Check
MicroPython's duty_u16(d) takes d from 0 to 65535. What duty cycle is duty_u16(32768)?
Check
Drive the LED on P1 with PWM at 5000 Hz and 25% duty.
MicroPython on the course's board: machine (Pin, PWM, ADC, DAC, UART, I2C, SPI, Timer, WDT) and time. Each call into the hardware takes about 40 µs. Tab indents; press Esc and then Tab to move on.
Check
Run the motor on P2 at D% (20%) of full speed using PWM channel 2 at F Hz (4000 Hz), writing the PWM registers directly.
C on the course's RISC-V board (10 MHz, no floating point). #include "board.h" for the registers; print(x) shows a number. Tab indents; press Esc and then Tab to move on.
Check
PWM on the 10 MHz board runs at 1000 Hz.
(a)
What PERIOD?
(b)
How many bits of duty resolution?
Check
PWM with PERIOD = 10000 drives a load that draws 20 mA when on, at 10% duty.
(a)
What DUTY value?
(b)
What average current?
Write units the way you normally would: 1.5 mA, 1500 µA and 0.0015 A are the same answer.
Check
Average of 9 V at 30% duty?
Write units the way you normally would: 1.5 V, 1500 mV and 0.0015 kV are the same answer.
Check
PERIOD for 4000 Hz?
Check
Resolution bits for PERIOD 1000?
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