[Solved] Use timer for precise interrupt

Post here first, or if you can't find a relevant section!
Step73
Posts: 23
Joined: Tue Jan 14, 2020 2:55 pm

Re: Use timer for precise interrupt

Post by Step73 »

fredbox wrote:
Tue Jan 14, 2020 10:28 pm

Code: Select all

timerBase->setMode(2, TIMER_OUTPUT_COMPARE);
as the first timerBase line.
So why this line was removed in the example?

https://github.com/stm32duino/STM32Exam ... 0a3352f716

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

Re: Use timer for precise interrupt

Post by fpiSTM »

It is required for v1.8.0 of the core.
It will not be needed for higher version.
I guess you use the STM32Examples master not the last official release which does not contains this update.
In a general way you have to use the release version of the archive.
Else if you have to use the repo master, you have to use it for all (core, libraries,...)

Step73
Posts: 23
Joined: Tue Jan 14, 2020 2:55 pm

Re: Use timer for precise interrupt

Post by Step73 »

fpiSTM wrote:
Wed Jan 15, 2020 7:54 am
It is required for v1.8.0 of the core.
It will not be needed for higher version.
I guess you use the STM32Examples master not the last official release which does not contains this update.
In a general way you have to use the release version of the archive.
Else if you have to use the repo master, you have to use it for all (core, libraries,...)
You're right, but I see nothing but the master branch on STM32Example repo.
Anyway, even adding this line it still does not work.

Here the updated code:

Code: Select all

#define LED_RED 1 // was already defined elsewhere

void setup()
{

  pinMode(LED_RED, OUTPUT); 
  digitalWrite(LED_RED, HIGH);

  TIM_TypeDef *Instance = TIM1;
  //TIM_TypeDef *Instance = TIM2;
  //TIM_TypeDef *Instance = TIM3;
  HardwareTimer *timerBase = new HardwareTimer(Instance);   
  timerBase->setMode(1, TIMER_OUTPUT_COMPARE, NC);
  //timerBase->setMode(1, TIMER_OUTPUT_COMPARE);
  //timerBase->setMode(2, TIMER_OUTPUT_COMPARE);
  timerBase->setOverflow(5, HERTZ_FORMAT);
  timerBase->attachInterrupt(timer_callback);
  timerBase->resume();
}

void loop()
{
}

void timer_callback(HardwareTimer *)
{
  digitalWrite(LED_RED, !digitalRead(LED_RED));
}
I would not give up and using the 1 ms interrupt. I need to control some steppers and I want to interrupt the main code only when necessary. Of course I'm toggling a pin just to be sure the callback is fired (now it isn't). Once fixed, I will put other code there.

Step73
Posts: 23
Joined: Tue Jan 14, 2020 2:55 pm

Re: Use timer for precise interrupt

Post by Step73 »

FIXED!!!

I don't know why, but I had to delete the build directory and rebuild all.
Now it works... thanks a lot guys.

If you just help me how to find the 1.8.0 branch of the examples repo I will try to follow them precisely next time ;)

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

Re: Use timer for precise interrupt

Post by fpiSTM »

Step73 wrote:
Wed Jan 15, 2020 8:23 am

If you just help me how to find the 1.8.0 branch of the examples repo I will try to follow them precisely next time ;)
1.8.0 is the version of the core. This is not the same than the STM32Examples library version.

Post Reply

Return to “General discussion”