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

Change Timer1 to Timer3 on ATmega32u4-based dev boards #115

Open
CoolBots opened this issue Jul 13, 2023 · 2 comments
Open

Change Timer1 to Timer3 on ATmega32u4-based dev boards #115

CoolBots opened this issue Jul 13, 2023 · 2 comments
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement

Comments

@CoolBots
Copy link

CoolBots commented Jul 13, 2023

As of version 1.2.1 of the library, ATmega32u4-based boards are defined to use Timer1 raher than Timer3. This configuration conflicts with millis() and micros() functions. While not too difficult to change, it does make the library more difficult to use in educational settings (we're a robotics/programming school for kids). If possible, could Timer1 be changed to Timer3 for these devices? The specific device we are using is an Adafruit ItsyBitsy 5V.

It would be no issue to submit a PR, of course, provided there isn't a strong reason to keep it as Timer1, as technically this would be a breaking change (although it is likely 32u4 users of this library make this modification anyhow, as millis() and micros() are useful functions...). Likewise, if there is a workaround that is fairly straightforward and does not require modification of the library that we are not aware of, please let us know.

It is worthwhile mentioning that we have seen other examples of this choice of Timer1 instead of Timer3 being an issue on 32u4 boards, most notably from Pololu Robotics and Electronics: https://www.pololu.com/docs/0J57/8.b

CodeRef:

#elif defined(__AVR_ATmega32U4__)
#define _useTimer1
typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t;

@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Jul 13, 2023
@per1234
Copy link
Contributor

per1234 commented Jul 13, 2023

Hi @CoolBots. Thanks for your report.

As of version 1.2.1 of the library

This statement seems misleading to me. No change to the timer used by ATmega32U4-based boards was introduced in the 1.2.1 release. In fact, the last relevant change was made back in 2012:
arduino/Arduino#102

and released in Arduino IDE 1.0.2 (at that time the Servo library was distributed as a part of the IDE installation), and in the 1.0.0 release of the standalone Servo library after the library was split out from the IDE project.

@CoolBots
Copy link
Author

CoolBots commented Jul 14, 2023

My apologies, I merely meant to tie the issue to the version of the library I discovered it in. You're right though, it's misleading, as it sounds like a new issue in this version, which is not the case. I'll be more careful with my wording.

After reviewing the change you referenced in 2012, I realize that Timer3 was removed to avoid conflict with tone() on ATmega32u4. Simply changing to that timer will fix one issue at expense of another. I'm open to suggestions; if no practical solution exists due to lack of timers, this issue should be closed as unresolvable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

2 participants