Using 256 prescaler, maximum timer1 interval is only 26.843542 seconds !!! So the timer1 maximum interval is very short. The timer1's 23-bit counter terribly can count only up to 8,388,607. The ESP8266 has two hardware timers, but timer0 has been used for WiFi and it's not advisable to use. The ESP8266 timers are badly designed, using only 23-bit counter along with maximum 256 prescaler. The catch is your function is now part of an ISR (Interrupt Service Routine), and must be lean / mean, and follow certain rules. For example, certain function is blocking while it's connecting to WiFi or some services. That's necessary if you need to measure some data requiring better accuracy.įunctions using normal software timers, relying on loop() and calling millis(), won't work if the loop() or setup() is blocked by certain operation. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). These hardware timers, using interrupt, still work even if other functions are blocking. The correct choice is to use a Hardware Timer with Interrupt to call your function. You'd prefer to have your function called, no matter what happening with other functions (busy loop, bug, etc.). So your function might not be executed, and the result would be disastrous. But what if another function is blocking the loop() or setup(). You normally use a software timer to poll, or even place the function in loop(). ![]() ![]() Imagine you have a system with a mission-critical function, measuring water level and control the sump pump or doing something much more important. Why do we need this Hardware Timer Interrupt? This library enables you to use Interrupt from Hardware Timers on an ESP8266-based board. You can install directly from Arduino Library Manager
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |