How can I Create a second ISR for a secod timer
Posted: Mon Feb 12, 2018 1:51 pm
I could do this with One Timer, but not with more than One how can I do this
My approach was
My approach was
Code: Select all
/* create a hardware timer */
hw_timer_t * timer0 = NULL;
// Timer 0 Setup ***************************************************
pinMode(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 onTimer function to our timer */
timerAttachInterrupt(timer0, &ontimer0, true);
/* Set alarm to call onTimer function every second 1 tick is 1us
=> 1 second is 1000000us */
/* Repeat the alarm (third parameter) */
timerAlarmWrite(timer0, 1000000, true);
/* Start an alarm */
timerAlarmEnable(timer0);
void IRAM_ATTR ontimer0()
{
Code in Timer
}
/// Definition in ESP-32-HAL Timers
typedef struct hw_timer_s {
hw_timer_reg_t * dev;
uint8_t num;
uint8_t group;
uint8_t timer;
portMUX_TYPE lock;
} hw_timer_t;
static hw_timer_t hw_timer[4] = {
{(hw_timer_reg_t *)(DR_REG_TIMERGROUP0_BASE),0,0,0,portMUX_INITIALIZER_UNLOCKED},
{(hw_timer_reg_t *)(DR_REG_TIMERGROUP0_BASE + 0x0024),1,0,1,portMUX_INITIALIZER_UNLOCKED},
{(hw_timer_reg_t *)(DR_REG_TIMERGROUP0_BASE + 0x1000),2,1,0,portMUX_INITIALIZER_UNLOCKED},
{(hw_timer_reg_t *)(DR_REG_TIMERGROUP0_BASE + 0x1024),3,1,1,portMUX_INITIALIZER_UNLOCKED}
};