Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




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 ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists