Challenge - 5 Problems
PWM Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
PWM Duty Cycle Calculation Output
What is the output of this Python code that calculates the duty cycle percentage for a PWM signal?
Raspberry Pi
frequency = 1000 # 1 kHz period = 1 / frequency # seconds pulse_width = 0.00025 # 250 microseconds duty_cycle = (pulse_width / period) * 100 print(f"Duty cycle: {duty_cycle:.1f}%")
Attempts:
2 left
💡 Hint
Duty cycle is pulse width divided by period times 100.
✗ Incorrect
The period is 1/1000 = 0.001 seconds. The pulse width is 0.00025 seconds. So duty cycle = (0.00025 / 0.001) * 100 = 25%.
🧠 Conceptual
intermediate1:30remaining
Effect of Increasing PWM Frequency on Duty Cycle
If you keep the pulse width constant but increase the PWM frequency, what happens to the duty cycle?
Attempts:
2 left
💡 Hint
Duty cycle = pulse width / period. What happens to period when frequency increases?
✗ Incorrect
Increasing frequency makes the period shorter. Since pulse width is constant, duty cycle = pulse width / smaller period, so duty cycle increases.
🔧 Debug
advanced1:30remaining
Identify the Error in PWM Duty Cycle Calculation
What error does this code raise when calculating PWM duty cycle?
Raspberry Pi
frequency = 0 period = 1 / frequency pulse_width = 0.0005 duty_cycle = (pulse_width / period) * 100 print(f"Duty cycle: {duty_cycle}%")
Attempts:
2 left
💡 Hint
What happens if you divide by zero in Python?
✗ Incorrect
frequency is zero, so 1 / frequency causes ZeroDivisionError.
📝 Syntax
advanced1:30remaining
Syntax Error in PWM Duty Cycle Code
Which option contains a syntax error in the PWM duty cycle calculation?
Raspberry Pi
frequency = 500 period = 1 / frequency pulse_width = 0.0005 duty_cycle = (pulse_width / period) * 100 print(f"Duty cycle: {duty_cycle}%")
Attempts:
2 left
💡 Hint
Check for missing parentheses.
✗ Incorrect
Option B is missing a closing parenthesis, causing a SyntaxError.
🚀 Application
expert2:30remaining
Calculate PWM Frequency from Duty Cycle and Pulse Width
Given a PWM signal with a pulse width of 0.0001 seconds and a duty cycle of 10%, what is the PWM frequency?
Attempts:
2 left
💡 Hint
Use formula: duty cycle = pulse width / period * 100, then find frequency = 1 / period.
✗ Incorrect
Duty cycle = 10% = 0.1, pulse width = 0.0001 s. So period = pulse width / duty cycle = 0.0001 / 0.1 = 0.001 s. Frequency = 1 / 0.001 = 1000 Hz. But 1000 Hz is option C, check carefully. Actually, 0.0001 / period = 0.1 → period = 0.0001 / 0.1 = 0.001 s → frequency = 1 / 0.001 = 1000 Hz. So correct answer is A.