Challenge - 5 Problems
PWM Duty Cycle Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this PWM duty cycle calculation?
Given the following code snippet that calculates the PWM duty cycle for a motor, what is the value of
duty_cycle after execution?Embedded C
int max_pwm = 255; int speed_percent = 60; int duty_cycle = (speed_percent * max_pwm) / 100;
Attempts:
2 left
💡 Hint
Remember that duty cycle is a fraction of max PWM value based on percentage.
✗ Incorrect
The duty cycle is calculated by multiplying the speed percentage (60) by the max PWM value (255) and dividing by 100, which results in 153.
❓ Predict Output
intermediate2:00remaining
What is the LED brightness value after this PWM update?
Consider this code controlling LED brightness with PWM. What is the value of
led_brightness after running this code?Embedded C
int max_pwm = 1023; int brightness_percent = 25; int led_brightness = (brightness_percent * max_pwm) / 100;
Attempts:
2 left
💡 Hint
Calculate the percentage of max PWM value.
✗ Incorrect
25% of 1023 is 255.75, which truncates to 255 in integer arithmetic, but the actual integer division results in 255.75 truncated to 255. However, the calculation (25 * 1023) / 100 = 255.75 truncated to 255, so option A is correct.
❓ Predict Output
advanced2:00remaining
What error does this PWM duty cycle code produce?
What error will occur when compiling or running this code snippet?
Embedded C
int max_pwm = 255; float speed_percent = 75.5; int duty_cycle = (speed_percent * max_pwm) / 100;
Attempts:
2 left
💡 Hint
Check how float to int conversion works in C.
✗ Incorrect
In C, assigning a float expression to an int variable causes implicit conversion with truncation, usually with a warning but no error. The value is 192 after truncation.
🧠 Conceptual
advanced2:00remaining
Which statement best describes PWM duty cycle effect on motor speed?
Select the statement that correctly explains how PWM duty cycle affects motor speed.
Attempts:
2 left
💡 Hint
Think about how power delivery time affects motor rotation.
✗ Incorrect
PWM duty cycle controls how long the motor receives power in each cycle. A higher duty cycle means more power time, increasing speed.
❓ Predict Output
expert3:00remaining
What is the final value of
duty_cycle after this code runs?Analyze this embedded C code that adjusts PWM duty cycle dynamically. What is the final value of
duty_cycle?Embedded C
int max_pwm = 255; int duty_cycle = 0; for (int i = 0; i < 5; i++) { duty_cycle += (i * max_pwm) / 10; } if (duty_cycle > max_pwm) { duty_cycle = max_pwm; }
Attempts:
2 left
💡 Hint
Calculate the sum inside the loop and check the cap condition.
✗ Incorrect
The loop adds (i * 255) / 10 for i=0 to 4: 0 + 25 + 51 + 76 + 102 = 254. Since 254 <= 255, the cap condition is not met, so duty_cycle = 254 (A).