Motorola ONCE SC140 Application Note page 20

Enhanced once stopwatch timer
Table of Contents

Advertisement

#include <stdio.h>
#include "EOnCE_stopwatch.h"
#ifdef COMPILER_BETA_1_BUG
extern long ECNT_VAL;
#else
#include "EOnCE_registers.h"
#endif
void PLL_setup_300MHz()
{
asm("move.l #$80030003,PCTL0");
asm("move.l #$00010000,PCTL1");
}
void main(){
unsigned long clock_ext,clock_val,clock_cycle,cycle_req;
unsigned long time_sec;
extern unsigned long CLOCK_SPEED;
PLL_setup_300MHz();
EOnCE_stopwatch_timer_init();
EOnCE_LED_init();
cycle_req = CLOCK_SPEED*10;
EOnCE_stopwatch_timer_start();
do {
READ_IOREG(ECNT_VAL,clock_cycle);
clock_cycle = MAX_32_BIT - clock_cycle;/* Minus max value due to count down */
} while (clock_cycle <= cycle_req);
EOnCE_stopwatch_timer_stop(&clock_ext, &clock_val);
EOnCE_LED_off();
time_sec = Convert_clock2time(clock_ext, clock_val, EONCE_SECOND);
printf("duration = %u sec\n", time_sec);
cycle_req = CLOCK_SPEED*7.5;
EOnCE_stopwatch_timer_start();
do {
READ_IOREG(ECNT_VAL,clock_cycle);
clock_cycle = MAX_32_BIT - clock_cycle;/* Minus max value due to count down */
} while (clock_cycle <= cycle_req);
EOnCE_stopwatch_timer_stop(&clock_ext, &clock_val);
EOnCE_LED_off();
time_sec = Convert_clock2time(clock_ext, clock_val, EONCE_MILLISECOND);
printf("duration = %u ms\n", time_sec);
return;
}
16
Code 9. Testing Code
Using the SC140 Enhanced OnCE Stopwatch Timer
/* Setup to event detector 1 for any write to
dummy variable. Setup EOnCE event counter
to count if event 1 happens */
/* Setup LED to toggle in detection of
event 1 */
/* Calculate total clock cycles required
by 10 sec */
/* Event 1 happens, counter & LED on */
/* Read bit 31-0 counter value */
/* Stop timer, return bit 63-0
counter value */
/* LED off */
/* Calculate total clock cycles required
by 7.5 sec */
/* Event 1 happens, counter & LED on */
/* Read bit 31-0 counter value */
/* Stop timer, return bit 63-0
counter value */
/* LED off */

Advertisement

Table of Contents
loading

Table of Contents