Page 1 of 2
[SOLVED]Timer changes since 1.6
Posted: Thu Jan 23, 2020 10:22 am
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.
Re: Timer changes since 1.6
Posted: Thu Jan 23, 2020 11:32 am
by fpiSTM
Hi Ben
Check in the wiki the HardwareTimer page and the STM32Examples, you will find what you search from.
Re: Timer changes since 1.6
Posted: Thu Jan 23, 2020 11:43 am
by BennehBoy
I forgot about the wiki
Re: Timer changes since 1.6
Posted: Thu Jan 23, 2020 11:59 am
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.
Re: Timer changes since 1.6
Posted: Thu Jan 23, 2020 12:13 pm
by Ralf9
maybe you need this
Code: Select all
MyTim->setMode(2, TIMER_OUTPUT_COMPARE);
viewtopic.php?f=62&t=117
Re: Timer changes since 1.6
Posted: Thu Jan 23, 2020 12:16 pm
by BennehBoy
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.
Re: Timer changes since 1.6
Posted: Thu Jan 23, 2020 12:22 pm
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();
Re: Timer changes since 1.6
Posted: Thu Jan 23, 2020 12:51 pm
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
Re: Timer changes since 1.6
Posted: Thu Jan 23, 2020 12:53 pm
by BennehBoy
Doh, my apologies then.
Re: Timer changes since 1.6
Posted: Thu Jan 23, 2020 12:55 pm
by BennehBoy
Solved, thanks.