0
0
Embedded Cprogramming~20 mins

Duty cycle control for motor/LED in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PWM Duty Cycle Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
A255
B153
C60
D100
Attempts:
2 left
💡 Hint
Remember that duty cycle is a fraction of max PWM value based on percentage.
Predict Output
intermediate
2: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;
A256
B255
C1023
D25
Attempts:
2 left
💡 Hint
Calculate the percentage of max PWM value.
Predict Output
advanced
2: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;
ATypeError: cannot assign float to int without cast
BNo error, duty_cycle = 192
CSyntaxError: invalid expression
DWarning: implicit conversion from float to int, duty_cycle = 192
Attempts:
2 left
💡 Hint
Check how float to int conversion works in C.
🧠 Conceptual
advanced
2: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.
AHigher duty cycle means the motor receives power for a longer time, increasing speed.
BPWM frequency controls speed, duty cycle controls torque.
CDuty cycle does not affect motor speed, only voltage does.
DLower duty cycle increases motor speed by reducing power interruptions.
Attempts:
2 left
💡 Hint
Think about how power delivery time affects motor rotation.
Predict Output
expert
3: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;
}
A0
B127
C254
D255
Attempts:
2 left
💡 Hint
Calculate the sum inside the loop and check the cap condition.