Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong timer initialisation for ESP32 giving strange ibus polling frequency #40

Open
fanfanlatulipe26 opened this issue Jul 3, 2023 · 1 comment

Comments

@fanfanlatulipe26
Copy link

Configuration: ESP32 Dev Kit
The comments in the README and in the source code say that the iBus should be polled at least once per 1 ms.
When a timer is used the library uses the following code:

      #if defined(ARDUINO_ARCH_ESP32) 
        hw_timer_t * timer = NULL;
        timer = timerBegin(timerid, F_CPU / 1000000L, true); // defaults to timer_id = 0; divider=80 (1 ms); countUp = true;
        timerAttachInterrupt(timer, &onTimer, true); // edge = true
        timerAlarmWrite(timer, 1000, true);  //1 ms
        timerAlarmEnable(timer);

The code uses F_CPU, the CPU clock, to calculate a prescaler value that will give a 1ms timer.

In fact the clock source of the timers is APB_CLK (typically 80 MHz) and not the CPU clock and the code above will only give a 1ms timer if the CPU clock is 80Mhz.
By default in Arduino IDE the cpu clock is 240Mhz, the prescaler will be 240 and the timer will fire every 3ms

With the code above, the faster is the CPU clock, the slower will be the poll frequency of the iBus. Strange .

A fixed prescaler should be used ?: 80
timer = timerBegin(timerid, 80, true); // defaults to timer_id = 0; divider=80 (1 ms); countUp = true;

@fanfanlatulipe26
Copy link
Author

See issue #39
Timer/ISR should not be used at least in the Arduino/IESP32 context and so this issue is not relevant if we don't use timer.

Option IBUSBM_NOTIMER should be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant