0
0
Embedded Cprogramming~15 mins

Duty cycle control for motor/LED in Embedded C - Mini Project: Build & Apply

Choose your learning style9 modes available
Duty cycle control for motor/LED
📖 Scenario: You are working on a simple embedded system that controls the brightness of an LED or the speed of a motor using PWM (Pulse Width Modulation). The duty cycle determines how long the signal stays ON in one cycle, affecting brightness or speed.In this project, you will write code to set up the duty cycle and then calculate the ON time based on a fixed period.
🎯 Goal: Build a program that defines a duty cycle percentage, calculates the ON time for a PWM signal with a fixed period, and prints the ON time value.
📋 What You'll Learn
Create a variable to hold the PWM period in microseconds
Create a variable to hold the duty cycle percentage
Calculate the ON time based on the duty cycle and period
Print the ON time value
💡 Why This Matters
🌍 Real World
PWM signals are used in many devices to control motor speed, LED brightness, and other electronics by adjusting the duty cycle.
💼 Career
Understanding duty cycle control is important for embedded systems engineers and anyone working with hardware control and microcontrollers.
Progress0 / 4 steps
1
Set the PWM period
Create an integer variable called pwm_period and set it to 20000 to represent the PWM period in microseconds.
Embedded C
Need a hint?

The PWM period is the total time of one cycle. Use an integer variable named pwm_period and assign it the value 20000.

2
Set the duty cycle percentage
Create an integer variable called duty_cycle and set it to 30 to represent the duty cycle percentage (30%).
Embedded C
Need a hint?

The duty cycle is the percentage of time the signal is ON. Use an integer variable named duty_cycle and assign it the value 30.

3
Calculate the ON time
Create an integer variable called on_time and calculate its value as (pwm_period * duty_cycle) / 100 to find the ON time in microseconds.
Embedded C
Need a hint?

Multiply pwm_period by duty_cycle and divide by 100 to get the ON time.

4
Print the ON time
Use printf to print the text "ON time: " followed by the value of on_time and then " microseconds\n".
Embedded C
Need a hint?

Use printf("ON time: %d microseconds\n", on_time); to display the ON time.