Dear Foristers,
can anyone, please, send me an excample for a HW-Timer interrupt.
This is my Demo, which I used successfully on a ESP32 D1 Mini NodeMCU, but I cannot compile it for CubeCell AB01:
/***********************************************
* Demo 22: How to use Timer interrupt in Arduino ESP32
*
* File: Timer0_ISR.ino
* Date: 2022/02/11
* Version: v1.0
* Author: based on code from Tech It Yourself
* http://www.iotsharing.com/2017/06/how-to-use-interrupt-timer-in-arduino-esp32.html
* Update: 2022/02/11 - Äd Franzis
*
*/
/* ----------------------------------------
* Tested on this environment:
* Board: "WEMOS D1 MINI ESP32"
* Upload Speed: "921600"
* CPU Frequency: "240MHz (WiFi/BT)"
* Flash Frequency: "80MHz"
* Partition Scheme: "Standard"
*
* Chip is ESP32-D0WDQ6 (revision 1)
* Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
* Crystal is 40MHz
*
***********************************************/
/* create a hardware timer0 */
hw_timer_t * timer0 = NULL;
/* LED pin */
#define GPIO_LED LED_BUILTIN
/* LED state */
volatile byte state = LOW;
void IRAM_ATTR onTimer0(){
state = !state;
digitalWrite(GPIO_LED, state);
}// END OF: IRAM_ATTR onTimer0()
void setup() {
Serial.begin(115200);
pinMode(GPIO_LED, OUTPUT);
/* Use 1st timer of 4 */
/* 1 tick take 1/(80MHZ/80) = 1us so we set divider 80 and count up */
timer0 = timerBegin(0, 80, true);
/* Attach onTimer0 function to our timer0 */
timerAttachInterrupt(timer0, &onTimer0, true);
/* Set alarm to call onTimer0 function every second 1 tick is 1us
=> 1 second is 1000000us */
/* Repeat the alarm (third parameter) */
timerAlarmWrite(timer0, 1000000, true); //timer ISR onTime0 will be called each second
/* Start an alarm */
timerAlarmEnable(timer0);
Serial.println("timer0 is started");
}// END OF: setup()
void loop() {
/* empty loop */
}// END OF: loop()
In the finel code, loop() is not empty, i.e. CubeCell will not sleep and will not be in LowPower-Mode.
Unfortunately, I couldn’t find any information about the HW-Times on CubeCell.
I hope, someone can help me.
Kind regards
Äd