Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Delay Function using TIM 2 in Count up Overflow Mode Configure TIM 2 to overflow every 1 ms in count up mode to create your

Delay Function using TIM2 in Count up Overflow Mode
Configure TIM2 to overflow every 1ms in count up mode to create your own HAL delay
function. This is done by enabling TIM2 and setting the prescaler (PSC) and auto-reload
value (ARR). It is recommended to read up on Chapter 22.3.2 of the datasheet to
understand the principles of different counter modes.
The instructions to do so are as follows.
1. Enable TIM2 in the Reset and Clock Control.
2. Set TIM2 in count up mode.
3. Set the Prescaler (PSC) and Auto-Reload Register (ARR) values.
4. Enable TIM2 on the Control Register.
5. Use TIM2 to generate your own HAL delay function.
To set the PSC and ARR values, the following relationship needs to be used.
F_event =(Fclk)/((PSC +1)(ARR +1))
Where the Fclk is the frequency of the system clock defined by the APB Timer Clocks in
CubeIDEs clock configuration. The overflow value is set by the ARR.
The delay function should have a similar format to what is shown. Call this function in
the main while loop and set a delay value (in milliseconds).
void my_delay_ms(uint32_t ms)
{
// Read from TIM2 counter and increment a variable.
// Clear the status register and repeat until the millis_val.
TIM2->SR &= ~(1<<0);
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Statistical And Scientific Database Management International Working Conference Ssdbm Rome Italy June 21 23 1988 Proceedings Lncs 339

Authors: Maurizio Rafanelli ,John C. Klensin ,Per Svensson

1st Edition

354050575X, 978-3540505754

More Books

Students also viewed these Databases questions

Question

7. Identify six intercultural communication dialectics.

Answered: 1 week ago