Jump to content

Timers using CC65


rje
 Share

Recommended Posts

I've started learning how time is measured on the X16.

In particular, I've been playing with clock_gettime() from <time.h>.  It includes a timespec structure that looks like this:

/* Structure for seconds and nanoseconds */
struct timespec {
     time_t tv_sec;  // <-- that's an unsigned long
     long tv_nsec;
};

I've been fetching the time like this:

struct timespec tp;
clock_gettime(CLOCK_REALTIME, &tp);

And, if I read the results correctly, the response is probably measuring to milliseconds.  I think this, because when I print tv_nsec, there's three digits of precision followed by six zeros.

I also tried shifting tv_nsec right by 10 bits, which results in what APPEARS to be six digits of precision -- but that would imply that the clock can measure microseconds.  And, upon reflection, I doubt it.  I think shifting bits results in a false reading because it's dividing by a non-decimal value.  So, I think the call is measuring to milliseconds.

Assume it's not accurate to THE millisecond, either.  I haven't checked that yet.

 

Edited by rje
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use