Bird
0
0

What is the issue with this PWM code snippet?

medium📝 Debug Q6 of 15
Raspberry Pi - PWM Output
What is the issue with this PWM code snippet?
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(16, GPIO.OUT)
pwm = GPIO.PWM(16, 2000)
pwm.start(-10)
AGPIO pin 16 cannot be used for PWM
BThe frequency value is too high for PWM
CThe duty cycle value is invalid because it is negative
DThe GPIO mode should be BOARD instead of BCM
Step-by-Step Solution
Solution:
  1. Step 1: Check duty cycle value

    The duty cycle must be between 0 and 100 inclusive.
  2. Step 2: Identify invalid value

    Here, the duty cycle is -10, which is invalid.
  3. Final Answer:

    The duty cycle value is invalid because it is negative -> Option C
  4. Quick Check:

    Duty cycle range check [OK]
Quick Trick: Duty cycle must be 0-100% only [OK]
Common Mistakes:
  • Using negative or >100 duty cycle values
  • Confusing GPIO modes (BCM vs BOARD)
  • Assuming frequency limits without checking

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes