Problem with timer

Post here first, or if you can't find a relevant section!
Post Reply
saeed144
Posts: 32
Joined: Mon Sep 21, 2020 10:11 am

Problem with timer

Post by saeed144 »

Hello
I tried to test my STM32F103C8T6 timer but it didn't work.
Can you help me?

Code: Select all

#if !defined(STM32_CORE_VERSION) || (STM32_CORE_VERSION  < 0x01090000)
#error "Due to API change, this sketch is compatible with STM32_CORE_VERSION  >= 0x01090000"
#endif

void Update_IT_callback(void)
{
  digitalWrite(PA11, !digitalRead(PA13));
}
void setup() {
#if defined(TIM1)
  TIM_TypeDef *Instance = TIM1;
#else
  TIM_TypeDef *Instance = TIM2;
#endif
  pinMode(PA11, OUTPUT);
  digitalWrite(PA11, HIGH);
  delay(1000);
  digitalWrite(PA11, !digitalRead(PA13));

  HardwareTimer *MyTim = new HardwareTimer(Instance);
  //MyTim->setPrescaleFactor(72000000);
  MyTim->setOverflow(1, HERTZ_FORMAT);
  MyTim->attachInterrupt(Update_IT_callback);
  MyTim->resume();

}

void loop() {

}
LED on pin A11 should blink every second.
by fpiSTM » Tue Nov 24, 2020 10:28 am
This is a register read.

Code: Select all

/**
  * @brief  Retrieve prescaler from hardware register
  * @param  None
  * @retval prescaler factor
  */
uint32_t HardwareTimer::getPrescaleFactor()
{
  // Hardware register correspond to prescaler-1. Example PSC register value 0 means divided by 1
  return (LL_TIM_GetPrescaler(_timerObj.handle.Instance) + 1);
}
Go to full post

User avatar
fpiSTM
Posts: 851
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 33
Location: Le Mans
Contact:

Re: Problem with timer

Post by fpiSTM »

Code: Select all

  digitalWrite(PA11, !digitalRead(PA13));
As it seems PA13 never change it seems logical....

Code: Select all

  digitalWrite(PA11, !digitalRead(PA11));

saeed144
Posts: 32
Joined: Mon Sep 21, 2020 10:11 am

Re: Problem with timer

Post by saeed144 »

Oh! you're right it blinks now , So sorry :roll:
I get presclaler factor and it returns 110.

Code: Select all

ans = MyTim->getPrescaleFactor();
110 is default?

User avatar
fpiSTM
Posts: 851
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 33
Location: Le Mans
Contact:

Re: Problem with timer

Post by fpiSTM »

This is a register read.

Code: Select all

/**
  * @brief  Retrieve prescaler from hardware register
  * @param  None
  * @retval prescaler factor
  */
uint32_t HardwareTimer::getPrescaleFactor()
{
  // Hardware register correspond to prescaler-1. Example PSC register value 0 means divided by 1
  return (LL_TIM_GetPrescaler(_timerObj.handle.Instance) + 1);
}

saeed144
Posts: 32
Joined: Mon Sep 21, 2020 10:11 am

Re: Problem with timer

Post by saeed144 »

Thank you so much, you're great :)

Post Reply

Return to “General discussion”