0
0
Raspberry Piprogramming~10 mins

PWM frequency and duty cycle relationship in Raspberry Pi - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the PWM frequency to 1000 Hz.

Raspberry Pi
pwm = GPIO.PWM(pin, [1])
Drag options to blanks, or click blank then click option'
A500
B1000
C2000
D50
Attempts:
3 left
💡 Hint
Common Mistakes
Using a frequency too low or too high for the device.
Confusing frequency with duty cycle.
2fill in blank
medium

Complete the code to set the PWM duty cycle to 75%.

Raspberry Pi
pwm.ChangeDutyCycle([1])
Drag options to blanks, or click blank then click option'
A50
B100
C25
D75
Attempts:
3 left
💡 Hint
Common Mistakes
Using values outside 0-100 range.
Confusing duty cycle with frequency.
3fill in blank
hard

Fix the error in setting the PWM frequency to 0 Hz (which is invalid).

Raspberry Pi
pwm = GPIO.PWM(pin, [1])
Drag options to blanks, or click blank then click option'
A100
B-50
C0
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Setting frequency to zero or negative values.
Passing None instead of a number.
4fill in blank
hard

Fill both blanks to create a dictionary mapping duty cycle percentages to their ON time in milliseconds for a 1 kHz PWM signal.

Raspberry Pi
on_time_ms = {dc: dc / 100 [1] 1000 / freq for dc in duty_cycles if dc [2] 0}
Drag options to blanks, or click blank then click option'
A*
B/
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using division instead of multiplication for ON time.
Including duty cycles less than or equal to zero.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps duty cycle percentages to their OFF time in milliseconds for a given frequency.

Raspberry Pi
off_time_ms = {dc: (100 - dc) / 100 [1] 1000 [2] freq [3] 0}
Drag options to blanks, or click blank then click option'
A*
B/
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect operators for multiplication or division.
Including duty cycles less than or equal to zero.