Page 1 of 1

Problem with timer

Posted: Tue Nov 24, 2020 7:36 am
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.

Re: Problem with timer

Posted: Tue Nov 24, 2020 8:43 am
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));

Re: Problem with timer

Posted: Tue Nov 24, 2020 8:53 am
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?

Re: Problem with timer

Posted: Tue Nov 24, 2020 10:28 am
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);
}

Re: Problem with timer

Posted: Tue Nov 24, 2020 10:43 am
by saeed144
Thank you so much, you're great :)