2025-04-14 10:54 AM
Hello,
STM32F103RB microcontroller.
I want to use Using one timer as prescaler for another timer mode (see figures below).
I want the slave timer to increment its counter every time the master timer generates update events. But the slave timer does this regardless of the update event (incrementing occurs constantly). I can't understand why. Tell me what I did wrong? I'm attaching the code.
#include "stm32f1xx.h"
static void init_tim3(void);
static void init_tim4(void);
static void init_tim3(void)
{
TIM3->CR1 &= ~0x00000001;
TIM3->CR2 |= 0x0020;
TIM3->PSC = 0x00000000;
TIM3->ARR = 0xFFFF;
TIM3->CNT = 0x0000;
TIM3->SR &= ~0x0001;
TIM3->DIER |= 0x0001;
//TIM3->CR1 |= 0x00000001;
}
static void init_tim4(void)
{
TIM4->CR1 &= ~0x00000001;
TIM4->SMCR |= 0x0020;
TIM4->SMCR |= 0x0007;
TIM4->PSC = 0x00000000;
TIM4->ARR = 0x007A;
TIM4->CNT = 0x0000;
//TIM4->CR1 |= 0x00000001;
}
void init_tim3_tim4(void)
{
init_tim3();
init_tim4();
TIM3->CR1 |= 0x00000001;
TIM4->CR1 |= 0x00000001;
}
2025-04-14 11:52 AM
> But the slave timer does this regardless of the update event (incrementing occurs constantly).
How do you observe this? How do you know it's "occuring constantly", what do you mean exactly by that?
JW
2025-04-14 11:55 AM
I see this through the debugger in the STM32CubeIDE.
2025-04-14 12:16 PM
Timers run when the code is paused in the debugger. Perhaps this is the reason for the misunderstanding.
Try enabling only the slave timer and ensure its CNT value does not progress.