Professional Documents
Culture Documents
Experiment No 3 Adc
Experiment No 3 Adc
ADVANCED PROCESSORS
Experiment NO: 3
Title: Interfacing of LPC2148 for internal ADC on interrupt basis at regular interval
generated by timer.
Objectives: After performing this experiment, learners will be able to express the concept of
interfacing of ADC with LPC 2148 and apply the knowledge of same interfacing in a
particular embedded application.
Aim: To interface ADC with LPC 2148 and show the output on LCD on interrupt basis at
regular interval generated by timer.
The A/D Control Register establishes the configuration of the converter and controls
the start of conversion. The first step in configuring the converter is to set up the peripheral
clock. As with all other peripherals, the A/D clock is derived from the PCLK. This PCLK
must be divided down to equal 4.5 MHz. This is a maximum value and if PCLK cannot be
divided down to equal 4.5 MHz. This is maximum value and if PCLK cannot be divided
down to equal 4.5MHz then the nearest value below 4.5MHz which can be achieved should
be selected
AD Data Register: This Contains Conversion done flag and Overrun Error
Features
• 10 bit successive approximation analog to digital converter.
• Measurement range of 0 V to VREF (2.0 V ≤ VREF ≤ VDDA).
• Each converter capable of performing more than 400,000 10-bit samples per second.
• Every analog input has a dedicated result register to reduce interrupt overhead.
• Burst conversion mode for single or multiple inputs.
• Optional conversion on transition on input pin or timer match signal.
• Global Start command for both converters (LPC2142/44/46/48 only).
PROCEDURE:
ALGORITHM :-
A. Main Routine:-
1. Start.
2. Initialize ADC and UART.
3. Declare UART and ADC Pins.
4. Execute the Test Point for UART Verification.
5. Send SOC Signal.
6. Wait for EOC Signal.
7. Read Data from ADC.
8. Shift ADC Data to LSB Position.
9. Mask all other bits except first 10 bits.
10. Process Data (BCD Conversion) and Transmit the ADC Data through UART to PC.
11. Execute the Test Point for UART Verification.
12. End.
CODE:
/***************************************************************/
/* This Program is to demonstrate the On Chip ADC Functionality */
/****************************************************************
Processor : LPC2148
*****************************************************************/
#include "LPC214x.h"
#include "stdio.h"
#include "LCD.h"
#include "UART.h"
void ADCInit(void)
{
int i;
i = PINSEL1 ;
i = ( i & 0xF0FFFFFF );
PINSEL1 = (i | (ADC0 | ADC1));
return volt_mv ;
}
for(i=0;i<4;i++)
{
ch = number =0;
ch = value & 0xF0000000;
ch = ch >> 28;
SendData(number);
value = value << 4;
}
}
int main(void)
{
unsigned int ad0_data,ad1_data,voltage;
unsigned char *String="ADC Value (hex)";
UartInit(9600);
ADCInit();
InitLCD();
while(*String)
{
SendData(*String);
String++;
}
while(1)
{
if(AD0STAT & 0x03)
{
// SendInstruction(0xC0);
voltage = get_adc_voltage(ad1_data);
// display_on_lcd(ad1_data);
printf("\r\nADC Voltage (mV) = %4d ",voltage);
}
}
return 0;
}
/**************************************************************************
End of file
**************************************************************************/
Output: After varying the potentiometer available on board, we can observe its equivalent
value after application of interrupt at regular interval.
Conclusion: Hence we can conclude that, with the help of ADC interfacing with LPC 2148
we can display the output on Hyper Terminal.