[SOLVED]Timer changes since 1.6

Post here all questions related to STM32 core if you can't find a relevant section!
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

[SOLVED]Timer changes since 1.6

Post by BennehBoy »

Hi Fred,

I'm revisiting an older project that users a click encoder.

I used to set up the timer like this:

Code: Select all

#define TIMER_ENC  TIM4
static stimer_t TimHandle;

/* Set TIMx instance. */
TimHandle.timer = TIMER_ENC;
/* Timer set to 1ms */
TimerHandleInit(&TimHandle, 1000 - 1, ((uint32_t)(getTimerClkFreq(TIMER_ENC) / (1000000)) - 1));
attachIntHandle(&TimHandle, checkenc);
What do I need to change to make this work in 1.8?

Feel free to point me at a relevant example.
by Ralf9 » Thu Jan 23, 2020 12:13 pm
maybe you need this

Code: Select all

MyTim->setMode(2, TIMER_OUTPUT_COMPARE);
viewtopic.php?f=62&t=117
Go to full post
Last edited by BennehBoy on Thu Jan 23, 2020 1:15 pm, edited 1 time in total.
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Timer changes since 1.6

Post by fpiSTM »

Hi Ben
Check in the wiki the HardwareTimer page and the STM32Examples, you will find what you search from.
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

Re: Timer changes since 1.6

Post by BennehBoy »

I forgot about the wiki :D
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

Re: Timer changes since 1.6

Post by BennehBoy »

OK so I think I know what I need to do... I want a time based interrupt that will fire every millisecond, so I just need to set up a 1000 hz timer? Based on the below example code?

Code: Select all

  MyTim->setOverflow(10, HERTZ_FORMAT); // 10 Hz
  MyTim->attachInterrupt(Update_IT_callback);
  MyTim->resume();
I'll give it a try.
Ralf9
Posts: 33
Joined: Sat Jan 11, 2020 7:21 pm
Answers: 1
Location: Germany, BaWü

Re: Timer changes since 1.6

Post by Ralf9 »

maybe you need this

Code: Select all

MyTim->setMode(2, TIMER_OUTPUT_COMPARE);
viewtopic.php?f=62&t=117
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

Re: Timer changes since 1.6

Post by BennehBoy »

Ralf9 wrote: Thu Jan 23, 2020 12:13 pm maybe you need this

Code: Select all

MyTim->setMode(2, TIMER_OUTPUT_COMPARE);
viewtopic.php?f=62&t=117
I just need to fire an interrupt every millisecond, if I was doing the pin handling myself (and not using a library) then yeah a comparison would be the way to go.

EDIT As it stands the interrupt doesn't fire my callback, I must be missing something.
Last edited by BennehBoy on Thu Jan 23, 2020 12:48 pm, edited 1 time in total.
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

Re: Timer changes since 1.6

Post by BennehBoy »

Open to suggestions....

globals:

Code: Select all

// Timer STM32
#define TIMER_ENC  TIM4
void checkenc(HardwareTimer*)
{
  clickEncoder->service();
}
setup:

Code: Select all

  TIM_TypeDef *Instance = TIMER_ENC;
  HardwareTimer *stimer_t = new HardwareTimer(Instance);
  stimer_t->setOverflow(1000, HERTZ_FORMAT); // 1000 Hz
  stimer_t->attachInterrupt(checkenc);
  stimer_t->resume();
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Timer changes since 1.6

Post by fpiSTM »

Like Ralf9 said
For 1.8 you need to do the setMode.
This will not be needed for next release.
Anyway, as you get the example on the master it is not present.
See:
https://github.com/stm32duino/STM32Exam ... 0a3352f716
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

Re: Timer changes since 1.6

Post by BennehBoy »

Doh, my apologies then.
BennehBoy
Posts: 135
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

Re: Timer changes since 1.6

Post by BennehBoy »

Solved, thanks.
Post Reply

Return to “General discussion”