18 SERVO 01.2012
control. A volatile variable’s memory location will be read
every time the variable is referenced; the compiler will know
that the code needs to do this because the last time the
variable was referenced it may not of held its current value.
Always do this for variables that change due to an interrupt.
The static definition tick10 tells the compiler that the value
must be retained even after the function is done and
returns. Static definitions act just like module global values,
but they are local to the function in which they are defined.
These static and volatile variables are an ansi C standard,
gcc is the only ansi C compliant compiler I’ve talked about
in this column. That is why you saw it first with this program.
It may take you a little longer to understand the nuances
of the gcc compiler with all its attributes and other arcane
looking constructs, but its consistency and completeness
will make you a happy programmer in the end. If anyone is
interested in the PIC24F’s output compare or PWM
capabilities, I’ll do that in another column because the
PIC24F allows you to map most of its hardware functions to
whatever pins you want them to come out on; the OCP
(PWM) functions require that mapping. This can get confusing
and really is a topic for an entire column. So, if you are
interested, drop me an email and I’ll consider it for the future.
Well, I’ve gone and used up a bunch of your time
reading Mr. Roboto again! I hope that you’ve gotten what
you came for. As usual, I enjoyed providing it. So, it’s a new
year and I’ll say it again, “Keep sending me those questions
and I’ll do my best to answer them!” I can be reached at
email@example.com. Enjoy your robots! SV