0
0
Raspberry Piprogramming~20 mins

PWM frequency and duty cycle relationship in Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PWM Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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}%")
ADuty cycle: 250.0%
BDuty cycle: 2.5%
CDuty cycle: 0.25%
DDuty cycle: 25.0%
Attempts:
2 left
💡 Hint
Duty cycle is pulse width divided by period times 100.
🧠 Conceptual
intermediate
1: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?
ADuty cycle decreases because the period gets shorter.
BDuty cycle stays the same because pulse width is constant.
CDuty cycle increases because the period gets longer.
DDuty cycle becomes zero because frequency is too high.
Attempts:
2 left
💡 Hint
Duty cycle = pulse width / period. What happens to period when frequency increases?
🔧 Debug
advanced
1: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}%")
AZeroDivisionError
BTypeError
CNameError
DNo error, prints duty cycle
Attempts:
2 left
💡 Hint
What happens if you divide by zero in Python?
📝 Syntax
advanced
1: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}%")
Aduty_cycle = pulse_width / period * 100
Bduty_cycle = pulse_width / (period * 100
Cduty_cycle = (pulse_width / period) * 100
D001 * )doirep / htdiw_eslup( = elcyc_ytud
Attempts:
2 left
💡 Hint
Check for missing parentheses.
🚀 Application
expert
2: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?
A10,000 Hz
B1,000,000 Hz
C1000 Hz
D100 Hz
Attempts:
2 left
💡 Hint
Use formula: duty cycle = pulse width / period * 100, then find frequency = 1 / period.