input in the PBC port control register to enable the A/D input, when the PCR2~PCR0 bits enable
an A/D input, the status of the port control register will be overridden. The VDD power supply pin is
used as the A/D converter reference voltage, and as such analog inputs must not be allowed to ex
-
ceed this value. Appropriate measures should also be taken to ensure that the VDD pin remains
as stable and noise free as possible.
Summary of A/D Conversion Steps
The following summarizes the individual steps that should be executed in order to implement an
A/D conversion process.
·
Step 1
Select which pins on Port B are to be used as A/D inputs and configure them as A/D input pins
by correctly programming the PCR2~PCR0 bits in the ADCR register.
·
Step 2
Select which channel is to be connected to the internal A/D converter by correctly programming
the ACS2~ACS0 bits which are also contained in the ADCR register.
·
Step 3
Select the required A/D conversion clock by correctly programming bits ADCS1 and ADCS0 in
the ACSR register.
·
Step 4
If the interrupts are to be used, the interrupt control registers must be correctly configured to en
-
sure the A/D converter interrupt function is active. Depending upon which device is used, the
master interrupt control bit, EMI, in either the INTC or INTC0 interrupt control register must be
set to ²1² and the A/D converter interrupt bit, EADI, in either the INTC, INTC0 or INTC1 register
must also be set to ²1².
· Step 5
The analog to digital conversion process can now be initialized by setting the START bit in the
ADCR register to from ²0² to ²1² and then to ²0² again. Note that this bit should have been origi-
nally set to ²0².
· Step 6
To check when the analog to digital conversion process is complete, the EOCB bit in the ADCR
register can be polled. The conversion process is complete when this bit goes low. When this
occurs the A/D data registers ADRL and ADRH can be read to obtain the conversion value. As
an alternative method if the interrupts are enabled and the stack is not full, the program can wait
for an A/D interrupt to occur.
Note
When checking for the end of the conversion process, if the method of polling the EOCB bit in the
ADCR register is used, step 4 above can be omitted.
A/D Type MCU
50