AnsweredAssumed Answered

using clock() function time.h

Question asked by Vrushali Taklikar on Mar 25, 2018
Latest reply on Mar 26, 2018 by Martin Kovar

Hi,

 

I am trying to use time.h file clock() function.

 

Here is my code. I am getting -1 as return value for clock() fucntion. 

What is going wrong here, can someone explain

 

#include "derivative.h" /* include peripheral declarations */
#include <time.h>
#include "MPC577xC.h"
void delay(int milliseconds);
extern void xcptn_xmpl(void);

void delay(int milliseconds)
{
clock_t ticks1 = clock(), ticks2 = ticks1;
clock_t target = milliseconds * CLOCKS_PER_SEC;
while ( ( ticks2 - ticks1) < target)
ticks2 = clock();
}

int main(void)
{
volatile int counter = 0;
int x;

   xcptn_xmpl (); /* Configure and Enable Interrupts */

   SIU.PCR[114].R= 0x0200;
   SIU.GPDO[114].B.PDOn = 0x0;
   for(x=0;x<10;x++)
   {
      SIU.GPDO[114].R = 1;
      delay(250);
      SIU.GPDO[114].R = 0;
   }

}

Outcomes