View Single Post
  #11   Spotlight this post!  
Unread 03-12-2004, 00:16
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Is there a built in tick/millisecond counter?

Quote:
Originally Posted by eugenebrooks
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'd like to point out two things:

1) You're using the variable 'msClock' outside of the interrupt service routine without using the the techniques I described above. I did not do this in my example code. But because you did, the likelyhood of getting corrupted data is one thousand times greater when compared to how I used the 'Clock' variable.

2) The function Display_Time() in my example is only called every seventeen milliseconds, which means the variable 'Clock' is only being accessed around fifty-nine times a second. In addition to what you did above, you've also moved error checking code into the Process_Data_From_Local_IO() loop which executes, oh, one-hundred thousand times a second, which increases the likelyhood of creating an error by an additional factor of seventeen-hundred times.

Combined, these changes increase the likelyhood of creating a race condition by a factor of roughly a million. If you're seeing an error every, say, two seconds when you increased the likelyhood of generating one by over a million, is what you've done really meaningful?

I wrote that example in the clearest, most concise way I know how to. My goal is to "set the hook" and get folks interested in investigating other cool things their robot controller can do. Introducing the concept of task synchronization is unnecessary and counterproductive for such an example.


Quote:
Originally Posted by eugenebrooks
Volatile does not appear to be required, probably due to the size of the unsigned long compared to the size of PIC machine registers...
Yes it is. You're spending quite a bit of effort in trying to poke holes in my example code. If you don't know that the 'volatile' keyword is indeed necessary, we shouldn't be having this exchange.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org