0
0
Embedded Cprogramming~10 mins

PWM generation using timers in Embedded C - 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 timer prescaler for PWM generation.

Embedded C
TIM_HandleTypeDef htim1;

void PWM_Init() {
    htim1.Init.Prescaler = [1];
    // Other initialization code
}
Drag options to blanks, or click blank then click option'
A65535
B79
C1000
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as prescaler causes no division, leading to very fast timer overflow.
2fill in blank
medium

Complete the code to set the PWM period by configuring the timer's auto-reload register.

Embedded C
void PWM_Init() {
    htim1.Init.Period = [1];
    // Other initialization code
}
Drag options to blanks, or click blank then click option'
A999
B79
C10000
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting period to 0 disables counting, no PWM generated.
3fill in blank
hard

Fix the error in setting the PWM pulse width for 50% duty cycle.

Embedded C
TIM_OC_InitTypeDef sConfigOC = {0};
sConfigOC.Pulse = [1];
// Other PWM channel configuration
Drag options to blanks, or click blank then click option'
Ahtim1.Init.Period / 2
Bhtim1.Init.Period
Chtim1.Init.Prescaler
Dhtim1.Init.Period * 2
Attempts:
3 left
💡 Hint
Common Mistakes
Using full period as pulse causes 100% duty cycle, no off time.
4fill in blank
hard

Fill both blanks to configure the timer for PWM mode and enable the preload feature.

Embedded C
sConfigOC.OCMode = [1];
sConfigOC.OCPreload = [2];
Drag options to blanks, or click blank then click option'
ATIM_OCMODE_PWM1
BTIM_OCMODE_TIMING
CTIM_OCNORELOAD_ENABLE
DTIM_OCPRELOAD_ENABLE
Attempts:
3 left
💡 Hint
Common Mistakes
Using timing mode disables PWM output.
5fill in blank
hard

Fill all three blanks to start the PWM signal on channel 1 and enable the timer.

Embedded C
HAL_TIM_PWM_Start(&htim1, [1]);
__HAL_TIM_ENABLE(&htim1);
__HAL_TIM_SET_COUNTER(&htim1, [2]);
htim1.Instance->CR1 |= [3];
Drag options to blanks, or click blank then click option'
ATIM_CHANNEL_1
B0
CTIM_CR1_CEN
DTIM_CHANNEL_2
Attempts:
3 left
💡 Hint
Common Mistakes
Starting PWM on wrong channel disables output.