View Single Post
  #10   Spotlight this post!  
Unread 02-12-2004, 21:53
eugenebrooks eugenebrooks is offline
Team Role: Engineer
AKA: Dr. Brooks
no team (WRRF)
 
Join Date: Jan 2004
Rookie Year: 2001
Location: Livermore, CA
Posts: 601
eugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond repute
Re: Is there a built in tick/millisecond counter?

Quote:
Originally Posted by Kevin Watson

It's a very hard thing to quantify. As an example, if the variable in question is a char, you'll never get corrupted data because all byte accesses on the 18F8520 are atomic in nature.

-Kevin
The variable in question is an unsigned long, msClock. Here is an example that shows the bogus msClock values you can get. You get one every few seconds. I stand corrected on volatile, the C18 user manual reccomends it, and mcClock was declared as such in clock.h.

#include "printf_lib.h"
void Process_Data_From_Local_IO(void) {
/* oldmsClock must be saved between calls.
*/
static unsigned long oldmsClock = 0;
unsigned long newmsClock;
newmsClock = msClock;
/* If we have a little byte trip from
the devil that we weren't expecting...
*/
if(newmsClock < oldmsClock) {
printf("Hit: old = %lx, new = %lx\n",
oldmsClock, newmsClock);
}
oldmsClock = newmsClock;
}


Hit output will be of the form:
Hit: old = 0dff new = 0d00
Hit: old = 020ff new = 02000
Hit: old = 02eff new = 02e00
Hit: old = 040ff new = 04000
That the interrupt is splitting the read of the low order byte,
and the next one up, is clear.

Last edited by eugenebrooks : 02-12-2004 at 22:35.