Anda di halaman 1dari 2

EXPERIMENT NO 05

AIM:- Write a program for interfacing Analog Input (ADC) with LPC2148
How to received and interpret analog data (i.e., 'interacting with the Real world')
Almost every dial or knob on any modern electronic device, for example, is probably analog.
Since our microcontrollers are digital, what that means is that we need to find a way to convert
those analog signals into something 'digital' that our microcontroller can actually understand.
LPC2148 has two of them built in. They work by converting voltage to a numeric value that the
microcontroller can understand. For example, with an internal voltage of 3.3V (which is the
Vref on the LPC2148) and your ADC set to return the maximum 10-bit data (meaning you have
possible values between 0 and 1023), 0.0V would return 0, 3.3V (or higher) would return 1023,
and 1.65V would return ~512.

Step 1: Configuring the ADC (ADCR)


In this particular case, we're using AD0.3, which means we are using A/D Converter 0 (the
LPC2148 has two ADCs named AD0 and AD1), and channel 3 (out of a possible 8 channels).
1. Select the pin function (PINSEL)
In the case of AD0.3 (located on pin 15 of the lpc2148), the pin can be configure to perform any
of the following functions:
1.
2.
3.
4.

P0.30 - General Purpose Input/Output 0.30


AD0.3 - Analog/Digital Converter 0, Input 3
EINT3 - External Interrupt 3
CAP0.0- Capture input for Timer 0, Channel 0

2. Make sure ADC0 is powered-on (PCONP)


It's always good practice to make sure that a peripheral is powered on (using
the PCONP register) before trying to use it.
3. Configure ADC0 (ADCR)
To configure the A/D Converter, we need to pass a specific 32-bit value to the
appropriate ADCR, or "Analog/Digital Control Register" This 'control register' manages the
configuration of our A/D converter, and determines a variety of things, including:
1. SEL - Which channel should be used (0..7)
2. CLKDIV - A value to divide PCLK by to determine which speed the A/D Converter
should operate at (up to a maximum of 4.5MHz)
3. CLKS - How precise the conversion results should be (between 3 and 10 bits)
4. PDN - Whether the A/D Converter is currently active (1) or sleeping (0)
This set of 8 bits corresponds to the 8 different 'channels' available on either A/D converter.
1. AD_CR_CLKS10: Sets the bit-accuracy of the converted values to the maximum 10-bit
(values between 0 and 1023)
2. AD_CR_PDN: Exits 'powered-down' mode, activating the ADC
3. ((3 - 1) << AD_CR_CLKDIVSHIFT): Set the CLK divider (12MHz/3) and shifts it to the
left to it's appropriate position
4. AD_CR_SEL3: Selects AD0 channel 3
Step 2: Reading the Conversion Results
Each ADC channel has it's own dedicated data register (ADDR0..7) that we can use to 'read' the
results of the analog to digital conversion, as well to check whether the current conversion is
complete or not. This bit is set to 1 when an A/D conversion is complete.If DONE is 1 (meaning
the conversion is complete), these 10 bits will contain a binary number representing the results of
our analog to digital conversion.
Before we can read the results from the A/D Data Register, we first need to perform the
following steps (to start the actual conversion process by re-configuring ADCR):
1. Stop any current conversions and deselect all channels
2. Select the channel you wish to use in your conversion
3. Manually tell the ADC to start converting
4. Wait for the conversion to complete
5. Read the 10-bit conversion results