ESP32 Timer: Change timer characteristics and restart during interrupt

Viewed 14

I need to add async music playing with buzzer to my ESP32 project, but I can't understand how to properly restart timer with required characteristics during interrupt.

The initial idea is next. I have some Sound structure, what contains array of Notes, where each note has length and tone.

To play Sound I use tone() function in interrupts. Using Note.tone I control frequency and using interrupt length I control time during what note is played.

So, in interrupt I have to do next:

  1. Get current note
  2. Start playing note using tone()
  3. Stop timer
  4. Set timer to create next interrupt in Note.length milliseconds.
  5. Start timer again.
  6. Exit interrupt.

Instead, it plays first note and freezes on second. I am developing project in simulation environment, so here is link for project. Related code is on lines 24 - 68, 184 - 232 and 1651 - 1672

Does anybody know what I did wrong here? I was following https://docs.espressif.com/projects/arduino-esp32/en/latest/api/timer.html during development, and if I correctly understood it, everything had to be okay, but by some reason, it isn't. What I did wrong?

0 Answers
Related