pls take a look at this SysTick Function

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

pls take a look at this SysTick Function

673 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by black_ghost on Thu Oct 13 14:17:54 MST 2011
Hello i am trying to use the systick as a delay function for my lcd but i have trouble understanding why and how she define the core clock to 6mhz. I want to use the clock and run it as 100mhz core clock. i found an example code but have trouble understanding it. below is the code. i want to define the core clock to run as 100mhz and not 6mhz. 


#define NVIC_ST_CTRL_R          (*((volatile unsigned long *)0xE000E010))
#define NVIC_ST_RELOAD_R        (*((volatile unsigned long *)0xE000E014))
#define NVIC_ST_CURRENT_R       (*((volatile unsigned long *)0xE000E018))
#define NVIC_ST_CTRL_COUNT      0x00010000  // Count flag
#define NVIC_ST_CTRL_CLK_SRC    0x00000004  // Clock Source
#define NVIC_ST_CTRL_INTEN      0x00000002  // Interrupt enable
#define NVIC_ST_CTRL_ENABLE     0x00000001  // Counter mode
#define NVIC_ST_RELOAD_M        0x00FFFFFF  // Counter load value

// Initialize SysTick with busy wait running at bus clock.
void SysTick_Init(void){
  NVIC_ST_CTRL_R = 0;                   // disable SysTick during setup
  NVIC_ST_RELOAD_R = NVIC_ST_RELOAD_M;  // maximum reload value
  NVIC_ST_CURRENT_R = 0;                // any write to current clears it
                                        // enable SysTick with core clock
  NVIC_ST_CTRL_R = NVIC_ST_CTRL_ENABLE+NVIC_ST_CTRL_CLK_SRC;
}
// Time delay using busy wait.
// The delay parameter is in units of the 6 MHz core clock. (167 nsec)
void SysTick_Wait(unsigned long delay){
  volatile unsigned long elapsedTime;
  unsigned long startTime = NVIC_ST_CURRENT_R;
  do{
    elapsedTime = (startTime-NVIC_ST_CURRENT_R)&0x00FFFFFF;
  }
  while(elapsedTime <= delay);
}

void SysTick_Wait10ms(unsigned long delay){
  unsigned long i;
  for(i=0; i<delay; i++){
    SysTick_Wait(60000);  // wait 10ms (assumes 6 MHz clock)
  }
}
0 Kudos
2 Replies

457 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by black_ghost on Sat Oct 15 17:10:19 MST 2011

Quote: StephenHawkings
If your SysTick counts every 10ms, then with 6MHz it counts to 0.01s / 0.167us = 60.000. If you want to count every 10ms for 100MHz, it needs to count to 0.01s / 0.01us = 1.000.000.

void SysTick_Wait10ms(unsigned long delay){
unsigned long i;
for(i=0; i<delay; i++){
SysTick_Wait(60000); // wait 10ms (assumes 6 MHz clock)
}

would be
SysTick_Wait(1000000); // wait 10ms (assumes 100 MHz clock)

But I think you should check for the interrupts; I can't see any ISR for SysTick. But INT is enabled.

Please check, SysTick counting speed is in collaboration with CPU clock and prescaler.
SH


Ok but how i will go about using the interrupts could you please show me the right direction or a good explanation and i could go from there. thanks
0 Kudos

457 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by StephenHawkings on Fri Oct 14 01:19:03 MST 2011
If your SysTick counts every 10ms, then with 6MHz it counts to 0.01s / 0.167us = 60.000. If you want to count every 10ms for 100MHz, it needs to count to 0.01s / 0.01us = 1.000.000.

void SysTick_Wait10ms(unsigned long delay){
unsigned long i;
for(i=0; i<delay; i++){
SysTick_Wait(60000); // wait 10ms (assumes 6 MHz clock)
}

would be
SysTick_Wait(1000000); // wait 10ms (assumes 100 MHz clock)

But I think you should check for the interrupts; I can't see any ISR for SysTick. But INT is enabled.

Please check, SysTick counting speed is in collaboration with CPU clock and prescaler.
SH
0 Kudos