Program Example Of 8/10-Bit A/D Converter - Fujitsu MB90480 Series Hardware Manual

F2mc-16lx 16-bit microcontroller
Table of Contents

Advertisement

17.8

Program Example of 8/10-Bit A/D Converter

This section describes the program example of the 8/10-bit A/D converter.
■ Program example of 8/10-bit A/D converter
Example of setting procedure
An example that A/D-converts the level input by AN0 (single
conversion, software trigger) is shown below.
<Initial setting>
Enable AN0 input
Set port input
Enable A/D input of AN0
A/D0 conversion time
Set conversion time
Set sampling time>>
Set compare time>>
Control A/D0
Control status register 1
Select operation mode>>
Set start channel>>
Set end channel>>
Control status register 2
Clear interrupt request flag>>
Disable interrupt>>
Select start trigger>>
Interrupt related
Set A/D interrupt level
Set I flag
<Start A/D>
Start AN0
Enable A/D0 interrupt
Start A/D0 software
Program example
void AD_sample()
{
AD0_INITIAL();
AD0_ch0_start();
}
void AD0_INITIAL(void)
{
Register name. bit name
IO_DDR6.bit.D60 = 0;
DDR6. P60
IO_ADER.bit.ADE0 = 1; /* AN0 only, A/D input */
ADER.ADE0
IO_ADCR2.byte = 0x70; /* Value is recommended value */
ADCR2
.ST1-0
.CT1-0
Register name. bit name
ADCS1
IO_ADCS1.byte= 0x00; /* Setting value : 00000000 (bit) */
.MD1-0
.ANS2-0
.ANE2-0
ADCS2
IO_ADCS2.byte= 0x00; /*Setting value : 00000000 (bit) */
.BUSY
.INT
.INTE
.PAUS
.STS1-0
.STRT
.Reserved bit
ICR14
IO_ICR14.byte= 0x00;
(CCR)
__EI();
}
void AD0_ch0_start(void)
{
Register name. bit name
IO_ADCS2.byte= 0x20;
ADCS2
.INT
.INTE
IO_ADCS2.byte= 0xA2;
ADCS2
.STRT
}
CHAPTER 17 8/10-BIT A/D CONVERTER
/* DDR6 AN0(P60) input */
/* 11 */
/* 10 */
/* Bit7-6=00: single mode */
/* Bit5-3=000: AN0 */
/* Bit2-0=000: AN0 */
/* Bit15=0: (no effect) */
/* Bit14=0: Clear interrupt request */
/* Bit13=0: Disable interrupt */
/* Bit12=0: */
/* Bit11-10=00: Software trigger */
/* Bit9=0: */
/* Bit8=0: "0" Write */
/* arbitrary value */
/* Enable interrupt */
/* Bit14=0: Clear AD0 interrupt flag */
/* Bit13=1: Enable AD0 interrupt */
/* Bit9=1: Start software */
(Continued)
379

Advertisement

Table of Contents
loading

Table of Contents