cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 AHB1 divider setting not changing apparent speed of TIM2

kevincuzner
Associate
Posted on August 12, 2016 at 04:18

I'm doing some for-fun bare metal programming on an STM32F103C8T6 in order to better understand how it works. Currently, I'm messing with the RCC module. However, I think I may have misread something in the reference manual since I'm not getting the expected behavior.

I've got the RCC set up to run the PLL from the HSI/2 with a multiplier of 6, theoretically giving a system clock speed of 24MHz I think. I have TIM2 with no prescaler set up to interrupt when it overflows. In my interrupt I have one of the GPIO bits being flipped. This GPIO is connected to my oscilloscope. Here is what I am seeing that is confusing me: - With the AHB1 divider at 0b000 my oscilloscope says that my GPIO is toggling at 00Hz, duty cycle 09%. - With the AHB1 divider at 0b100 my oscilloscope says that my GPIO is toggling at 78Hz, duty cycle 91%. - With the AHB1 divider at 0b101 my oscilloscope says that my GPIO is toggling at 383Hz, duty cycle 48% - With the AHB1 divider at 0b110 my oscilloscope says that my GPIO is toggling at 691Hz, duty cycle 11% - With the AHB1 divider at 0b111 my oscolloscope says that my GPIO is toggling at 700Hz, duty cycle 0.228% (it looks like a normally high line which goes low for 1.93uS). What I see is problems at the extreme ends of the divider, especially with the div by 16 (0b111) at the end. The div by 1 and div by 2 appear to have very similar behavior to each other as well. Alternately, I have something horribly wrong with my timer and interrupt setup. Here is my timer and interrupt setup:

RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
TIM2->DIER = TIM_DIER_UIE;
TIM2->CR1 = TIM_CR1_CEN;
NVIC_EnableIRQ(TIM2_IRQn);
...snip...
void TIM2_IRQHandler()
{
static uint8_t on = 0;
TIM2->SR = ~TIM_SR_UIF;
if
(on)
GPIOB->BSRR = GPIO_BSRR_BS0;
else
GPIOB->BSRR = GPIO_BSRR_BR0;
on ^= 0xFF;
}

Does anyone have any idea what could be going on here? #!stm32-!clock
1 REPLY 1
sherman
Associate II
Posted on September 01, 2016 at 13:56

Hello knuzner,

Can you post your entire code to help external troubleshooting?  Could be an issue in the configuration.