I found a BUG in IAR LPC2129 PORT

nobody wrote on Tuesday, March 21, 2006:

Salam,

in port.c

ulCompareMatch = configCPU_CLOCK_HZ / configTICK_RATE_HZ;

That’s wrong cause the clock of the peripherals (include Timer0) is NOT CPU Clock (CCLK) but it’s PCLK.

and

PCLK = CCLK / VBP Divider

At reset for LPC2129 VBP Divider = 4

So The above line must be

ulCompareMatch = (configCPU_CLOCK_HZ /4 ) / configTICK_RATE_HZ;

I found this bug when i was trying to blink a led every second using vTaskDelayUntil

Here is my working code.

static void vTaskCode(void *pvParameters)
{
    portTickType xLastWakeTime;
    const portTickType xFrequency = 1000;
    xLastWakeTime = xTaskGetTickCount();

    for (;:wink: {
         Led_Toggle();
         vTaskDelayUntil( &xLastWakeTime, xFrequency );
    }
}

Bye
Eng. Amr Ahmed
EGYPT

nobody wrote on Tuesday, March 21, 2006:

I forgot to mention that configTICK_RATE_HZ must be configure to 1000 in freeRTOSconfig.h to use the above task to blink the led every 1 SEC :slight_smile:

Enjoy
Amr Ahmed
EGYPT

nobody wrote on Tuesday, March 21, 2006:

I think, as downloaded, the line should actually be:

ulCompareMatch = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1;

cpu clock being defined to the correect value for the equation.

You change the value or use different hardware?

nobody wrote on Tuesday, March 21, 2006:

AS DOWNLOADED THE LINE IS

/* Calculate the match value required for our wanted tick rate. */
ulCompareMatch = configCPU_CLOCK_HZ / configTICK_RATE_HZ;

THAT IS NOT RIGHTTTTTTTTTTTT

nobody wrote on Tuesday, March 21, 2006:

AS DOWNLOADED

ulCompareMatch = configCPU_CLOCK_HZ / configTICK_RATE_HZ;

This is not right !!!

I use Olimex board (LPC2129)

So configCPU_CLOCK_HZ = 14745600 (crystal value)

I didn’t use the PLL.

#define configCPU_CLOCK_HZ            ( ( unsigned portLONG ) 14745600 )

BYE

nobody wrote on Tuesday, March 21, 2006:

It is right if you are using the same software and hardware as the demo with no modifications at all.  I know because I can time the LED’s flashing and they are exactly correct.

I think you are making an assumption as to what configCPU_CLOCK_HZ means.  This should be set to the frequency as used by the timer which may but probably will not be the same as some other clocks on the system.

nobody wrote on Tuesday, March 21, 2006:

That’s right man.

configCPU_CLOCK_HZ must be the clock of the Timer.

So configCPU_CLOCK_HZ must be

configCPU_CLOCK_HZ = configCPU_CLOCK_HZ / VBP Divider

Please look to the datasheet

Bye
AmR Ahmed
EGYPT