FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [September 2016 Threads] Creating tasksPosted by rclub123 on September 28, 2016 How to create two task such that one task runs at 0.5millisecond and another task runs at 100 millisecond using RTOS?
Creating tasksPosted by davedoors on September 28, 2016 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 tasksPosted by rclub123 on September 28, 2016 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 tasksPosted by rtel on September 28, 2016 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 tasksPosted by rclub123 on September 29, 2016 Thank you for your valuable suggestions... i have 1 last question..
i have created 2 tasks like below
~~~
void vTask0(void *pvParameters)
{
TickTypet xNextWakeTime;
const TickTypet 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)
{
TickTypet xNextWakeTime;
const TickTypet 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 tasksPosted by rtel on September 29, 2016 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 tasksPosted by rclub123 on September 29, 2016 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)..
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|