I try to use timer1 on STM32f103c8t6 (bluepill). I was read the datasheet and internet response/questions. However I can't understand "how can I adjust period value with registers". I was using timers with HAL library and calculate timing calculations, period and prescaler values etc.
(period)*(prescaler) / (clock Speed) = second
This is my already know formula.
My Clock Speed is 72Mhz and I was adjust Prescaler to 1000. I want to Period value to 72000 and I will have 1 second timer. But I don't know how can ı adjust period value, where is it.
void TIM1_Config(){
RCC-> APB2ENR |= 0x00000400; //TIM1 CLK Enable
TIM1-> CR1 |= 0x0083; //Auto Reload,Update Request Source, Counter Enable
TIM1-> DIER |= 0x0003; //CC1 Interrupt Enable, Update Interrupt Enable
TIM1-> ARR = 0x0064; //100 is set as Auto Reload Value
TIM1-> PSC |= 0x03E8; //1000 is set as Prescaler Value
TIM1-> (period value I need it)???? // it will set 72000
}
First, be aware that TMR clocks may be different from your system clock. So, be sure that you adjusted APB2 clock correctly.
Assuming that your APB2 clock is also 72 MHz, for 1 second period, you need to divide it by 72000000 (72e6) somehow. You need use ARR & PSC registers such that (ARR + 1) * (PSC + 1) = 72e6
. Keep in mind that these registers are 16-bit, so they can't be greater than 65535.
One possible combination is:
TIM1->PSC = 1124;
TIM1->ARR = 63999;
Please note that I didn't check your code / TMR settings.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.