# Execution only in last created task

**URL:** <https://forums.freertos.org/t/execution-only-in-last-created-task/4011>\
**Category:** Kernel\
**Created:** [September 10, 2013, 6:48am UTC](https://forums.freertos.org/t/execution-only-in-last-created-task/4011 "2013-09-10T06:48:24Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 10, 2013, 6:48am UTC](https://forums.freertos.org/t/execution-only-in-last-created-task/4011/1 "2013-09-10T06:48:24Z")

</div>

**[amarjith](https://sourceforge.net/u/amarjith/)** wrote on [Tuesday, September 10, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/b09b5a49/#1dd5):

I am beginner in RTOS here i tried to execute four tasks simultaneously(with same priority). But the program execution is only in Task4 and never exit the loop.Using pic24fj256ga106 and FreeRTOS7.5.3 ,&nbsp; I set break point in task4 as shown&nbsp; below when execution reaches at break point the values are a=0,b=0,c=0,d=0 and xTickCount =0. if i run one time it again reach the break point and values would be a=0,b=0,c=0,d=1 and xTickCount =94, 2nd time a=0,b=0,c=0,d=2 and xTickCount =188 and so on , it never exit task4. Please help me what could be the reason how can i run all simultaneously. please…

unsigned int a=0,b=0,c=0,d=0;  
int main( void )  
{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; prvSetupHardware();  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xTaskCreate( vTask1, “Task 1”, 200, NULL, 1, NULL );  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xTaskCreate( vTask2, “Task 2”, 200, NULL, 1, NULL );

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xTaskCreate( vTask3, “Task 2”, 200, NULL, 1, NULL );

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xTaskCreate( vTask4, “Task 2”, 200, NULL, 1, NULL );  
vTaskStartScheduler();

/\* If all is well then main() will never reach here as the scheduler will  
now be running the tasks. If main() does reach here then it is likely that  
there was insufficient heap memory available for the idle task to be created.  
CHAPTER 5 provides more information on memory management. \*/  
for( ;; );  
}

void vTask1( void \*pvParameters )  
{  
&nbsp;&nbsp;&nbsp; volatile unsigned long ul;  
for( ;; )  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PORTF = 0x0004;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a++;  
&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;

}

void vTask2( void \*pvParameters )  
{  
&nbsp;&nbsp;&nbsp; volatile unsigned long ul;  
for( ;; )  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PORTF = 0x0008;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b++;  
&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;

}

void vTask3( void \*pvParameters )  
{  
&nbsp;&nbsp;&nbsp; volatile unsigned long ul;  
for( ;; )  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PORTF = 0x0008;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c++;  
&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;

}

void vTask4( void \*pvParameters )  
{  
&nbsp;&nbsp;&nbsp; volatile unsigned long ul;

&nbsp;&nbsp;&nbsp; for( ;; )  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PORTF = 0x0008;&nbsp;&nbsp;&nbsp; // set break point here  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d++;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for( ul = 0; ul \< 50000; ul++ )  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PORTF = 0x0004;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for( ul = 0; ul \< 50000; ul++ )  
&nbsp;&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;  
&nbsp;&nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp; }  
}

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [September 10, 2013, 8:20am UTC](https://forums.freertos.org/t/execution-only-in-last-created-task/4011/2 "2013-09-10T08:20:43Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, September 10, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/b09b5a49/#b881):

The fact that the tick count is increasing shows the tick interrupt is executing, and each task has the same priority, so I’m not sure why they are not time slicing.&nbsp; From your code you would expect a, b and c to increment a lot faster than d as those tasks don’t contain the loop.&nbsp; I just executed your exact code (unmodified) in the Windows simulator and the behaviour was as expected.&nbsp; I don’t have the PIC24 hardware with me at the moment to try it on that.

One thing comes to mind.&nbsp; Do you have configUSE\_PREEMPTION set to 1 in FreeRTOSConfig.h?&nbsp; If it is set to 0 then a task switch will only happen if you call taskYIELD() in the implementation of the task.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 10, 2013, 9:24am UTC](https://forums.freertos.org/t/execution-only-in-last-created-task/4011/3 "2013-09-10T09:24:30Z")

</div>

**[amarjith](https://sourceforge.net/u/amarjith/)** wrote on [Tuesday, September 10, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/b09b5a49/#69ed):

Thank you for reply. I am expecting the result like a=1,b=1,c=1,d=1 in a single cycle of process.&nbsp;&nbsp;&nbsp;&nbsp; configUSE\_PREEMPTION is 1&nbsp; in FreeRTOSConfig.h.&nbsp; I am doing in MPLABX&nbsp; linux, and here some more things i observed&nbsp;&nbsp; if i delete two delay&nbsp; for() loop in task4 the&nbsp; xTickCount&nbsp; won’t increment it remains 0, d would increment by 1. If i put delay it would increment as i said before.&nbsp; I executed code step by step first execution will enter

void vTaskStartScheduler( void )

then

xReturn = xTaskCreate( prvIdleTask, ( signed char \* ) “IDLE”, tskIDLE\_STACK\_SIZE, ( void \* ) NULL, ( tskIDLE\_PRIORITY | portPRIVILEGE\_BIT ), NULL );

then

if( xReturn == pdPASS )  
{  
/\* Interrupts are turned off here, to ensure a tick does not occur  
before or during the call to xPortStartScheduler().&nbsp; The stacks of  
the created tasks contain a status word with interrupts switched on  
so interrupts will automatically get re-enabled when the first task  
starts to run.

STEPPING THROUGH HERE USING A DEBUGGER CAN CAUSE BIG PROBLEMS IF THE  
DEBUGGER ALLOWS INTERRUPTS TO BE PROCESSED. \*/  
portDISABLE\_INTERRUPTS();

xSchedulerRunning = pdTRUE;  
xTickCount = ( portTickType ) 0U;

/\* If configGENERATE\_RUN\_TIME\_STATS is defined then the following  
macro must be defined to configure the timer/counter used to generate  
the run time counter time base. \*/  
portCONFIGURE\_TIMER\_FOR\_RUN\_TIME\_STATS();

/\* Setting up the timer tick is hardware specific and thus in the  
portable interface. \*/  
if( xPortStartScheduler() != pdFALSE )

after this line enters directly to Task4. why this happening ?&nbsp; if i delete Task4, Task 3 behaves like, if delete task3 Task 2 only work.&nbsp; Execution is only in the Task which i created last.

void vTaskStartScheduler( void )  
{  
portBASE\_TYPE xReturn;

/\* Add the idle task at the lowest priority. \*/  
#if ( INCLUDE\_xTaskGetIdleTaskHandle == 1 )  
{  
/\* Create the idle task, storing its handle in xIdleTaskHandle so it can  
be returned by the xTaskGetIdleTaskHandle() function. \*/  
xReturn = xTaskCreate( prvIdleTask, ( signed char \* ) “IDLE”, tskIDLE\_STACK\_SIZE, ( void \* ) NULL, ( tskIDLE\_PRIORITY | portPRIVILEGE\_BIT ), &xIdleTaskHandle ); /\*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. \*/  
}  
#else  
{  
/\* Create the idle task without storing its handle. \*/  
xReturn = xTaskCreate( prvIdleTask, ( signed char \* ) “IDLE”, tskIDLE\_STACK\_SIZE, ( void \* ) NULL, ( tskIDLE\_PRIORITY | portPRIVILEGE\_BIT ), NULL );&nbsp; /\*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. \*/  
}  
#endif /\* INCLUDE\_xTaskGetIdleTaskHandle \*/

#if ( configUSE\_TIMERS == 1 )  
{  
if( xReturn == pdPASS )  
{  
xReturn = xTimerCreateTimerTask();  
}  
}  
#endif /\* configUSE\_TIMERS \*/

if( xReturn == pdPASS )  
{  
/\* Interrupts are turned off here, to ensure a tick does not occur  
before or during the call to xPortStartScheduler().&nbsp; The stacks of  
the created tasks contain a status word with interrupts switched on  
so interrupts will automatically get re-enabled when the first task  
starts to run.

STEPPING THROUGH HERE USING A DEBUGGER CAN CAUSE BIG PROBLEMS IF THE  
DEBUGGER ALLOWS INTERRUPTS TO BE PROCESSED. \*/  
portDISABLE\_INTERRUPTS();

xSchedulerRunning = pdTRUE;  
xTickCount = ( portTickType ) 0U;

/\* If configGENERATE\_RUN\_TIME\_STATS is defined then the following  
macro must be defined to configure the timer/counter used to generate  
the run time counter time base. \*/  
portCONFIGURE\_TIMER\_FOR\_RUN\_TIME\_STATS();

/\* Setting up the timer tick is hardware specific and thus in the  
portable interface. \*/  
if( xPortStartScheduler() != pdFALSE )  
{  
/\* Should not reach here as if the scheduler is running the  
function will not return. \*/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Nop();  
}  
else  
{  
Nop();/\* Should only reach here if a task calls xTaskEndScheduler(). \*/  
}  
}  
else  
{  
/\* This line will only be reached if the kernel could not be started,  
because there was not enough FreeRTOS heap to create the idle task  
or the timer task. \*/  
configASSERT( xReturn );  
}  
}

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [September 10, 2013, 10:00am UTC](https://forums.freertos.org/t/execution-only-in-last-created-task/4011/4 "2013-09-10T10:00:30Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, September 10, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/b09b5a49/#7fc6):

I have just tried:

1) Taking the PIC24 MPLAB X project in the FreeRTOS download.  
2) Replaced main() in the project with your main().  
3) Added in your four task definitions, and the a, b, c and d variables (cut and paste from your post).  
4) Changed the project to use the simulator instead of the real hardware.  
5) Built and executed the project.

All the variables are being incremented - a, b and c are incremented very quickly, d is incremented much more slowly, as expected.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 10, 2013, 10:38am UTC](https://forums.freertos.org/t/execution-only-in-last-created-task/4011/5 "2013-09-10T10:38:07Z")

</div>

**[amarjith](https://sourceforge.net/u/amarjith/)** wrote on [Tuesday, September 10, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/b09b5a49/#db63):

Ho!!. … Let me know what simulator you are using? Here what could be the cause of error , can you&nbsp; guess or any suggestion please?? i tried every known possibilities.&nbsp; :-(.&nbsp; I tried with taskYIELD(),&nbsp; vTaskDelete( NULL ), vTaskDelay( 2) etc… No change.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [September 10, 2013, 10:47am UTC](https://forums.freertos.org/t/execution-only-in-last-created-task/4011/6 "2013-09-10T10:47:57Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, September 10, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/b09b5a49/#37cc):

> Let me know what simulator you are using?

The one in MPLAB X.

> what could be the cause of error

I really don’t know.&nbsp; As I said, the tick interrupt is evidently running so it should not be a problem.&nbsp; You might want to double check that the tick interrupt really is running by placing a break point in configTICK\_INTERRUPT\_HANDLER(), which is in FreeRTOS/Source/portable/MPLAB/PIC24\_dsPIC/port.c.&nbsp; You can also step through the function, which should call portYIELD(), which is itself a function you can step through.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 10, 2013, 11:30am UTC](https://forums.freertos.org/t/execution-only-in-last-created-task/4011/7 "2013-09-10T11:30:21Z")

</div>

**[amarjith](https://sourceforge.net/u/amarjith/)** wrote on [Tuesday, September 10, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/b09b5a49/#4c1d):

xTickCount is not incrementing (when watch xTickCount&nbsp; in debugging mode) if i delete delay loops for( ul = 0; ul \< 50000; ul++ ) { ; }&nbsp; in Task4 . If the error is in tick interrup how can i fix it.&nbsp;

in

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [September 10, 2013, 11:42am UTC](https://forums.freertos.org/t/execution-only-in-last-created-task/4011/8 "2013-09-10T11:42:56Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, September 10, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/b09b5a49/#a0b5):

Are you using the default tick interrupt handler provided in port.c, or providing your own?  
Are you using the same chip as used in the demo, or have you retargeted the demo to a different chip?

Most likely the source of the issue will be in the configuration bits, especially if you have changed the target chip in the project options.&nbsp; Take a look using the Windows-\>PIC Memory Views-\>Configuration Bits menu option in MPLAB X.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 10, 2013, 12:02pm UTC](https://forums.freertos.org/t/execution-only-in-last-created-task/4011/9 "2013-09-10T12:02:18Z")

</div>

**[amarjith](https://sourceforge.net/u/amarjith/)** wrote on [Tuesday, September 10, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/b09b5a49/#25cd):

I didnt&nbsp; make any change in the downloaded code FreeRTOS7.5.3&nbsp; only added four tasks in the main.&nbsp; I am using pic24fj256GA106, and configuaration settings

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
\* Configuration bits for&nbsp; processor &nbsp; \*  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

// PIC24FJ256GA106 Configuration Bit Settings

#include \<xc.h\>

// CONFIG3  
#pragma config WPFP = WPFP5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Write Protection Flash Page Segment Boundary (Page 5 (0x1400))  
#pragma config WPDIS = WPDIS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Segment Write Protection Disable bit (Segmented code protection disabled)  
#pragma config WPCFG = WPCFGDIS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Configuration Word Code Page Protection Select bit (Last page(at the top of program memory) and Flash configuration words are not protected)  
#pragma config WPEND = WPSTARTMEM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Segment Write Protection End Page Select bit (Write Protect from page 0 to WPFP)

// CONFIG2  
#pragma config POSCMOD = NONE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Primary Oscillator Select (Primary oscillator disabled)  
#pragma config IOL1WAY = ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // IOLOCK One-Way Set Enable bit (Write RP Registers Once)  
#pragma config OSCIOFNC = OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Primary Oscillator Output Function (OSCO functions as CLKO (FOSC/2))  
#pragma config FCKSM = CSDCMD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Clock Switching and Monitor (Both Clock Switching and Fail-safe Clock Monitor are disabled)  
#pragma config FNOSC = FRC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Oscillator Select (Fast RC Oscillator (FRC))  
#pragma config IESO = ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Internal External Switch Over Mode (IESO mode (Two-speed start-up) enabled)

// CONFIG1  
#pragma config WDTPS = PS32768&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Watchdog Timer Postscaler (1:32,768)  
#pragma config FWPSA = PR128&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // WDT Prescaler (Prescaler ratio of 1:128)  
#pragma config WINDIS = OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Watchdog Timer Window (Standard Watchdog Timer is enabled,(Windowed-mode is disabled))  
#pragma config FWDTEN = OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Watchdog Timer Enable (Watchdog Timer is disabled)  
#pragma config ICS = PGx2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Comm Channel Select (Emulator functions are shared with PGEC2/PGED2)  
#pragma config GWRP = OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // General Code Segment Write Protect (Writes to program memory are allowed)  
#pragma config GCP = OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // General Code Segment Code Protect (Code protection is disabled)  
#pragma config JTAGEN = OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // JTAG Port Enable (JTAG port is disabled)

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [September 10, 2013, 12:14pm UTC](https://forums.freertos.org/t/execution-only-in-last-created-task/4011/10 "2013-09-10T12:14:52Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, September 10, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/b09b5a49/#cf9e):

Are these bits generated by the settings in the IDE?

I can see a few differences in the settings you posted compared to the settings in the IDE window opened using the menu item I mentioned above - for CONFIG1 anyway.&nbsp; I can’t see any settings for CONFIG2.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 10, 2013, 12:34pm UTC](https://forums.freertos.org/t/execution-only-in-last-created-task/4011/11 "2013-09-10T12:34:50Z")

</div>

**[amarjith](https://sourceforge.net/u/amarjith/)** wrote on [Tuesday, September 10, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/b09b5a49/#7ec8):

Yes, iam using MPLAB X IDE v1.80, with XC16 compiler. will you please post the setting which you have? it may another version of&nbsp; MPLAB .

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [September 10, 2013, 1:29pm UTC](https://forums.freertos.org/t/execution-only-in-last-created-task/4011/12 "2013-09-10T13:29:34Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, September 10, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/b09b5a49/#3cde):

It is not easy to post an image here, but if you take a clean FreeRTOS distribution, open the project, and then view the configuration bits window you will see what they are set to.&nbsp; This is all assuming the project is somehow configured to use the bits that are defined by the settings in that window.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 11, 2013, 7:58am UTC](https://forums.freertos.org/t/execution-only-in-last-created-task/4011/13 "2013-09-11T07:58:20Z")

</div>

**[amarjith](https://sourceforge.net/u/amarjith/)** wrote on [Wednesday, September 11, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/b09b5a49/#eaf8):

i coudnt find anything wrong in configuration bits, let me ask you something

here i checked Task1

void vTask1( void \*pvParameters )  
{  
&nbsp;&nbsp;&nbsp;&nbsp; volatile unsigned long ul;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp; for( ;; )  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PORTF = 0x0004;&nbsp;&nbsp;&nbsp;&nbsp; //set break point here  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a++;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for( ul = 0; ul \< 1000; ul++ )  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {

/\* This loop is just a very crude delay implementation. There is  
nothing to do in here. Later examples will replace this crude  
loop with a proper delay/sleep function. \*/  
}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp; }

}

when i execute one time in the Task1 loop a =1, XTickCount=1, 2nt time a =2, XTickCount=2 and so on.&nbsp; If i replace&nbsp; for( ul = 0; ul \< 1000; ul++ ) {}&nbsp; with&nbsp;&nbsp;&nbsp; vTaskDelay(200);&nbsp;&nbsp; XTick Count starts counting when a=63, XTick Count&nbsp; would be 2 in next 63. i tried with&nbsp; vTaskDelay(20000); ,vTaskDelay(200000);&nbsp; ,vTaskDelay(2); but no change in this relation XTick Count starts counting only when a=63,.&nbsp; when it switch to another task(&nbsp; XTickCount&nbsp; value?)

///////////FreeRTOSConfig/////////

#ifndef FREERTOS\_CONFIG\_H  
#define FREERTOS\_CONFIG\_H

#include \<p24FJ256GA106.h\>

/\*---------------------------------------  
\* Application specific definitions.  
\*  
\* These definitions should be adjusted for your particular hardware and  
\* application requirements.  
\*  
\* THESE PARAMETERS ARE DESCRIBED WITHIN THE ‘CONFIGURATION’ SECTION OF THE  
\* FreeRTOS API DOCUMENTATION AVAILABLE ON THE [FreeRTOS.org](http://FreeRTOS.org) WEB SITE.  
\*  
\* See [http://www.freertos.org/a00110.html.](http://www.freertos.org/a00110.html.)  
\*---------------------------------------\*/

#define configUSE\_PREEMPTION 1  
#define configUSE\_IDLE\_HOOK 1  
#define configUSE\_TICK\_HOOK 0  
#define configTICK\_RATE\_HZ ( ( portTickType ) 10000 )  
#define configCPU\_CLOCK\_HZ ( ( unsigned long ) 16000000 )&nbsp; /\* Fosc / 2 \*/  
#define configMAX\_PRIORITIES ( ( unsigned portBASE\_TYPE ) 4 )  
#define configMINIMAL\_STACK\_SIZE ( 115 )  
#define configTOTAL\_HEAP\_SIZE ( ( size\_t ) 5120 )  
#define configMAX\_TASK\_NAME\_LEN ( 4 )  
#define configUSE\_TRACE\_FACILITY 0  
#define configUSE\_16\_BIT\_TICKS 1  
#define configIDLE\_SHOULD\_YIELD 1

/\* Co-routine definitions. \*/  
#define configUSE\_CO\_ROUTINES 1  
#define configMAX\_CO\_ROUTINE\_PRIORITIES ( 2 )

/\* Set the following definitions to 1 to include the API function, or zero  
to exclude the API function. \*/

#define INCLUDE\_vTaskPrioritySet 1  
#define INCLUDE\_uxTaskPriorityGet 0  
#define INCLUDE\_vTaskDelete 0  
#define INCLUDE\_vTaskCleanUpResources 0  
#define INCLUDE\_vTaskSuspend 1  
#define INCLUDE\_vTaskDelayUntil 1  
#define INCLUDE\_vTaskDelay 1

#define configKERNEL\_INTERRUPT\_PRIORITY 0x01

#endif /\* FREERTOS\_CONFIG\_H \*/

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [September 11, 2013, 10:34am UTC](https://forums.freertos.org/t/execution-only-in-last-created-task/4011/14 "2013-09-11T10:34:27Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, September 11, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/b09b5a49/#5dd4):

You have configTICK\_RATE\_HZ set to 10KHz, which is **extremely** fast, probably to fast by a factor of about 100 at least.&nbsp; I suspect most of your CPU time will be spend servicing interrupts.&nbsp; Try setting it to 100.

You also have configUSE\_16\_BIT\_TICKS, which means the maximum number of ticks you can block for is 0xffff.&nbsp; With a tick frequency of 10KHz the tick count will overflow every 6 seconds (which doesn’t matter to FreeRTOS).

When you replace the loop with vTaskDelay(200); I would expect there to be a minimum of 200 ticks between each increment of a, and I would not expect a to increment more than once before the tick count reached 200 minimum.&nbsp;

If I were to set up a test here again I’m sure that is what I would find as when I replicated your tests yesterday I found everything function as expected, and I could not replicate your results.&nbsp; Sorry - I don’t know what is wrong with your project, but obviously something quite fundamental.&nbsp; Maybe it is related to the extremely fast tick you have configured.

Maybe as an aside, if you have configTICK\_RATE\_HZ set above 1000 then you cannot use the portTICK\_RATE\_MS constant.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 11, 2013, 11:38am UTC](https://forums.freertos.org/t/execution-only-in-last-created-task/4011/15 "2013-09-11T11:38:48Z")

</div>

**[amarjith](https://sourceforge.net/u/amarjith/)** wrote on [Wednesday, September 11, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/b09b5a49/#89f5):

Thank you so much for all your support and valuable time. Its working now, actually i got FreeRTOS code (which i worked so far)&nbsp; from my friend not downloaded from here, I have downloaded new and checked, everything is fine. Thanks again for all your help!&nbsp; 🙂
