AN2090 Freescale Semiconductor / Motorola, AN2090 Datasheet - Page 6

no-image

AN2090

Manufacturer Part Number
AN2090
Description
Using the SC140/SC1400 Enhanced On-Chip Emulator Stopwatch Timer
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Setting Up the Stopwatch Timer In an Application
2.3 Stopping the Stopwatch Timer
The C code to stop the stopwatch timer is shown in Example 3.
#include “EOnCE_registers.h”
void EOnCE_stopwatch_timer_stop(unsigned long *clock_ext, unsigned long *clock_val)
{
}
To stop the stopwatch timer, the ECNT_CTRL register is cleared to zero. After the stopwatch timer stops, the
routine copies the values of the ECNT_VAL and ECNT_EXT registers into program variables. Therefore, the
stopwatch timer can be used again without losing the result of the previous measurement.
Because ECNT_VAL contains the result of a countdown process, the routine converts that result into the actual
number of cycles elapsed by subtracting the ECNT_VAL from the value to which it was initialized, specifically,
4294967295.
2.4 Converting Cycles to Actual Time
The stopwatch timer measures durations in units of core clock cycles. Most often the units of interest are units of
absolute time, such as milliseconds or microseconds. Conversion from core clock cycles, as measured by the event
counter registers, to milliseconds is computed in Equation 1.
EXT is the value in ECNT_EXT, VAL is the value in ECNT_VAL, and Clock Speed is measured in MHz.
Example 4 shows the C code for clock-cycle-to-time conversion. The C code depends on setting the value of the
constant CLOCK_SPEED in EOnCE_stopwatch.c to match the clock speed as set in the PLL. The conversion
routine distinguishes between three different output units: seconds, milliseconds, and microseconds. Handling each
unit separately allows the computations to be performed using integer arithmetic without loss of accuracy.
6
WRITE_IOREG(ECNT_CTRL,0);
READ_IOREG(ECNT_VAL,*clock_val); /* Save ECNT_VAL in program variable */
READ_IOREG(ECNT_EXT,*clock_ext); /* Save ECNT_EXT in program variable */
*clock_val = (MAX_32_BIT-*clock_val); /* Adjust for countdown */
Using the SC140/SC1400 Enhanced On-Chip Emulator Stopwatch Timer, Rev. 1
Time ms
(
)
Example 3. C Code to Stop the Stopwatch Timer
=
(
EXT
×
0xffffffff
+
/* Disable event counter */
VAL
)
×
------------------------------ -
ClockSpeed
1000
Freescale Semiconductor
Equation 1

Related parts for AN2090