1、 先了解一下我上篇写的。
//www.greatytc.com/p/1f7bb66d9b40
2、 创建了一个定时器
static void periodic_timer_callback(void* arg)
{
//int64_t time_since_boot = esp_timer_get_time();
//ESP_LOGI(TAG, "Periodic timer called, time since boot: %010lld us", time_since_boot);
printf("------->Event PCNT unit<-------------%d\n",hallGetCounter(HALL_PCNT_UINT_L));
hallClearCounter(HALL_PCNT_UINT_L);
}
void my_time_init(void)
{
const esp_timer_create_args_t periodic_timer_args = {
.callback = &periodic_timer_callback,
/* name is optional, but may help identify the timer when debugging */
.name = "periodic"
};
esp_timer_handle_t periodic_timer;
ESP_ERROR_CHECK(esp_timer_create(&periodic_timer_args, &periodic_timer));
ESP_ERROR_CHECK(esp_timer_start_periodic(periodic_timer, 1000000));
}
3、 创建4个任务
void reset_task(void *arg)
{
uint32_t i;
uint32_t j;
int *tab;
while(1)
{
i=0xfffff;
while(i)
{
i--;
for (j=0; j<100;j++)
{
}
}
printf("------->reset_task<------------:%d\n",*((int *) arg));
vTaskDelay(1000 / portTICK_RATE_MS);
}
}
int task1_par =1;
int task2_par =2;
int task3_par =3;
int task4_par =4;
void my_create_task(void)
{
xTaskCreatePinnedToCore(reset_task, "reset task", 2048, (void*)&task1_par, 10, NULL, 1);
xTaskCreatePinnedToCore(reset_task, "reset task", 2048, (void*)&task2_par, 10, NULL, 1);
xTaskCreatePinnedToCore(reset_task, "reset task", 2048, (void*)&task3_par, 10, NULL, 0);
xTaskCreatePinnedToCore(reset_task, "reset task", 2048, (void*)&task4_par, 10, NULL, 0);
}
4、测试应用和效果
void app_main()
{
hallInit();
hallStartCounter(HALL_PCNT_UINT_L);
my_time_init();
my_create_task();
while(1)
{
vTaskDelay(1000 / portTICK_RATE_MS);
}
}
在这种极端的条件下,误差在0.7%。