Motorola once sc140 User Manual

Page of 28
Verifying Correct Setup
15
In EE_CTRL, the EE1DEF field is set to 00, which signifies output signal when detected by EDCA1. The 
remaining fields in EE_CTRL are irrelevant because they are not used.
Code 7 shows the setup code for EE control registers.
Code 7.   EOnCE_LED_init()
void EOnCE_LED_init()
{
*((long *)EE_CTRL) &= ~(3<<2); /* Toggle EE1 when event1 happens */
}
6.1.2  
Toggling EE1
The initialization previously discussed the set up of EE1 to toggle each time an event is detected by 
EDCA1. The same channel is also used to trigger the stopwatch timer to count. Therefore, all that remains 
is to create an EDCA1 event when the stopwatch timer stops. This is achieved by writing to the Enhanced 
OnCE stopwatch timer flag variable. 
Caution must be taken to perform this write only after execution of 
EOnCE_stopwatch_timer_stop()
.
Code 8.   Turn LED Off
void EOnCE_LED_off(){
    EOnCE_stopwatch_timer_flag = 0; /* Create an EDCA1 event */
}
6.2   
Testing the Stopwatch Timer
The program depicted in Code 9 on page -16 sets up the stopwatch timer and then measures the time it 
takes to execute two loops whose duration is built into the program.
The measured code sequences are constructed to take 10 seconds and 7.5 seconds, respectively. These 
durations are constructed by having the code sample the Enhanced OnCE counter and loop until the 
expected number of clock cycles have passed.
It is recommended to try this code prior to measuring the target application, as a means of verifying correct 
setup of the system. If the times measured are not correct, it is recommended to check the PLL setup and 
the values of the clock speed and the memory-mapped register base (as set in the header files).
If the SC140 compiler beta 1.0 V is used, COMPILER_BETA_1_BUG must be defined to make the code 
run correctly. In the macro WRITE_IO(REG,VAL) or READ_IO(REG,VAL), REG is deemed as 16-bit 
even though it is 32-bit in macro definition. It is fixed by explicitly declaring a long variable if 
COMPILER_BETA_1_BUG is defined.