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

VtaskDelay problem on PIC24

Posted by Quatoria on August 23, 2013
Dear,

I am having problem with Vtaskdelay function its seems to never return, my code is very simple :

void vTaskCode( void * pvParameters )
{
for( ;; )
{
PORTDbits.RD2 = 0;
vTaskDelay(100);
PORTDbits.RD2 = 1;
vTaskDelay(100);
}
}

int main(int argc, char** argv) {

vP24Initialise();

xTaskCreate( vTaskCode, "NAME", comSTACK_SIZE,NULL, 2,NULL);

vTaskStartScheduler();

while (1);
/* Will only reach here if there is insufficient heap available to start
the scheduler. */
return 0;

}

Using Freertos 7.5.2 on Pic24FJ256GA106.

Any idea will help.

Thanks

RE: VtaskDelay problem on PIC24

Posted by MEdwards on August 23, 2013
Is the tick interrupt running? If not time will stand still so the 100 tick delay will not time out.

RE: VtaskDelay problem on PIC24

Posted by Quatoria on August 24, 2013
In fact any delay is not working, may be I miss some init function for FreeRtos ?

Rgds

RE: VtaskDelay problem on PIC24

Posted by Quatoria on August 24, 2013
Just for more information, this is an extract of hardwareprofile.h :

#define GetSystemClock() 32000000UL
#define GetPeripheralClock() (GetSystemClock() / 2)
#define GetInstructionClock() (GetSystemClock() / 2)
#define MILLISECONDS_PER_TICK 10
#define TIMER_PRESCALER TIMER_PRESCALER_8 //TIMER_PRESCALER_1
#define TIMER_PERIOD 20000 //40000

and my freertosconfig.h :

#define MPLAB_PIC24_PORT

#define configUSE_PREEMPTION1
#define configUSE_IDLE_HOOK0
#define configUSE_TICK_HOOK0
#define configTICK_RATE_HZ( ( portTickType ) 1000 )
#define configCPU_CLOCK_HZ( ( unsigned long ) 16000000 ) /* 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_FACILITY0
#define configUSE_16_BIT_TICKS1
#define configIDLE_SHOULD_YIELD1

/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#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_vTaskPrioritySet1
#define INCLUDE_uxTaskPriorityGet0
#define INCLUDE_vTaskDelete1
#define INCLUDE_vTaskCleanUpResources1
#define INCLUDE_vTaskSuspend1
#define INCLUDE_vTaskDelayUntil1
#define INCLUDE_vTaskDelay1


#define configKERNEL_INTERRUPT_PRIORITY0x01


if anybody has an idea to help me, welcome :-)

RE: VtaskDelay problem on PIC24

Posted by Richard on August 24, 2013
I agree with edwards3 diagnosis in post 2. Did you check that? You can do by either setting a break point in the tick interrupt or simply letting the program run for a while then inspecting the xTickCount variable in FreeRTOS/Source/tasks.c

Regards.

RE: VtaskDelay problem on PIC24

Posted by Quatoria on August 24, 2013
I think the tick interrupt is set correctly, I put an applicationtickhook handler and discovered strange behavior, I entered only one time in vapplicationtickhook or if I follow correctly I should enter each tick time ?


void vApplicationTickHook( void )
{
ul++;
if (ul == 2) {PORTDbits.RD2 = 1;} // ul == 1 yes greater never

}

RE: VtaskDelay problem on PIC24

Posted by Quatoria on August 24, 2013
I discovered strange things the init of tick timer int is done correctly as this : __attribute__(( weak )) void vApplicationSetupTickTimerInterrupt( void )
{
const unsigned long ulCompareMatch = ( ( configCPU_CLOCK_HZ / portTIMER_PRESCALE ) / configTICK_RATE_HZ ) - 1;

/* Prescale of 8. */
T1CON = 0;
TMR1 = 0;

PR1 = ( unsigned short ) ulCompareMatch;

/* Setup timer 1 interrupt priority. */
IPC0bits.T1IP = configKERNEL_INTERRUPT_PRIORITY;

/* Clear the interrupt as a starting condition. */
IFS0bits.T1IF = 0;

/* Enable the interrupt. */
IEC0bits.T1IE = 1;

/* Setup the prescale value. */
T1CONbits.TCKPS0 = 1;
T1CONbits.TCKPS1 = 0;

/* Start the timer. */
T1CONbits.TON = 1;


}

BUT it never reaches the interrupt routine :

void __attribute__((__interrupt__, auto_psv)) configTICK_INTERRUPT_HANDLER( void )
{
/* Clear the timer interrupt. */
IFS0bits.T1IF = 0;
LATDbits.LATD2 = ~LATDbits.LATD2;
if( xTaskIncrementTick() != pdFALSE )
{
portYIELD();
}
}

Any idea ?

RE: VtaskDelay problem on PIC24

Posted by MEdwards on August 24, 2013
configTICK_INTERRUPT_HANDLER defaults to _T1Interrupt. Is that the name used for the timer 1 interrupt in your build?

RE: VtaskDelay problem on PIC24

Posted by Quatoria on August 24, 2013
Yes at the begining of port.c ther is :

#ifndef configTICK_INTERRUPT_HANDLER
#define configTICK_INTERRUPT_HANDLER _T1Interrupt
#endif /* configTICK_INTERRUPT_HANDLER */

I am just thinking if there is any problem with my config flag may be ?

_CONFIG2(FNOSC_PRI & POSCMOD_HS & IOL1WAY_OFF )// Primary HS OSC
_CONFIG1(JTAGEN_OFF & FWDTEN_OFF & ICS_PGx2 )// JTAG off, watchdog timer off

Regards

RE: VtaskDelay problem on PIC24

Posted by woops_ on August 24, 2013
if the tick hook is hit once then the interrupt install must be ok and clearing the interrupt or peripheral seems to be the cause. it can be that the config bits get set in the IDE not the source code, check your project to see which. normally projects should not need any changes to run.

RE: VtaskDelay problem on PIC24

Posted by Quatoria on August 24, 2013
I can confirm that the interrupt handler :

void __attribute__((__interrupt__, auto_psv)) configTICK_INTERRUPT_HANDLER( void )
{
/* Clear the timer interrupt. */
IFS0bits.T1IF = 0;
LATDbits.LATD2 = ~LATDbits.LATD2;
if( xTaskIncrementTick() != pdFALSE )
{
portYIELD();
}
}

is NEVER called not at least one time.

RE: VtaskDelay problem on PIC24

Posted by Quatoria on August 25, 2013
No more progress the interrupt is never called, do I need special things to configure since I am in mplabX latest version ?

RE: VtaskDelay problem on PIC24

Posted by Richard on August 25, 2013
I'm not sure which is the latest, but using V1.80 I have just taken a clean download, opened the PIC24 project, set the debugger to use the simulator, built and started a debug session. The result is that - without having made any changes other than setting the debugger to use the simulator - the timer's interrupt service routine is being hit and the tick count is being incremented.

Can you try doing the same?

Regards.

RE: VtaskDelay problem on PIC24

Posted by Richard on August 25, 2013
....using V1.80 of MPLAB X, if that was not clear in my previous post.

Regards.

RE: VtaskDelay problem on PIC24

Posted by Quatoria on August 26, 2013
Dear Richard,

Many thanks to all for you support I finally solved my problem and I wanted to share the solution with you, after hours and hours of searching I came to the conclusion that the Interrupt was never called due to some bad information during linking.

I have to precise that I am not using same pic of FreeRtos demo which is P24FJ128GA010, my pic with my own hardware is P24FJ256GA106, so when importing in MPALB X version 1.85 the whole demo I was oblige to tell the linker that GLD file is different and I imported the one provided in microchip library BUT this file is wrong it has bad entry for IVT and alternate IVT, I finally decided to copy and paste all the IVT and alt IVT section from freertos demo and the Interrupt is now working...
I did not contacted yet Microchip for this problem.

Hope it helps future user.

Best Regards


[ 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