Skip to content

Conversation

@sneakyaardvark
Copy link

Set the timer frequency to 1MHz to match expected microsecond resolution for the alarm value.

The issue: the ESP32 library timerBegin(frequency) function uses a frequency in Hz to set the resolution of the timer and the alarm value (in timerAlarm()). Currently both the frequency and alarm value are set to the BPM in microseconds, so the interrupt will always be every second (or a ratio, if the tempo is later changed, changing the alarm value but keeping the default resolution).

Solution: set the timer frequency to 1MHz to match the expectation the alarm value is in microseconds.

midilab and others added 3 commits November 8, 2025 08:53
v2.3.0 Release merge from develop branch
Set the timer frequency to 1MHz to match expected microsecond
resolution for the alarm value.
@midilab
Copy link
Owner

midilab commented Dec 3, 2025

Hi @sneakyaardvark ,

Good catch! thank you for reporting back and pull back. It is strange that the API makes timerBegin uses frequency but timeAlarm uses micro seconds.

But to keep api compatibility we must convert init_clock to frequency instead of hardcode the value.

Can you please add this change to the code?

// convert micro seconds to frequency
uint32_t frequency_hz = 1000000 / period_us

@midilab midilab changed the base branch from main to develop December 23, 2025 20:32
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

Successfully merging this pull request may close these issues.

2 participants