lpcware

systick setup in lpcopen

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by qrptech on Wed Jan 06 04:18:39 MST 2016
Hi,

I did a very quick and short search for something on this topic,
did not find a thing relevant enough. But here goes :

While writing a program for a project a came across this "strange"
behaviour with the final tick rate of the systick timer. When I set
it to 10 Hz, using the periph_blinky example, with

// Ticks per second
#define TickRate_Hz 10

it results in a 10 Hz tick rate. But when set to 1 or 2 it will output a
steady state (the LED is constant on).

After some searching I found that the clksource bit in the systick
timer control register is set, then Chip_Clock_SetSysTickClockDiv()
cannot be set to 1. It must be at least 2,5 according to the user
manual page 324. So I changed some stuff :

// The sysTick counter only has 24 bits of precision, so it will
// overflow quickly with a fast core clock. You can alter the
// sysTick divider to generate slower sysTick clock rates
Chip_Clock_SetSysTickClockDiv(200);

and in core_cm3.h :

/*******************************************************************************
* \brief  System Tick Configuration
*
* The function initializes the System Timer and its interrupt, and starts
* the System Tick Timer.
* Counter is in free running mode to generate periodic interrupts.
*
* \param [in]  ticks  Number of ticks between two interrupts.
*
* \return          0  Function succeeded.
* \return          1  Function failed.
*
* \note When the variable __Vendor_SysTickConfig is set to 1, then
*       the function SysTick_Config is not included. In this case,
*       the file <i>device</i>.h
* must contain a vendor-specific implementation of this function.
******************************************************************************/
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if((ticks - 1) > SysTick_LOAD_RELOAD_Msk)
{
// Reload value impossible
return (1);
}
// Set reload register
SysTick->LOAD  = ticks - 1;
// Set Priority for Systick Interrupt
NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1);
// Load the SysTick Counter Value
SysTick->VAL = 0;
// Enable SysTick IRQ and SysTick Timer
SysTick->CTRL = SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;
// Function successful
return (0);
}

Now it is working as, I think, intended :-)

Oh, I tried it with 3 values in Chip_Clock_SetSysTickClockDiv(), being 5, 200 and 255.

roelof

Outcomes