Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Dept. of Electronics and Telecom.

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.

Apparatus: : LPC2148 Evaluation Board, USB to Serial communication cable, Power


supply adaptor. Pc with Keil uVision4 and Flash Magic software
Theory:
The Analog-To-Digital Converter on some LPC2148 is 10-bit successive approximation
converter, with a conversion time of 2.44usec or just say 410 Kbps. The A/D converter has
either 4 or 8 multiplexed input depending on the variant.

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

TE E&TC Page No.


Dept. of Electronics and Telecom. ADVANCED PROCESSORS

AD Control Register:- It determines the conversion mode, Channel & Resolution.

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).

INTERFACING ADC –LPC2148:


Adjustable potentiometer RPOT1 is connected to analog channel P0.6 (AD1.0 — ADC 1, input 0.
Available in LPC2144/46/48 only.). JP13 jumper is used to enable the potmeter input. VR1 setting
provides input voltages between 0V and 3V3
to the ADC

TE E&TC Page No.


Dept. of Electronics and Telecom. ADVANCED PROCESSORS

PROCEDURE:

1. Provide +5v dc power supply to ARM LPC2148 board.


2. Connect ARM LPC2148 board to computer using USB to serial cable.
3. Open Keil uVision4
4. Select new project
5. Then go on local drives (desktop) & create folder and give file name related to our
project and save this file
6. Select device(NXP-LPC2148)
7. After this one window will appear “start-up file”, click on yes.
8. Go to file select new file and write code in this new file and save this file as “.c” file
then right click on target and select “options for target”. Click on linker and select
“use memory layout” and click on output and select “create hex file”.
9. Double click on source group 1 and add “.c ” file
10. Click on “translate current file ” , click on “build target” , click on” rebuild all target
files”

TE E&TC Page No.


Dept. of Electronics and Telecom. ADVANCED PROCESSORS

11. Open flash magic


12. Select device LPC2148.
13. Select com port which has been utilised by our ARM LPC 2148 board (right click
computer then click on properties, after this go to hardware and click on device
manager. In device manager observed which port has been utilised by “prolific
drivers” )
14. Set baud rate -9600
15. Set interface-none
16. Set oscillator frequency 12 Mhz
17. Click on “erase all flash codes”
18. Browse and select hex file which has been created in our project folder
19. Go to ISP and click on read device signature , if device is not ready then at a same
press reset and interrupt key on ARM LPC 2148 board and first release reset and then
interrupt.
20. Then click on start to load programme in LPC2148
21. Open Hyper Terminal (on Flash Magic --- Tools--- Terminal --- Terminal Settings ---
Hyper Terminal )
22. To observe output press reset.

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.

TE E&TC Page No.


Dept. of Electronics and Telecom. ADVANCED PROCESSORS

Flow Chart for Main Routine:-

TE E&TC Page No.


Dept. of Electronics and Telecom. ADVANCED PROCESSORS

CODE:
/***************************************************************/
/* This Program is to demonstrate the On Chip ADC Functionality */
/****************************************************************
Processor : LPC2148

ADC 0 Mapping : AD0.1 -> P0.28


AD0.2 -> P0.29

Jumper Settings : No jumper selection

*****************************************************************/
#include "LPC214x.h"
#include "stdio.h"
#include "LCD.h"
#include "UART.h"

#define ADC0 1 << 24


#define ADC1 1 << 26
#define ADC_ON 1 << 21
#define ADC_Start 1 << 24

#define ADC_Channel 0x03 // selects the channel 0


and 1 for ADC0
#define ADC_Divider 0x03 << 8 // selects the divider
value
#define ADC_Burst 1 << 16 // burst mode selection
#define ADC_CLKS 0x00 << 17 // number of bits

void adcdelay(unsigned int time)


{
unsigned int i,j;
for(i = 0; i < time ;i++ )
{
for(j = 0; j < 10000 ; j++);
}
}

void ADCInit(void)
{
int i;
i = PINSEL1 ;
i = ( i & 0xF0FFFFFF );
PINSEL1 = (i | (ADC0 | ADC1));

AD0CR = (ADC_Channel | ADC_Divider | ADC_Burst | ADC_CLKS);


// ADC control register settings
i = AD0CR;
AD0CR = (i | ADC_ON); // start ADC Conversion
}

unsigned int get_adc_voltage(unsigned int volt)


{
unsigned int volt_mv;

TE E&TC Page No.


Dept. of Electronics and Telecom. ADVANCED PROCESSORS

volt_mv = ((volt * 3300) / 1024);

return volt_mv ;
}

display_on_lcd(unsigned int value)


{
unsigned int ch, number,i;
value = value << 16;

for(i=0;i<4;i++)
{
ch = number =0;
ch = value & 0xF0000000;
ch = ch >> 28;

if((0 <= ch && ch <= 9))


{
number = ch + 0x30;
}
if((0xA <= ch && ch <= 0xF))
{
number = ch + 0x37;
}

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);

ad1_data = (AD0DR1 & 0x0000FFC0)>>6;


adcdelay(500);

TE E&TC Page No.


Dept. of Electronics and Telecom. ADVANCED PROCESSORS

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.

TE E&TC Page No.

You might also like