stm32duino / Arduino_Core_STM32

STM32 core support for Arduino
https://github.com/stm32duino/Arduino_Core_STM32/wiki
Other
2.82k stars 972 forks source link

Help with hardware timers #672

Closed TadyTheFish closed 5 years ago

TadyTheFish commented 5 years ago

Hello

I'm trying to write some code using hardware timers and I have a lot of problems since there are no examples. I would like some help with timer interrupts. ` HardwareTimer Timer2 = HardwareTimer(TIM1);

void setup(){ Timer2.setPrescaleFactor(72); Timer2.setMode(1, TIMER_OUTPUT_COMPARE); Timer2.setCaptureCompare(1, some_delay_in_microseconds); Timer2.setOverflow(startDelayOneFour+1); Timer2.attachInterrupt(1, timerISR); Timer2.refresh(); Timer2.setCount(0); } void loop(){

} void timerISR(){ Timer2.detachInterrupt(1); // Stop the timer from firing this ISR //do stuff... }`

This does not compile.... error: invalid conversion from 'void (*)()' to 'void (*)(HardwareTimer*)' [-fpermissive]

So I was digging in the tone library and found that I need to write the ISR diffrently... void timerISR(HardwareTimer *HT){ Timer2.detachInterrupt(1); // Stop the timer from firing this ISR //do stuff... } This does compile but it seems it does not work... I am a begginer in this stuff and I don't really understand what is the meaning of HardwareTimer *HT.

On Arduino boards and Teensy boards yo don't need to write IRSs like that...

Thank you!

fpistm commented 5 years ago

Hi @TadyTheFish Here the wiki: https://github.com/stm32duino/wiki/wiki/HardwareTimer-library You can install the library STM32Examples to get some examples. HardwareTimer *HT is the hardware timer pointer, that's all.

TadyTheFish commented 5 years ago

Wooohoooaa thank you!!!! How did I missed this..

fpistm commented 5 years ago

Welcome.

TadyTheFish commented 5 years ago

Hmmmm library manager doesn't find the library

fpistm commented 5 years ago

Which library ? STM32Examples?

TadyTheFish commented 5 years ago

Yes... I tried searching through github for the link you provided but can't find anything. Maybe I missed something. The only link to examples that I can find is this .. https://github.com/stm32duino/STM32Examples This should be easier to access...

How can I install the examples? Library manager? If so It cannot find STM32Examples

fpistm commented 5 years ago

Well, I guess you search STM32Examples and it not found it while searching STM32 Examples it works:

image

TadyTheFish commented 5 years ago

Thank you ... It was the space :)