Creating tasks

How to create two task such that one task runs at 0.5millisecond and another task runs at 100 millisecond using RTOS?

Creating tasks

Use vTaskDelayUntil() http://www.freertos.org/vtaskdelayuntil.html see the example on the page. 0.5ms is very fast though best to trigger from an interrupt.http://www.freertos.org/vTaskNotifyGiveFromISR.html

Creating tasks

Thanks for your reply.. i followed that link you provided.. it is in the ticks.. means it perfoms the task after 10 ticks.. but i want this in milliseconds.. i want task to execute after 0.5 milliseconds and 100 millisecond.. how could i achieve that? My clock freq and tick rate is as below ~~~

define configCPUCLOCKHZ ((unsigned long)96000000)

define configTICKRATEHZ ((portTickType)1000)

~~~ edit: After reading some forums i understood about tick.. so configTICKRATEHZ=1000 means in 1 second OS will generate 1000 ticks… but i dont know how to get 0.5 milliseconds (because there is nothing like 0.5 ticks for 1000kHZ).. i think i need to change configTICKRATEHZ.. Am i right?

Creating tasks

If configTICKRATEHZ is 1000, then the tick frequency will be 1000Hz/1KHz. So one tick every ms, and a timing granularity of 1ms (so specifying a 1ms delay will give you between 0.0001ms and 0.9999ms). You cannot specify a 0.5ms delay time with a 1KHz tick rate, and it is not recommended to go over 1KHz. You can however trigger tasks from an interrupt, and a link to the recommended way of doing that has already been provided. Normally you would use the pdMSTOTICKS() macro to convert milliseconds into tick periods, but that won’t work if the tick rate is greater than 1KHz.

Creating tasks

Thank you for your valuable suggestions… i have 1 last question.. i have created 2 tasks like below ~~~ void vTask0(void *pvParameters) { TickType_t xNextWakeTime; const TickType_t xFrequency = 1; xNextWakeTime = xTaskGetTickCount();
while(1)
{
    if (xSemaphoreTake(xGPIOmutex, (portTickType)10) == pdTRUE)
    {
      adc_val[0]=ADC_read();
      xSemaphoreGive(xGPIOmutex);
      vTaskDelayUntil(&xNextWakeTime, xFrequency);
    }
    printf("channel 0 = %d n", adc_val[0]);
}
} ~~~ ~~~ void vTask1(void *pvParameters) { TickType_t xNextWakeTime; const TickType_t xFrequency = 10;
xNextWakeTime = xTaskGetTickCount();

  while (1)
  {

      if (xSemaphoreTake(xGPIOmutex, (portTickType)10) == pdTRUE)
      {
        adc_val[1]=ADC1_read();
        xSemaphoreGive(xGPIOmutex);
        vTaskDelayUntil(&xNextWakeTime, xFrequency);
      }
      printf("channel 1 = %d n", adc_val[1]);
  }
} ~~~ if i set xFrequency=1 in task 1, the above code(both task 1 and task 2) will execute only once.. if i put xFrequency=5 in task1 then both will work fine.. what might be the problem why it is not working if set xFrequency=1?

Creating tasks

I would expect it to work with xFrequency set to 1. What happens if you take out the call to printf()? Without printf() you might not be able to tell if it is working or not, so you can replace the printf() with a pin toggle that you can then view on a scope, or replace the printf() with a simple variable increment so when you pause the debugger you can view the variable’s value (use a different variable for each task and ensure the variable is declared volatile).

Creating tasks

I tried what you said.. i took variable ‘a’ for task1 and ‘b’ for task1 i add these two variables to watch list.. as per as my understanding of the code value of ‘b’ should be 10 multiple of ‘a’.. i.e. if b=1 then ‘a’ should be 10, if b=2, ‘a’ should be 20… but in my case it is random.. or may be “almost 5 multiple”(hope you understood)..