HW-Assisted Delay
1. Poor Dr. J was caught making a blunder when discussing the range of
the delay method that utilizes the Core Timer. (Listing 4 in the
Project 2 document.) While it is true that the maximum value of the
argument to the function is 2^32 - 1, the actual implemenation of the
function imposes a lower limit.
(a) Using our PIC32 settings, what is the maximum
value of mS that can be used without the Core Timer "wrapping", i.e.,
incrementing past the starting point?
(b) What limit does the tWait variable impose?
(c) What is the correct answer for the maximum number of msec delay that can be used as an argument to the function?
2. As written, Listing 4 is considered a "blocking" function, i.e., it
won't return until the delay as expired. However, Dr. J would now like
you to create a "non-blocking" hardware-assisted delay using the Core
Timer and static variables as needed to implement the following
behavior:
(a) The first time the routine is called, it sets an
internal variable to to indicate that a delay is in progress, saves
other information as well, and returns a "1" to show a delay operation
is in progress.
(b) Subsequent calls to the delay routine will check
to determine if the delay has elapsed and if so, return "0". Otherwise,
it returns a "1".
A sample application is below
main()
{
non_block_delay(100); // Initial call
while(non_block_delay(100))
{
task1;
task2;
}// end while
} // end main
The above will cause task1 and task2 to be executed repeatedly for at least 100 msec.