100microsecond timer in esp32
100microsecond timer in esp32
Dear All,
I am new to esp32 wanted to know how I can have a timer for 100 microseconds. An interrupt is to be generated at the lapse of 100microseconds
Should I use LEDC example or HW timer example or does FreeRtos API supports this. From my study so far I could not find freertos support for microseconds resolution.
Kindly let me know which one I should be using for accurate time period.
Thanks for help.
I am new to esp32 wanted to know how I can have a timer for 100 microseconds. An interrupt is to be generated at the lapse of 100microseconds
Should I use LEDC example or HW timer example or does FreeRtos API supports this. From my study so far I could not find freertos support for microseconds resolution.
Kindly let me know which one I should be using for accurate time period.
Thanks for help.
-
- Posts: 9772
- Joined: Thu Nov 26, 2015 4:08 am
Re: 100microsecond timer in esp32
You can probably use any of the timer sources for this... one of the timer groups, the LED PWM controller timers, maybe even the built-in Xtensa timers if you do not need clock switching... For what exactly do you require this, however? It might be that using a dedicated hardware peripheral is more suited to your needs.
Re: 100microsecond timer in esp32
I tried using Xtensa Timers , using xos.h and xos_timer.h. There are compilation errors and xos_clock_freq undefined error. Any config changes required for using Xtensa Timer APIs. I had set esp32 clock freq as 80MZ.
Re: 100microsecond timer in esp32
You can use the following code for the TG0 timer:
Also check the timer group example: https://github.com/espressif/esp-idf/bl ... ple_main.c
Code: Select all
#include <stddef.h>
#include "esp_intr_alloc.h"
#include "esp_attr.h"
#include "driver/timer.h"
static intr_handle_t s_timer_handle;
static void timer_isr(void* arg)
{
TIMERG0.int_clr_timers.t0 = 1;
TIMERG0.hw_timer[0].config.alarm_en = 1;
// your code, runs in the interrupt
}
void init_timer(int timer_period_us)
{
timer_config_t config = {
.alarm_en = true,
.counter_en = false,
.intr_type = TIMER_INTR_LEVEL,
.counter_dir = TIMER_COUNT_UP,
.auto_reload = true,
.divider = 80 /* 1 us per tick */
};
timer_init(TIMER_GROUP_0, TIMER_0, &config);
timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0);
timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, timer_period_us);
timer_enable_intr(TIMER_GROUP_0, TIMER_0);
timer_isr_register(TIMER_GROUP_0, TIMER_0, &timer_isr, NULL, 0, &s_timer_handle);
timer_start(TIMER_GROUP_0, TIMER_0);
}
void app_main()
{
init_timer(100);
}
- rajkumar patel
- Posts: 29
- Joined: Mon Apr 10, 2017 12:43 pm
- Location: india
Re: 100microsecond timer in esp32
hi Abhiram,
have you got any update or info regarding feasibility of xtensa(xos) timers from here or from other sources?
i'm also looking forward to use xtensa timers.
thanks.
regards.
have you got any update or info regarding feasibility of xtensa(xos) timers from here or from other sources?
i'm also looking forward to use xtensa timers.
thanks.
regards.
Regards,
Rajkumar M. Patel
Rajkumar M. Patel
- rajkumar patel
- Posts: 29
- Joined: Mon Apr 10, 2017 12:43 pm
- Location: india
Re: 100microsecond timer in esp32
hey Abhiram,Abhiram wrote:I tried using Xtensa Timers , using xos.h and xos_timer.h. There are compilation errors and xos_clock_freq undefined error. Any config changes required for using Xtensa Timer APIs. I had set esp32 clock freq as 80MZ.
have a look at this,
i've also encountered the same linking error but along with some more undefined references to xos_timer functions. but i'm not clear about which lib file to add and where to add. do u have any idea regarding this?
regards.
Regards,
Rajkumar M. Patel
Rajkumar M. Patel
Re: 100microsecond timer in esp32
Hi Rajkumar ,
No I gave up using Xtensa timers. no Clarity yet on those lines
No I gave up using Xtensa timers. no Clarity yet on those lines
- rajkumar patel
- Posts: 29
- Joined: Mon Apr 10, 2017 12:43 pm
- Location: india
Re: 100microsecond timer in esp32
let's hope someone will come up with some practicality details of these timers.
Regards,
Rajkumar M. Patel
Rajkumar M. Patel
Re: 100microsecond timer in esp32
You can refer to FreeRTOS port layer code for an example of how these timers are used (portasm.S). In C, RSR and WSR macros can be used to read and write CCOUNT and CCOMPAREx registers.
xos functions mentioned above can not be used in IDF because IDF doesn't include corresponding libraries or source files. The header files are still present for some historical reason.
I do suggest trying the hardware timers (TimerGroup peripherals) instead of Xtensa timers, as these are documented in the TRM and there is an example illustrating their use in ESP-IDF.
xos functions mentioned above can not be used in IDF because IDF doesn't include corresponding libraries or source files. The header files are still present for some historical reason.
I do suggest trying the hardware timers (TimerGroup peripherals) instead of Xtensa timers, as these are documented in the TRM and there is an example illustrating their use in ESP-IDF.
- rajkumar patel
- Posts: 29
- Joined: Mon Apr 10, 2017 12:43 pm
- Location: india
Re: 100microsecond timer in esp32
Hi ESP_igrr,
that's true, all i was using for reference was header file of that xtensa(xos)timers. i didn't thought of missing libraries as this sort of case is very rare. thanks for shading light on this.
i tried hardware timer feasibility and that works just fine. but microsecond resolution test i haven't performed yet.
regards.
that's true, all i was using for reference was header file of that xtensa(xos)timers. i didn't thought of missing libraries as this sort of case is very rare. thanks for shading light on this.
i tried hardware timer feasibility and that works just fine. but microsecond resolution test i haven't performed yet.
regards.
Regards,
Rajkumar M. Patel
Rajkumar M. Patel
Who is online
Users browsing this forum: Bing [Bot] and 67 guests