Fujitsu MB90480 Series Hardware Manual page 277

F2mc-16lx 16-bit microcontroller
Table of Contents

Advertisement

Program example of input capture
Example of setting procedure
Rising edge of the pulse input to IN0 is detected, and
the value of the free-running timer is recorded. Repeat
this twice and measure the time between triggers.
However reading of capture value and calculation
processing is interrupt processing.
<Initial setting>
Control free-running timer
Set control register
Clock selection>>
Interrupt request flag>>
Interrupt request enable>>
Count operation>>
Initialization condition of timer>>
TCDT clear>>
Count clock>>
Set timer data value
Port
Set IN0 input of port
Control input capture
Set control register
Interrupt request flag>>
Interrupt request enable>>
Select ch.1 valid edge polarity>>
Select ch.0 valid edge polarity>>
Interrupt related
Set interrupt level
Set I flag
Set variable
<Start>
Start input capture ch.0
Interrupt control
Start Free-running timer
Start count operation
<Interrupt>
Interrupt processing
Clear interrupt request flag
(Arbitrary processing)
••••••••••
<Interrupt vector>
Set vector table
Note:
Setting related to clock and setting of _set_il (numeric
value) are required in advance. See the chapter of
clock and interrupt.
Program example
void INPUT0_sample(void)
{
freerun_initial();
INPUT0_initial();
INPUT0_start();
freerun_start();
}
void freerun_initial(void)
{
IO_TCCS.word = 0x20; /* Setting value=0000_0000_0010_0000 */
TCCS
.ECKE
.IVF
.IVFE
.STOP
.MODE
.SCLR
.CLK2-0
IO_TCDT = 0x0000;
TCDT
}
void INPUT0_initial(void)
{
IO_DDR9.byte = 0x00; /* DDR9 IN0(P96) input */
Register name. bit name
DDR9 .P96
IO_ICS01.byte = 0x01; /* Setting value=0000_0001 */
ICS01
.ICP1,ICP0
.ICE1,ICE0
.EG11,EG10
.EG01,EG00
IO_ICR07.byte = 0x10; /* Set input capture ch.0 interrupt level
ICR07
__EI();
(CCR)
count = 0;
}
void INPUT0_start(void)
{
Register name. bit name
IO_ICS01.bit.ICE0 = 1;
ICS01 .ICE0
}
void freerun_start(void)
{
Register name. bit name
IO_TCCS.bit.STOP = 0; /* bit5 = 0
TCCS .STOP
}
__interrupt void INPUT0_int(void)
{
Register name. bit name
IO_ICS01.bit.ICP0 = 0;
ICS01 .ICP0
if(count==0)
Data1 = IO_IPCP0;
else if(count==1) {
Data2 = IO_IPCP0;
cycle = (data2-data1)*125; /* Measure time */
}
count++;
}
#pragma intvect INPUT0_int 26
Note:
For the description form of the register, see "SAMPLE I/O REGISTER FILES FOR
2
F
MC-16LX FAMILY MB90480 SERIES".
CHAPTER 12 16-BIT INPUT/OUTPUT TIMER
/* bit15 = 0 ECKE internal clock source */
/* bit7 = 0
IVF interrupt request flag */
/* bit6 = 0
IVFE disable interrupt */
/* bit5 = 1
Disable STOP count */
/* bit4 = 0
Initialize by MODE reset, clear bit */
/* bit3 = 0
Initialize SCLR free-running timer value */
/* bit2-0 = 000 CLK2-0 count clock φ*/
/* Initialize timer data value */
/* bit7-6 = 00 Clear ICP1, 0 valid edge flag */
/* bit5-4 = 00 Disable ICE1, 0 interrupt */
/* bit3-2 = 00 No EG11, EG10 ch.1 edge detection */
/* bit1-0 = 01 EG01, EG00 ch.0 rising edge detection */
(arbitrary value) */
/* Enable interrupt */
/* bit4 = 1
Enable ICE0 ch.0 interrupt */
Enable STOP count */
/* bit6 = 0
Clear ICP0 valid edge detection flag */
/* Record value of free-running timer (first time) */
/* Record value of free-running timer (second time) */
255

Advertisement

Table of Contents
loading

Table of Contents