Fujitsu FR81S Benutzerhandbuch
CHAPTER 21: 32-BIT FREE-RUN TIMER
8. Sample Program
FUJITSU SEMICONDUCTOR LIMITED
CHAPTER
: 32-BIT FREE-RUN TIMER
FUJITSU SEMICONDUCTOR CONFIDENTIAL
42
8. Sample Program
This section explains sample program of the free-run timer.
Setting procedure example 1
Free-run timer 3, Clock=PCLK/2^6,
Count the number of compare matches using interrupt
processing.
<
Initial setting>
-Free-run timer ch.3 control Register name.Bit name
Control register setting
Clock selection>>
Compare interrupt request flag>>
Compare interrupt request
enabled>>
Counting Operation>>
TCDT clear>>
Count clock>>
TCCSH3/TCCSL3
.ECKE
.ICLR
.ICRE
.STOP
.CLR
.CLK3-0
Timer data value setting
TCDT3
-Interrupt-related Register name.Bit name
Sets an interrupt level.
ICR34
I flag setting
(CCR)
-Variable setting
<Activation>
-Free-run timer ch.3 activation Register name.Bit name
Count operation activation
TCCS3 .STOP
<Interrupt >
-Interrupt processing Register name.Bit name
Clearing of interrupt request flag
TCCS3.ICLR
(Any process)
Variable counting
<Interrupt vector>
Vector table setting
Note:
Clock-related settings and the setting of __set_il (numeric
value) need to be configured in advance. See “CHAPTER:
CLOCK” and “CHAPTER: INTERRUPT CONTROL
(INTERRUPT CONTROLLER)”
Program example 1
void FREE_RUN_TIMER3_sample(void)
{
FREERUN3_initial();
FREERUN3_start();
}
void FREERUN3_initial(void)
{
IO_TCCS3.word = 0x0041; /* Setting value=0000_0000_0100_0001 */
/* bit15 = 0 ECKE internal clock source */
/* bit14 -10= 00000 Reserved bit */
/* bit9 = 0 ICLR compare interrupt request flag */
/* bit8 = 0 ICRE compare interrupt disabled */
/* bit7 = 0 Reserved bit */
/* bit6 = 1 STOP count disabled */
/* bit5 = 0 Reserved bit */
/* bit4 = 0 SCLR Initialization of SCLR free-run timer value
(no) */
/* bit3-0 = 0001 CLK3-0 Count clock PCLK/2=32MHz/2 */
IO_TCDT3 = 0x0000;
/* Initialization of timer data value */
IO_ICR[34].byte = 0x10; /* Free-run timer 3 interrupt level setting (any value) */
__EI();
/* Interrupt enabled */
count = 0;
}
void FREERUN3_start(void)
{
IO_TCCS3.bit.STOP = 0; /* bit6 = 0 STOP count enabled */
}
__interrupt void
FREE_RUN_TIMER3_int(void)
{
IO_TCCS3.bit.ICLR = 0;
/* bit9 = 0 Clearing of ICLR compare match flag */
count++;
}
Specification of interrupt routine required in vector table
#pragma intvect FREE_RUN_TIMER3_int 50
MB91520 Series
MN705-00010-1v0-E
837