Page 1 of 2

timers in esp32

Posted: Sat Dec 17, 2016 1:02 pm
by kamesh
Hi,

I need to know the info about timers in esp32. How many timers are there? How to use timers in coding using ardunio IDE.

Re: timers in esp32

Posted: Sat Dec 17, 2016 4:21 pm
by kolban
See the following for information about the underlying hardware timers ...

http://esp-idf.readthedocs.io/en/latest/api/timer.html

However, depending on your needs there are "logically" any number of timers. It is common to register a timer and have that timer added to a list such that the "next" timer to fire is at the head of the list and when it is timer to fire the timer, it fires and then the story repeats with the next entry on the list. In that story, all one needs is one timer with a decent enough resolution.

The Arduino IDE and associate libraries is likely going to conform to Arduino standards/conventions for programming. As such a search on how to use Timers in Arduino is very likely going to apply for the ESP32. I googled "arduino timers" and found a wealth of tips.

Re: timers in esp32

Posted: Mon Dec 19, 2016 7:40 am
by kamesh
hi,

I did not get clear view of using esp32 timers in ardunio ide. Can you provide any examples of esp32 timer application using ardunio ide...

Re: timers in esp32

Posted: Mon Dec 19, 2016 8:18 am
by ESP_Sprite
This seems to be Arduino-specific; moved to the Arduino subforum.

Re: timers in esp32

Posted: Mon Dec 19, 2016 3:08 pm
by kolban
Kamesh,
Maybe you can post some information on what you mean by "use timers" ... what is it you are trying to achieve? Common examples would be:

* Call a C function every 5 seconds
* Measure how much time it took to perform a task

But there might be a different interpretation on your ask.

Re: timers in esp32

Posted: Tue Dec 20, 2016 4:23 am
by kamesh
hi,

I need a timer to be continuous on and for every 5 sec interrupt should come .

Re: timers in esp32

Posted: Tue Dec 20, 2016 4:38 am
by kolban
I think the classic way in Arduino programming is:

Code: Select all

unsigned long startTime;

setup() {
   startTime = millis();
}

loop() {
   if (millis() - startTime >= 5000) {
      // 5 seconds have elapsed. ... do something interesting ...
      startTime = millis();
   }
}

Re: timers in esp32

Posted: Tue Dec 20, 2016 5:11 am
by kamesh
hi,

Thank you for your response. I want to use two timers independently can you give suggestion on that?

Re: timers in esp32

Posted: Tue Dec 20, 2016 6:01 am
by kolban
Maybe something like the following ...

Code: Select all

unsigned long startTime1;
unsigned long startTime2;

setup() {
   startTime1 = millis();
   startTime2 = millis();   
}

loop() {
   if (millis() - startTime1 >= 5000) {
      // 5 seconds have elapsed on timer 1 ... do something interesting ...
      startTime1 = millis();
   }
   if (millis() - startTime2 >= 3000) {
      // 3 seconds have elapsed on timer2 ... do something interesting ...
      startTime2 = millis();
   }
}

Re: timers in esp32

Posted: Tue Dec 20, 2016 6:29 am
by kamesh
hi,

It is really awesome. can we pass arguments in miils(). i.e i want timer interrupt for every 100 ms and 200 ms and so on. so can i pass argument like millis(100),milli(200).....? where can i write timer interrupt handler function?


lets take an example of external interrupt. In that attachinterrupt(pin num, function name, edge);

here function name is the handler function, the same way i need for timer interrupt. pls provide me some example code.

thanks in advance.