esp32 high resolution timer
Posted: Sun May 06, 2018 1:22 pm
Hello,
I am trying to use the esp32 high-resolution timers but I am not getting the right tick interval. I am calling esp_timer_start_periodic() with 10 microseconds but it is triggering at 50 microseconds. Am I configuring correctly?
I am trying to use the esp32 high-resolution timers but I am not getting the right tick interval. I am calling esp_timer_start_periodic() with 10 microseconds but it is triggering at 50 microseconds. Am I configuring correctly?
Code: Select all
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
#include <stddef.h>
#include "esp_intr_alloc.h"
#include "esp_attr.h"
#include "driver/timer.h"
#include "esp_timer.h"
/* Can run 'make menuconfig' to choose the GPIO to blink,
or you can edit the following line and set a number here.
*/
#define BLINK_GPIO CONFIG_BLINK_GPIO
char state;
static void timer_func(void* arg)
{
// your code, runs in the interrupt
if (state) {
state = 0;
gpio_set_level(BLINK_GPIO, 1);
} else {
state = 1;
gpio_set_level(BLINK_GPIO, 0);
}
}
void init_timer(int timer_period_us)
{
int64_t t_end;
esp_timer_handle_t timer1;
esp_timer_create_args_t args = {
.callback = &timer_func,
.arg = &t_end,
.name = "timer1"
};
// ---
gpio_pad_select_gpio(BLINK_GPIO);
/* Set the GPIO as a push/pull output */
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
//----
esp_timer_create(&args, &timer1);
//ref_clock_init();
esp_timer_start_periodic(timer1, timer_period_us);
while(1) {
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
esp_timer_delete(timer1);
}
void app_main()
{
init_timer(10); // 10uS
}