Answered step by step
Verified Expert Solution
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 TIM in Count up Overflow Mode
Configure TIM to overflow every ms in count up mode to create your own HAL delay
function. This is done by enabling TIM and setting the prescaler PSC and autoreload
value ARR It is recommended to read up on Chapter of the datasheet to
understand the principles of different counter modes.
The instructions to do so are as follows.
Enable TIM in the Reset and Clock Control
Set TIM in count up mode.
Set the Prescaler PSC and AutoReload Register ARR values.
Enable TIM on the Control Register.
Use TIM to generate your own HAL delay function.
To set the PSC and ARR values, the following relationship needs to be used.
Fevent FclkPSC ARR
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 mydelaymsuintt ms
Read from TIM counter and increment a variable.
Clear the status register and repeat until the millisval.
TIMSR & ~;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started