ESP32 Timer Interrupt
Hardware timer, how to run once and restart again?
Problema con timer y gestor de placa ESP32
Timer error building infinity cube. New syntax?
Guys
I have a DevKitC dev board, and I'm trying to set up a HW timer that I want to re-use under certain conditions. In other words, I don't want it to reload automatically, it should run once and then remain dormant until I enable it again. It seems to work the first time, but when I enable the timer a second time it fires immediately, without any delay. It seems I'm not resetting it properly, so that the counter starts from 0 again (?).
What I've tried is this:
initialize timer 0 in setup(), with a prescaler for 80MHz.
myTimer = timerBegin (0, 80, true); timerAttachInterrupt (myTimer, &isrMyTimer, true);
then when I want to use the timer I enable it as follows (for a duration of 3 seconds):
timerAlarmWrite(myTimer, 3000000), false); timerAlarmEnable(myTimer);
I am also trying to confirm the frequency to use for the timer, whether it is indeed 80MHz. I get the values as shown below for the different functions. Any thoughts on what they mean?
getCpuFrequencyMhz() 240 getXtalFrequencyMhz() 40 getApbFrequency() 80000000
Building, https://github.com/mecharms/Infinity-LED-CUBE/tree/main
I believe the problem is the timer is written under old format so does not work with new version in IDE.
Does anyone know if this is just a syntax fix?
//-------------------------------- // Configure Prescaler to 80, as our timer runs @ 80Mhz // Giving an output of 80,000,000 / 80 = 1,000,000 ticks / second timer = timerBegin(0, 80, true); timerAttachInterrupt(timer, &onTime, true); // Fire Interrupt every 1m ticks, so 1s timerAlarmWrite(timer, 5000000, true); timerAlarmEnable(timer); //-------------------------------- C:\Users\Jason\Downloads\Infinity-LED-CUBE-main\Infinity-LED-CUBE-main\code\cube_led\cube_led.ino: In function 'void setup()':
C:\Users\Jason\Downloads\Infinity-LED-CUBE-main\Infinity-LED-CUBE-main\code\cube_led\cube_led.ino:3829:21: error: too many arguments to function 'hw_timer_t* timerBegin(uint32_t)'
3829 | timer = timerBegin(0, 80, true);
| ~~~~~~~~~~^~~~~~~~~~~~~
In file included from C:\Users\Jason\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.2.0\cores\esp32/esp32-hal.h:98,
from C:\Users\Jason\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.2.0\libraries\Wire\src/Wire.h:33,
from C:\Users\Jason\Downloads\Infinity-LED-CUBE-main\Infinity-LED-CUBE-main\code\cube_led\cube_led.ino:2:
C:\Users\Jason\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.2.0\cores\esp32/esp32-hal-timer.h:35:13: note: declared here
35 | hw_timer_t *timerBegin(uint32_t frequency);
| ^~~~~~~~~~
C:\Users\Jason\Downloads\Infinity-LED-CUBE-main\Infinity-LED-CUBE-main\code\cube_led\cube_led.ino:3830:23: error: too many arguments to function 'void timerAttachInterrupt(hw_timer_t*, void (*)())'
3830 | timerAttachInterrupt(timer, &onTime, true);
| ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
C:\Users\Jason\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.2.0\cores\esp32/esp32-hal-timer.h:50:6: note: declared here
50 | void timerAttachInterrupt(hw_timer_t *timer, void (*userFunc)(void));
| ^~~~~~~~~~~~~~~~~~~~
C:\Users\Jason\Downloads\Infinity-LED-CUBE-main\Infinity-LED-CUBE-main\code\cube_led\cube_led.ino:3832:3: error: 'timerAlarmWrite' was not declared in this scope; did you mean 'timerWrite'?
3832 | timerAlarmWrite(timer, 5000000, true);
| ^~~~~~~~~~~~~~~
| timerWrite
C:\Users\Jason\Downloads\Infinity-LED-CUBE-main\Infinity-LED-CUBE-main\code\cube_led\cube_led.ino:3833:3: error: 'timerAlarmEnable' was not declared in this scope; did you mean 'timerAlarm'?
3833 | timerAlarmEnable(timer);
| ^~~~~~~~~~~~~~~~
| timerAlarm
exit status 1
Compilation error: too many arguments to function 'hw_timer_t* timerBegin(uint32_t)'
Thank you!