timers in esp32

kamesh
Posts: 35
Joined: Sat Aug 06, 2016 5:14 am

timers in esp32

Postby kamesh » Sat Dec 17, 2016 1:02 pm

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.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: timers in esp32

Postby kolban » Sat Dec 17, 2016 4:21 pm

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.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

kamesh
Posts: 35
Joined: Sat Aug 06, 2016 5:14 am

Re: timers in esp32

Postby kamesh » Mon Dec 19, 2016 7:40 am

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...

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: timers in esp32

Postby ESP_Sprite » Mon Dec 19, 2016 8:18 am

This seems to be Arduino-specific; moved to the Arduino subforum.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: timers in esp32

Postby kolban » Mon Dec 19, 2016 3:08 pm

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.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

kamesh
Posts: 35
Joined: Sat Aug 06, 2016 5:14 am

Re: timers in esp32

Postby kamesh » Tue Dec 20, 2016 4:23 am

hi,

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

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: timers in esp32

Postby kolban » Tue Dec 20, 2016 4:38 am

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();
   }
}
Last edited by kolban on Tue Dec 20, 2016 6:02 am, edited 1 time in total.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

kamesh
Posts: 35
Joined: Sat Aug 06, 2016 5:14 am

Re: timers in esp32

Postby kamesh » Tue Dec 20, 2016 5:11 am

hi,

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

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: timers in esp32

Postby kolban » Tue Dec 20, 2016 6:01 am

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();
   }
}
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

kamesh
Posts: 35
Joined: Sat Aug 06, 2016 5:14 am

Re: timers in esp32

Postby kamesh » Tue Dec 20, 2016 6:29 am

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.

Who is online

Users browsing this forum: No registered users and 56 guests