Inaccurate timings using FreeRTOS + LPC1769?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Inaccurate timings using FreeRTOS + LPC1769?

914件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xenod on Tue Apr 17 05:49:29 MST 2012
I have a problem with periodic task timing not being very accurate. For example a high priority task with 10ms period is executed somewhere between 7ms - 10ms intervalls.

The periodic timing of the task is achieved with the following code:

vTaskDelayUntil(&xLastWake,(10/portTICK_RATE_MS));


In the template for a FreeRTOS project there is a comment in the SetupHardware()-function that says that the system clock must be initialized to achieve accurate timing. Since I use CMSIS the function SystemInit(); is called from ResetISR on system boot. This function initializes the main oscillator and PLL to give CCLK of 100 Mhz and peripherals clock of 25 Mhz. Isn't this enough? Or do I have to re-init the clock in SetupHardware()?

Doesn't seem logical because as long as it is initialized before the scheduler is started everything should be ok?

Here's the code for SystemInit() from CMSIS-library:

void SystemInit (void)
{
#if (CLOCK_SETUP)                       /* Clock Setup                        */
  LPC_SC->SCS       = SCS_Val;
  if (SCS_Val & (1 << 5)) {             /* If Main Oscillator is enabled      */
    while ((LPC_SC->SCS & (1<<6)) == 0);/* Wait for Oscillator to be ready    */
  }

  LPC_SC->CCLKCFG   = CCLKCFG_Val;      /* Setup Clock Divider                */

  LPC_SC->PCLKSEL0  = PCLKSEL0_Val;     /* Peripheral Clock Selection         */
  LPC_SC->PCLKSEL1  = PCLKSEL1_Val;

  LPC_SC->CLKSRCSEL = CLKSRCSEL_Val;    /* Select Clock Source for PLL0       */

#if (PLL0_SETUP)
  LPC_SC->PLL0CFG   = PLL0CFG_Val;      /* configure PLL0                     */
  LPC_SC->PLL0FEED  = 0xAA;
  LPC_SC->PLL0FEED  = 0x55;

  LPC_SC->PLL0CON   = 0x01;             /* PLL0 Enable                        */
  LPC_SC->PLL0FEED  = 0xAA;
  LPC_SC->PLL0FEED  = 0x55;
  while (!(LPC_SC->PLL0STAT & (1<<26)));/* Wait for PLOCK0                    */

  LPC_SC->PLL0CON   = 0x03;             /* PLL0 Enable & Connect              */
  LPC_SC->PLL0FEED  = 0xAA;
  LPC_SC->PLL0FEED  = 0x55;
  while (!(LPC_SC->PLL0STAT & ((1<<25) | (1<<24))));/* Wait for PLLC0_STAT & PLLE0_STAT */
#endif

#if (PLL1_SETUP)
  LPC_SC->PLL1CFG   = PLL1CFG_Val;
  LPC_SC->PLL1FEED  = 0xAA;
  LPC_SC->PLL1FEED  = 0x55;

  LPC_SC->PLL1CON   = 0x01;             /* PLL1 Enable                        */
  LPC_SC->PLL1FEED  = 0xAA;
  LPC_SC->PLL1FEED  = 0x55;
  while (!(LPC_SC->PLL1STAT & (1<<10)));/* Wait for PLOCK1                    */

  LPC_SC->PLL1CON   = 0x03;             /* PLL1 Enable & Connect              */
  LPC_SC->PLL1FEED  = 0xAA;
  LPC_SC->PLL1FEED  = 0x55;
  while (!(LPC_SC->PLL1STAT & ((1<< 9) | (1<< 8))));/* Wait for PLLC1_STAT & PLLE1_STAT */
#else
  LPC_SC->USBCLKCFG = USBCLKCFG_Val;    /* Setup USB Clock Divider            */
#endif

  LPC_SC->PCONP     = PCONP_Val;        /* Power Control for Peripherals      */

  LPC_SC->CLKOUTCFG = CLKOUTCFG_Val;    /* Clock Output Configuration         */
#endif

#if (FLASH_SETUP == 1)                  /* Flash Accelerator Setup            */
  LPC_SC->FLASHCFG  = (LPC_SC->FLASHCFG & ~0x0000F000) | FLASHCFG_Val;
#endif
}
0 件の賞賛
返信
1 返信

832件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Tue Apr 17 09:07:36 MST 2012
This is very strange.
The  FreeRTOS tick is created using the systick timer running at 1 msec
and vTaskDelayUntil waits until the tick counter is at the given value (i.e. 10 msec after you read the tick timer.

If your task runs at a rate that is shorter than 10 msec, there must be a problem with your program.

Rob
0 件の賞賛
返信