0
0
Embedded Cprogramming~10 mins

Generating precise delays with 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 start the timer.

Embedded C
TIM2->CR1 |= [1];
Drag options to blanks, or click blank then click option'
ATIM_CR1_DIR
BTIM_CR1_CEN
CTIM_CR1_UDIS
DTIM_CR1_OPM
Attempts:
3 left
💡 Hint
Common Mistakes
Using TIM_CR1_UDIS disables the timer update event.
Using TIM_CR1_DIR changes the counting direction.
Using TIM_CR1_OPM sets one pulse mode instead of starting timer.
2fill in blank
medium

Complete the code to set the prescaler value for the timer.

Embedded C
TIM3->PSC = [1] - 1;
Drag options to blanks, or click blank then click option'
Aprescaler_value
Bcounter_value
Cdelay_time
Dtimer_frequency
Attempts:
3 left
💡 Hint
Common Mistakes
Using delay_time instead of prescaler_value.
Setting counter_value in PSC register.
Confusing timer_frequency with prescaler_value.
3fill in blank
hard

Fix the error in the code to wait until the timer update event occurs.

Embedded C
while (!(TIM4->SR & [1])) {}
Drag options to blanks, or click blank then click option'
ATIM_SR_CC1IF
BTIM_SR_TIF
CTIM_SR_CC2IF
DTIM_SR_UIF
Attempts:
3 left
💡 Hint
Common Mistakes
Using capture/compare flags instead of update flag.
Using undefined or incorrect flag bits.
4fill in blank
hard

Fill both blanks to configure the timer for a 1s delay assuming 16MHz clock.

Embedded C
TIM5->PSC = [1] - 1;
TIM5->ARR = [2] - 1;
Drag options to blanks, or click blank then click option'
A16000
B1000
C1600
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping prescaler and ARR values.
Using wrong values that don't match clock frequency.
5fill in blank
hard

Fill all three blanks to create a delay function using TIM6 with prescaler and auto-reload values.

Embedded C
void delay_ms(uint16_t ms) {
    TIM6->PSC = [1] - 1;
    TIM6->ARR = [2] * ms - 1;
    TIM6->EGR = [3];
    TIM6->SR = 0;
    TIM6->CR1 |= TIM_CR1_CEN;
    while (!(TIM6->SR & TIM_SR_UIF)) {}
}
Drag options to blanks, or click blank then click option'
A16000
B1
CTIM_EGR_UG
D1000
Attempts:
3 left
💡 Hint
Common Mistakes
Not generating update event after changing PSC and ARR.
Using wrong multiplier for ARR.
Forgetting to clear status register before starting timer.