LPC1769 SystickTimer

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1769 SystickTimer

2,369 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sostomariano on Fri May 09 20:11:34 MST 2014
Hi there , im trying to make a simple program using Systick Timer. I want to make the Led (P0.22 ) to turn ON/OFF each 5 seconds. That means , 5 seconds ON -> 5 seconds OFF -> 5 seconds ON->.....

Im not quite sure I'm understanding how the systick works. I made a void Systick_Init(void) function to initialize the systick.

void SystickInit(void)
{
STRELOAD = (STCALIB)-1;
STCURR = 0;
ENABLE = 1;
TICKINT = 1;
CLKSOURCE = 1;

}

The thing is, i put a certain value in STRELOAD, and the lpc is going to decrease 1 unit each 10 ms , so if i put for example the value 500 in STRELOAD , it would take 5 seconds to reach the value 0 , and when it does the bit COUNTFLAG turns 1 and call the Handler function, is it that way how it works ?
I made a .c file in which i put the function initializer and the Handler , which header files do i have to include ?

void Systick_Handler(void)
{
if( COUNTFLAG == 1 )
{
COUNTFLAG = 0; // clear interrupt
SetPin(0,22,~GetPin(0,22));
}
}
Labels (1)
0 Kudos
Reply
2 Replies

1,511 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sostomariano on Fri May 30 11:38:24 MST 2014
The examples provided by Cmsis2 ( LPCX176x_cmsis2_systick ) are quite poor , not to be rude sorry . but the file systick_main.c, has no initialization . i mean it must be a function called systick_init or something like that in which you configure the aproppiate registers..

This is the code

// CMSIS headers required for setting up SysTick Timer
#include "LPC17xx.h"

#include <cr_section_macros.h>
#include <NXP/crp.h>

// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

#include "leds.h"

volatile uint32_t msTicks; // counter for 1ms SysTicks

// ****************
//  SysTick_Handler - just increment SysTick counter
void SysTick_Handler(void) {
  msTicks++;
}

// ****************
// systick_delay - creates a delay of the appropriate number of Systicks (happens every 1 ms)
__INLINE static void systick_delay (uint32_t delayTicks) {
  uint32_t currentTicks;

  currentTicks = msTicks;// read current tick counter
  // Now loop until required number of ticks passes.
  while ((msTicks - currentTicks) < delayTicks);
}

// ****************
int main(void) {

led2_init();// Setup GPIO for LED2
led2_on();// Turn LED2 on

// Setup SysTick Timer to interrupt at 1 msec intervals
if (SysTick_Config(SystemCoreClock / 1000)) { 
    while (1);  // Capture error
}


// Enter an infinite loop, just incrementing a counter and toggling leds every second
volatile static int i = 0 ;
while(1) {
i++;
    systick_delay (2000); // wait 2 seconds (2000ms)
    led2_invert();// Toggle state of LED2
}
return 0 ;
}


Thanks

0 Kudos
Reply

1,511 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mc on Sun May 11 17:22:45 MST 2014
Hi Sostomariano,
Your approach is correct. You can just use peripheral_systick example available in our LPCOpen plateform. It toggles port with an LED.
If you are using Keil or IAR IDE, you can download lpcopen package from below link
http://www.lpcware.com/system/files/lpcopen_2_10_keil_iar_nxp_lpcxpresso_1769.zip

For Xpressso IDE download package from

http://www.lpcware.com/system/files/lpcopen_2_10_lpcxpresso_nxp_lpcxpresso_1769.zip

0 Kudos
Reply