Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

Creating tasks

Posted 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 tasks

Posted 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 tasks

Posted 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 tasks

Posted 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 tasks

Posted 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 tasks

Posted 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 tasks

Posted 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)..


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner