Hi.
I need a high frequency task (250 Hz) to control a cnc motor. Moreover this task needs to be deterministic.
I tried to do an example ofhigh frequency task using "hello world " sample, but I obtain only 100 Hz task .
My code is this:
#include <stdio.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "esp_log.h"
#define YYS_RTC_TASK_STACK_SIZE 9192
#define YYS_RTC_TASK_PRIORITY configMAX_PRIORITIES
static void yys_rtc_task(void* arg);
static TaskHandle_t yys_rtc_task_hdl;
void app_main(void)
{
BaseType_t err = ESP_OK;
printf("Hello world!\n");
/* Print chip information */
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
printf("This is %s chip with %d CPU core(s), WiFi%s%s, ",
CONFIG_IDF_TARGET,
chip_info.cores,
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
printf("silicon revision %d, ", chip_info.revision);
printf("Minimum free heap size: %d bytes\n", esp_get_minimum_free_heap_size());
fflush(stdout);
//esp_restart();
// Necessario un ritardo prima della creazione della rtc task altrimenti abortisce
vTaskDelay(1000 / portTICK_PERIOD_MS);
// Creo la task principale
err = xTaskCreate(yys_rtc_task, "yys_rtc_task", YYS_RTC_TASK_STACK_SIZE, NULL, YYS_RTC_TASK_PRIORITY, &yys_rtc_task_hdl);
if (err != pdTRUE)
{
ESP_LOGE("TEST", "create yys_rtc_task failed");
return;
}
}
static void yys_rtc_task(void* arg)
{
static int64_t time = 0;
static int64_t endTime = 0;
static int64_t deltaT = 0;
static TickType_t xLastWakeTime;
static const TickType_t xFrequency = 1;
static BaseType_t xWasDelayed;
// Initialise the xLastWakeTime variable with the current time.
xLastWakeTime = xTaskGetTickCount();
for (;;)
{
// Wait for the next cycle.
xWasDelayed = xTaskDelayUntil(&xLastWakeTime, xFrequency);
time = esp_timer_get_time();
deltaT = time - endTime;
endTime = time;
// Perform action here. xWasDelayed value can be used to determine
// whether a deadline was missed if the code here took too long.
ESP_LOGE("TEST", "time %lld -- deltaT %lld", time, deltaT);
}
}
High Frequency task
Re: High Frequency task
In menuconfig, Componenbt config, FreeRTOS, kernel, try setting configTICK_RATE_HZ to 1000.
-
- Posts: 9757
- Joined: Thu Nov 26, 2015 4:08 am
Re: High Frequency task
Alternatively, try using a hardware timer and a semaphore to unblock your task. That way, you're not beholden to the FreeRTOS timer.
Who is online
Users browsing this forum: No registered users and 56 guests