Japanese
PROGRAMMER'S GUIDETimer library
■ | Go forward
timer library

1. guide


1.1 Purpose

This library mainly provides function-like macros to obtain programmable WAIT and processing times.

1.2 Overview

The timer uses the free running timer (FRT) in the CPU and the timer interrupt in the SCU. We have prepared function-like macros considering the following uses for each device.

●SCU

●CPU

1.3 Detailed explanation

●SCU
< how to use>
For details on how to use it, see timer interrupt in the SCU user's manual.

< calling sequence>
The following is a calling sequence that uses timer 1 to generate a timer 1 interrupt when drawing the 10th bit of each line, and inverts that line if it is an odd numbered line.

Uint32 time_flg; /* Interrupt flag */
...
void vblankOut() /* V-BLANK OUT execution function */
{
     Uint32 intr_count = 0; /* Interrupt counter */
     ...
     TIM_T1_DISABLE(); /* Disable timer 1 interrupt */
     TIM_T1_SET_MODE(TIM_MD_LINE); /* Specify interrupt generation every line */
     TIM_T1_SET_DATA(10);                 
                  /* Specify the interrupt generation timing at the 10th bit of the line */
     time_flg = OFF; /* Turn off interrupt flag */
     TIM_T1_ENABLE(); /* Timer 1 interrupt enable */
     ...
     for(intr_count< ALL_LINE_NUM){
                                           /* Until all line interrupts are executed */
               changeLine(intr_count); /* Invert odd line */
               intr_count ++; /* Line count */
     }
}
void timeIntr() /* Interrupt execution function */
{
     time_flg = ON; /* Turn on interrupt flag */
}

●CPU
< Basics>
counter value
A counter value is used to specify time to FRT. This counter value is explained below.

The count-up period of the counter value changes depending on the division specification and graphic mode specification. The count-up period can be calculated using the following calculation.

Count-up period (s) = Divide x 1/Clock frequency (Hz)

It is convenient to use the following function-like macros to convert count values to microseconds and microseconds to count values.

 function
 function-like macro
 number
 Counter value -> microsecond conversion
 TIM_FRT_CNT_TO_MCR
 15
 microsecond -> Counter value conversion
 TIM_FRT_MCR_TO_CNT
 16

< how to use>
Initialization
Execute the following function-like macro before obtaining the elapsed time and using the wait time (WAIT) function.

 function
 function-like macro
 number
 FRT initialization
 TIM_FRT_INIT
 8

How to obtain elapsed time
The following functions are provided to obtain the elapsed time.

 function
 function-like macro
 number
 Counter value setting (16 bits)
 TIM_FRT_SET_16
 9
 Obtain counter value (16 bit)
 TIM_FRT_GET_16
 10

void sysInit()
{
     TIM_FRT_INIT(8); /* Set divider to 8 */
     ...
}

 void writeFrameBuff()
{
     Uint16 count; /* Obtained count value storage area */
     float micro_sec; /* Microsecond storage area */
     TIM_FRT_SET_16(0); /* Set the count value to 0 */
     WriteAllVram(); /* Execute the process you want to measure */
     count = TIM_Frt_Get_16(); /* Get the count value */
                                           /* count indicates the execution time of WriteAllVram() */
     micro_sec = TIM_FRT_CNT_TO_MCR(count);/* Convert counter value to microseconds */
     printDisplay(micro_sec); /* Display the elapsed time on the screen */
}


■ | Go forward
PROGRAMMER'S GUIDETimer library
Copyright SEGA ENTERPRISES, LTD., 1997