How run a FreeRTOS task at a specific hertz

brahmajit
Posts: 24
Joined: Wed Sep 08, 2021 10:31 am

How run a FreeRTOS task at a specific hertz

Postby brahmajit » Mon Jan 31, 2022 10:11 am

I'm new to programming and electronics in general. I want run a task at 100 Hz. Unfortunately I don't know how to do that with FreeRTOS, if anyone could help it would be very helpful.

Code: Select all

void Task1code( void * parameter ){
  Serial.print("Task1 running on core ");
  Serial.println(xPortGetCoreID());

  for(;;){
    // some code 
   // Pause the task for 500ms
    vTaskDelay(500 / portTICK_PERIOD_MS); // I guess this is something I need to change?
  } 
}
Thank you.

brahmajit
Posts: 24
Joined: Wed Sep 08, 2021 10:31 am

Re: How run a FreeRTOS task at a specific hertz

Postby brahmajit » Mon Jan 31, 2022 12:19 pm

Thanks to idahowalker from Arduino forum for this code snippet.

Code: Select all

void Task1code( void * parameter ){
  Serial.print("Task1 running on core ");
  Serial.println(xPortGetCoreID());
  TickType_t xLastWakeTime = xTaskGetTickCount();
  const TickType_t xFrequency = 5000; //delay for mS

  for(;;)
  {
        xLastWakeTime = xTaskGetTickCount();
    vTaskDelayUntil( &xLastWakeTime, xFrequency );

   // some code 
   // Pause the task for 500ms
      } 
}  // put your main code here, to run repeatedly:

Who is online

Users browsing this forum: No registered users and 124 guests