Skip to main content
Graduate II
April 14, 2025
Solved

Using one timer as prescaler for another timer STM32F103RB

  • April 14, 2025
  • 1 reply
  • 462 views

Hello,
STM32F103RB microcontroller.
I want to use Using one timer as prescaler for another timer mode (see figures below).

Mykola_Levun_0-1744652867550.png

Mykola_Levun_1-1744652896489.png

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;
}

 

    This topic has been closed for replies.
    Best answer by TDK

    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.

    1 reply

    Super User
    April 14, 2025

    > 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

    Graduate II
    April 14, 2025

    I see this through the debugger in the STM32CubeIDE.

    TDKAnswer
    Super User
    April 14, 2025

    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.