4 Replies Latest reply on Jul 28, 2015 10:49 AM by allene

    clock() not working as expected.  What's up?

    allene

      I am trying to get a timestamp (see other thread) and tried the function clock() that should read the system clock.  I am printing out the value of clock once a second timed by a GPS input.  I can see a steady display of the gps data from a printf statement but the associated clock() values are not sonstant.  Every 5th one has about 50% more digits between the numbers. I call this once a second and the printf output comes out once a second but the number x3 is not at all constant.

       

      int time_stamp(){

           unsigned long xyzzy;

           static unsigned long x2 = 0;

           xyzzy = (unsigned long)( clock());

           unsigned long x3 = xyzzy - x2;

           printf("** timestamp is %lu %lu %lu\n", xyzzy, x2, x3);

           x2 = xyzzy;

      return (int)xyzzy;

      }

       

       

      So, can I fix this or is there another way to get a sub second clock?