How can I Create a second ISR for a secod timer

ats3788
Posts: 27
Joined: Thu Feb 01, 2018 10:12 am

How can I Create a second ISR for a secod timer

Postby ats3788 » 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

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}
};


mickeypop
Posts: 11
Joined: Mon May 08, 2017 8:56 pm

Re: How can I Create a second ISR for a secod timer

Postby mickeypop » Sat Feb 17, 2018 3:50 am

yo have the right idea

Code: Select all

       timer0 = timerBegin(0, 80, true);

       /* Attach onTimer function to our timer */
       timerAttachInterrupt(timer0, &ontimer0, true);
timer1 = timerBegin(1, 80, true); builds the timer object
-- the 1 is the timer. you have 4 timers, 0-3
-- 80 is the time
-- true makes it continuous/false would be a 1shot

then attach as above with a different function call.

Who is online

Users browsing this forum: No registered users and 32 guests