esp32 - ESP32 xTaskGetTickCount 不返回正确的值
问题描述
为什么这个简单的代码不起作用,如果 xTaskGetTickCount 不起作用,应该有什么替代方法?
static void PrintTextEvery8sec(void *pvParameters)
{
TickType_t time_start = xTaskGetTickCount();
while(1){
if( ( (xTaskGetTickCount() - time_start)/portTICK_PERIOD_MS) > 8000){
ESP_LOGI(TAG, "8 seconds has passed...!");
time_start = xTaskGetTickCount();
}
vTaskDelay(100 / portTICK_PERIOD_MS);
}
}
解决方案
我已经通过以下方式解决了它:
static void PrintTextEvery8sec(void *pvParameters)
{
TickType_t time_start = xTaskGetTickCount();
while(1){
/* pdTICKS give correct calculation */
/* \/ */
if( pdTICKS_TO_MS(xTaskGetTickCount() - time_start))** > 8000){
ESP_LOGI(TAG, "8 seconds has passed...!");
time_start = xTaskGetTickCount();
}
vTaskDelay(100 / portTICK_PERIOD_MS);
}
}
推荐阅读
- java - 如何使用 AsyncTask 从 URL 返回单个对象
- java - 我可以使用 UUID 作为模型/pojo 类中使用休眠搜索的 id 字段的数据类型吗
- ruby - 如何使用 Mechanize 登录网站
- visual-studio-code - 自动完成时查看颜色预览的问题
- python - Sqlalchemy - 如何使用 SqlAlchemy 实现联合。?
- c# - 如何重写曾经在 .NET Core 2.0 中工作但在 3.0 中不起作用的 EF LINQ 查询?
- php - sqlite3 & PHP 结果为空:object(SQLite3Result)#3 (0) { }
- android-studio - Android Studio:如何禁用重新格式化代码完成弹出窗口
- css - 是否可以在 Sass 中动态调用 mixin?
- spring - 我如何解决无法在(“NAWFEL”。“ORDO_DEP_UUSATEUR”。“EMPLOI”)中插入 NULL 的错误