beautypg.com

Wavetronix Click 500 (programmable controller) (CLK-500) - Developer Guide User Manual

Page 59

background image

58

CHAPTER 6 • TIMERS AND CLOCKS

Note

If the wrong operating mode or task was selected, simply hold the push-button to
restart the operating mode and task selection process. Once the correct mode or task
is selected, press the push-button.

The interrupt timer is available for writing custom programs. To write code that executes

each time the interrupt fires, you need to register a callback function to get processed as a

timer Interrupt Service Routine (ISR). Only one ISR can be attached to the timer interrupt

at a time. Registration is done in a setup function using the ClickTimerRegisterCalllback

function. The following code block shows an example where an ISR named ProgressTimer-

ISR is registered.

void Setup( void )
{
ClickTimerRegisterCallback(ProgressTimerISR);
PlayPauseState = PROGRESS_STATE_PLAY;
Startup = TRUE;
WaitTimer.active = FALSE;
}

The Click 500 executes almost 60 million instructions per second, which means that over

600 thousand instructions can execute every 90th of a second. However, you want to be

sure that your interrupt service routine code only does what it needs to in order to prevent

starving the main idle loop. While the ISR is executing, the main idle loop is blocked in a

suspended state.

One way to limit the amount of code in an ISR is to pass state information from a critical

code path in the ISR to a non-critical segment of the idle loop. The following example ISR

code uses the global variables ProgressState and ProgressStateRead to pass state informa-

tion from the ISR to the idle loop.

In the example below, the ISR code is used to time the activation of a progress indication bar

and the associated idle loop is then used to display the progress indication on the yellow bank

void ProgressTimerISR(void)
{
static char ProgressCounter;

#GLOBAL_INIT
{