How to calculate the values to be inserted in the TIM2 registers?
#include "stm32f4xx.h" // Device header
// Trying to use the General Purpose Timer (TIM2) to create a 1 second delay
// Board External Crystal 8.0 MHz
// Port A Pin 0 Output
// The program should output a high on GPIOA Pin 0 and delay 1 second then output low and delay 1 second.
int main(void){
RCC->AHB1ENR |= 0x00000001; //Enable Clock to PortA
GPIOA->MODER |= 0x00000001; //General Purpose IO for PortA Pin 0
//TIM2 Configuration
RCC->APB1ENR |= 0x00000001; Enable Clock to TIM2
TIM2->PSC = 8000-1;
TIM2->ARR = 10000 - 1;
TIM2->CNT = 0;
TIM2->CR1 = 0x00000001;
while(1){
while((!TIM2->SR & 1)){
GPIOA->ODR ^= 0x00000001; // Output high/low on Pin0 PortA
}
}
}Would like to know how to calculate the values that should be inserted in TIM2->PSC, TIM2->ARR, and TIM2->CNT. Is there a formula to calculate the values. Also what values must be added to the registers in the above program to make it a 1 second delay. The program runs but the LED doesn't blink, its just ON.
