Question: An MCU programmer wants to develop a real time chronometer, which can count to 1 0 0 minutes, on STM 3 2 F 4 by

An MCU programmer wants to develop a real time chronometer, which can count to 100 minutes,
on STM32F4 by using a timer peripheral (TIM2). TIM2 has a 16 bit TIMx_PSC register, a 32 bit
TIMx_ARR register, and a 32 bit TIMx_CNT register. TIM2 is connected to the APB1 bus. The source
clock of the timer is clock of the bus. Assume that all required settings and variable declarations are
done and the code will be executed after resetting.
(i) APB1 bus has arranged to have a clock frequency of 50MHz. Analyze the below code and
determine the values, those should be written to related registers. Show your calculations and
justify your results. Determine the period of the timer and the time it takes to create an interrupt request.

...
TIM_HandleTypeDef htim2;
...
int main(void)
{
...
TIM2->PSC=.......................................................;
TIM2->ARR=.......................................................;
HAL_TIM_Base_Start_IT(&htim2);
...
}
...
Interrupt handler void TIM2_IRQHandler(void)
{
HAL_TIM_IRQHandler(&htim2); //clears IRQ
splitsecond= splitsecond +1; //salise
if (splitsecond ==100)
{
splitsecond =0;
second= second+1;
}
if (second ==60)
{
second =0;
minute= minute +1;
}
if (minute ==100)
{
minute =0;
}

}
Interrupt handler void EXTI0_IRQHandler(void)
{
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0); //clears IRQ
i=TIMx_CNT;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!