0

I am working on a board which comprises LPC1768 microcontroller. All I want to do is to create an accurate time delay using osdelay function of CMSIS RTOS API. I have set my systick time tick count to 10000.But when I use osdelay(1000) in my thread, it doesn't creates delay period of 1 second as it should do !

Here is the source code

#include"cmsis_os.h"  
#include"lpc17xx.h"
void Thread1 (void const *argument) {

while (1) {

LPC_GPIO2->FIOPIN = 0x00000001;                                              

osDelay(1000);                                          

LPC_GPIO2->FIOPIN = 0x00000000; 

osDelay(1000);

}

}

osThreadId main_ID,led_ID1,led_ID2; 

osThreadDef(Thread1,osPriorityNormal, 1, 0);

int main (void)
{

SystemInit();

LPC_PINCON->PINSEL4 = 0x00000000;  

LPC_GPIO2->FIODIR = 0xffffffff;

osKernelInitialize ();  

led_ID1 = osThreadCreate(osThread(Thread1), NULL);

osKernelStart ();  

}

Now, my problem is with osdelay(1000) not providing a delay of 1000ms as it should do with systick timer tick value set to 1000.

artless noise
  • 21,212
  • 6
  • 68
  • 105
Rahul Gusai
  • 701
  • 1
  • 6
  • 11
  • Can you post a snapshot of the source? And sample outputs or errors that you may be getting? – anacron Aug 23 '16 at 18:24
  • I have added the source code. – Rahul Gusai Aug 24 '16 at 15:25
  • What do you end up getting as a delay? Generally an OS timer delay isn't going to create accurate delays, because you may be blocked from running for a longer time by a high priority task, and the OS tick is asynchronous to when you request the delay, so there's about one tick of wiggle room in how long the delay (assuming not blocked) is, plus context switch time. – rjp Aug 24 '16 at 17:07
  • 1
    Actually, the problem was with the input clock frequency of the sysctick timer. It was set to 12mhz while CPU is operating at 96mhz. After setting the input frequency to 96mhz, it was able to create an accurate delay of 1s. – Rahul Gusai Aug 24 '16 at 17:20

0 Answers0