2023-08-16 22:45:23 -04:00
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
2022-05-29 22:49:39 -04:00
2021-02-01 01:10:15 -05:00
# Example: General Purpose Timer
2016-12-21 20:18:15 -05:00
2023-01-05 06:34:05 -05:00
This example uses the **legacy timer group driver** to generate timer interrupts with and without auto-reload. But we highly recommend you to use the new [GPTimer Driver ](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gptimer.html ) in your new projects.
2017-09-25 00:20:12 -04:00
2021-02-01 01:10:15 -05:00
## How to Use Example
### Hardware Required
* A development board with ESP SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
* A USB cable for Power supply and programming
### Build and Flash
Run `idf.py -p PORT flash monitor` to build, flash and monitor the project.
(To exit the serial monitor, type ``Ctrl-]``.)
2021-06-14 23:51:31 -04:00
See the [ESP-IDF Getting Started Guide ](https://idf.espressif.com/ ) for all the steps to configure and use the ESP-IDF to build projects.
2023-01-05 06:34:05 -05:00
2021-02-01 01:10:15 -05:00
## Example Output
2023-01-05 06:34:05 -05:00
```text
2021-12-17 00:19:20 -05:00
I (0) cpu_start: Starting scheduler on APP CPU.
I (325) example: Init timer with auto-reload
I (835) example: Timer auto reloaded, count value in ISR: 3
I (1335) example: Timer auto reloaded, count value in ISR: 3
I (1835) example: Timer auto reloaded, count value in ISR: 3
I (2335) example: Timer auto reloaded, count value in ISR: 3
I (2335) example: Init timer without auto-reload
I (2835) example: Timer alarmed at 500003
I (3335) example: Timer alarmed at 1000003
I (3835) example: Timer alarmed at 1500003
I (4335) example: Timer alarmed at 2000003
2021-02-01 01:10:15 -05:00
```
2017-09-25 00:20:12 -04:00
## Functionality Overview
2021-12-17 00:19:20 -05:00
* Configure one timer with auto-reload enabled, alarm period set to 0.5s
* On reaching the interval value the timer will generate an alarm
* The timer will reload with initial count value on alarm, by hardware
* Reconfigure the timer with auto-reload disabled, initial alarm value set to 0.5s
* The timer keeps incrementing and in the alarm callback, the software reconfigures its alarm value by increasing 0.5s
* The main task will print the count value that captured in the alarm callback
2017-09-25 00:20:12 -04:00
2021-02-01 01:10:15 -05:00
## Troubleshooting
2017-09-25 00:20:12 -04:00
2021-02-05 12:49:28 -05:00
For any technical queries, please open an [issue ](https://github.com/espressif/esp-idf/issues ) on GitHub. We will get back to you soon.