khoih-prog / RPI_PICO_TimerInterrupt

This library enables you to use Interrupt from Hardware Timers on RP2040-based boards such as RASPBERRY_PI_PICO. These RPI_PICO_TimerInterrupt Hardware Timers, using Interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's mandatory if you need to measure some data requiring better accuracy. It now supports 16 ISR-based Timers, while consuming only 1 Hardware Timer. Timers' interval is very long (ulong millisecs). The most important feature is they're ISR-based Timers. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks.
MIT License
32 stars 15 forks source link

invalid conversion from 'void (*)()' to 'pico_timer_callback' {aka 'bool (*)(repeating_timer*)'} #2

Closed janczeresnia closed 2 years ago

janczeresnia commented 2 years ago

Hi I get an error compiling an example from your git website on Raspberry Pico Core 1.13.1 in Arduino I'm trying to use only Hardware Timer directly:

#include <RPi_Pico_TimerInterrupt.h>

#define TIMER_FREQ_HZ 8000.000
#define TIMER_INTERVAL_US 125

RPI_PICO_Timer ITimer1(1);

volatile uint32_t lastIsrMicros = 0;
volatile uint32_t deltaIsrMicros;

TimerHandler:

void TimerHandler() {
  deltaIsrMicros = micros() - lastIsrMicros;
  lastIsrMicros = micros();
}
if (ITimer1.setFrequency(TIMER_FREQ_HZ, TimerHandler)) { <---- Error
    Serial.println("Starting ITimer OK, millis() = " + String(millis()));
  } else {
    Serial.println("Can't set ITimer. Select another freq. or timer");
  }

Error : invalid conversion from 'void ()()' to 'pico_timer_callback' {aka 'bool ()(repeating_timer*)'} [-fpermissive]

And in loop

void loop() {
    Serial.println("delta: " + String(deltaIsrMicros));
    delay(1000);
}

I have fixed this error. Change TimerHandler to:

bool TimerHandler(struct repeating_timer *t) {
  deltaIsrMicros = micros() - lastIsrMicros;
  lastIsrMicros = micros();
  return true;
}
khoih-prog commented 2 years ago

Great that you can solve the problem by yourself. It's always better to recheck the working examples and compare to see what we're doing not correctly.