Вы находитесь на странице: 1из 8

Date:

Experiment No.6

On chip ADC interfacing

Aim: Interfacing LPC2148 for internal ADC on interrupt basis

Components:
 Educational practice board for ARM7 LPC2148
 All in one general purpose board (ASK25)
 +9V power supply
 USB A to B type cable
 20 pin flat cable
 Single lead wire
 PC
 Eclipse IDE
 Flash Magic Utility

Connections:

 J1 of ARM7 is connected to PL3 of ASK25


 J4 -( 3 PIN Connector of ARM) pin1 is connected to pin 1 of PL-10 of ASK 25 (short
pin 1 and pin 2 of JP4 and JP5)

Note: Make sure the following header files are included in the project:
Included Files:

HEADER FILES SOURCE FILES


LPC214x.h VIClowlevel.c
VIClowlevel.h lcd.c
Lcd.h
Interfacing diagram:

Pin Connection PL3 Connector of Ask25 J1 Connector of EPBARM7


1 P0.0
2 P0.1
3 P0.2
4 P0.3
5 P0.4
6 RS P0.5
7 R/W* P0.6
8 E P0.7
9 NC
10 D0 P0.8
11 D1 P0.9
12 D2 P0.10
13 D3 P0.11
14 D4 P0.12
15 D5 P0.13
16 D6 P0.14
17 D7 P0.15
18 3.3V
19 5V 5.0V
20 GROUND GND
PL10:
ASK-25A has a 3 pin Relimate connector which brings out 2 analog signals from potentiometer.
J4 - 3 pin Relimate connector
The EPBARM7 has 3 pin Relimate connector which brings out ADC-0 module signals. The
ADC0 connector is routed to 3 pin connector J4. Two channels of the ADC are available on this
connector.
Pin No. Connection GPIO
1 AD0.1 P0.28
2 AD0.2 P0.29

Remaining ADC channels are available on P7.

The EPBARM7 has 4 pin FRC connector which brings out the ADC signals.

Pin No. P7 GPIO


1 AD0.3 P0.30
2 AD0.4 P0.25
3 AD0.6 P0.4
4 AD0.7 P0.5
5 AD1.0 P0.6
6 AD1.1 P0.8
7 AD1.2 P0.10
8 AD1.3 P0.12
9 AD1.4 P0.13
10 AD1.5 P0.15
11 AD1.6 P0.21
12 AD1.7 P0.22
13 VCC
14 GND

ADGDR:

A/D Global Data Register. This register contains the ADC’s DONE bit and the result of the
most recent A/D conversion.

Bit 31 30 29:27 26:24 23:16 15:6 5:0


Symbol DONE OVERUN - CHN - RESULT -

Bit Description
0:5 Reserved, user software should not write ones to reserved bits. The value read from
a reserved bit is not defined.

15:6 When DONE is 1, this field contains a binary fraction representing the voltage on the
Ain pin selected by the SEL field, divided by the voltage on the VDDA pin (V/VREF).
Zero in the field indicates that the voltage on the Ain pin was less than, equal to, or close
to that on VSSA, while0x3FF indicates that the voltage on Ain was close to, equal to, or
greater than that on VREF
.

23:16 Reserved, user software should not write ones to reserved bits. The value read from
a reserved bit is not defined.

26:24 These bits contain the channel from which the RESULT bits were converted
29:27 Reserved, user software should not write ones to reserved bits. The value read from
a reserved bit is not defined.

30 This bit is 1 in burst mode if the results of one or more conversions was (were) lost
and overwritten before the conversion that produced the result in the RESULT bits.
This bit is cleared by reading this register.

31 This bit is set to 1 when an A/D conversion completes. It is cleared when this register is
read and when the ADCR is written. If the ADCR is written while a conversion is still in
progress, this bit is set and a new conversion is started.

ADGSR: A/D Global Start Register. This address can be written (in the AD0 address range) to
start conversions in both A/D converters simultaneously.

Bit 31:28 27 26:24 23:17 16 15:0


Symbol - EDGE START - BURST -

Bit Symbol Description


15:0 Reserved, user software should not write ones to reserved bits. The value read
from a reserved bit is not defined

16 BURST 0 The AD converters do repeated conversions at the rate selected by their


CLKS fields, scanning (if necessary) through the pins selected by 1s in
their SEL field. The first conversion after the start corresponds to the
least-significant 1 in the SEL field, then higher numbered 1-bits (pins) if
applicable. Repeated conversions can be terminated by clearing this bit,
but the conversion that’s in progress when this bit is cleared will be
completed.

1 Conversions are software controlled and require 11 clocks.


23:17 - Reserved, user software should not write ones to reserved bits. The value read
from a reserved bit is not defined.

26:24 START 000 No start (this value should be used when clearing PDN to 0)
001 Start conversion now
010 Start conversion when the edge selected by bit 27 occurs on
P0.16/EINT0/MAT0.2/CAP0.2 pin

011 Start conversion when the edge selected by bit 27 occurs on


P0.22/CAP0.0/MAT0.0 pin.
100 Start conversion when the edge selected by bit 27 occurs on MAT0.1
101 Start conversion when the edge selected by bit 27 occurs on MAT0.3
110 Start conversion when edge selected by bit 27 occurs onMAT1.0.
111 Start conversion when the edge selected by bit 27 occurs on MAT1.1
27 EDGE 0 Start conversion on a falling edge on the selected CAP/MAT signal.
1 Start conversion on a rising edge on the selected CAP/MAT signal.
31:28 - Reserved, user software should not write ones to reserved bits. The value read
from a reserved bit is not defined.

ADDR0: The A/D Data Register holds the result when an A/D conversion is complete, and also
includes the flags that indicate when a conversion has been completed and when a conversion
overrun has occurred.

Bit 31 30 29:16 15:6 5:0


Symbol DONE OVERUN - RESULT -

Bit Symbol Description


0:5 - Reserved, user software should not write ones to reserved bits. The value
read from a reserved bit is not defined.

15:6 RESULT When DONE is 1, this field contains a binary fraction representing the
voltage on the AIN pin, divided by the voltage on the VREFpin
(V/VREF).Zero in the field indicates that the voltage on the AIN pin was
less than, equal to, or close to that on VSSA while 0x3FF indicates that
thevoltage on AIN was close to, equal to, or greater than that on VREF.
29:16 - Reserved, user software should not write ones to reserved bits. The value
read from a reserved bit is not defined.
30 OVERUN This bit is 1 in burst mode if the results of one or more conversions was
(were) lost and overwritten before the conversion that produced the result in
the RESULT bits.This bit is cleared by reading this register

31 DONE This bit is set to 1 when an A/D conversion completes. It is cleared when
this register is read

Sample Algorithm:

void attribute_((interrupt(“IRQ”)) timer_routine(void)

1. Start interrupt service routine ISR_ENTRY();


2. Read ADC value.
3. Display value in hex after conversion.
4. Go to vector address = 0x00(vendor specific).
5. TOIR=1(clear interrupt).
6. Exit from interrupt service routine.

main program(read ADC value after every 1 second)

1. Initialise LCD.
2. Write string to LCD.
3. Display channel number.
4. Configure timer mode T0CTCR = 0X00.
5. T0PC = 0, Prescalar counter is set to 0.
6. T0pr = 0XF0, Prescalar is set to hex value of 240 so 12 Mhz/240 = 50000
7. T0mr0 = 0x350, The match register values are continuously compared to the timer
counter value. When the two values are equal enable reload thr’ match control register.
8. T0MCR = 0X3, Interrupt on match and reset timer.
9. T0TCR = 1, Enable timer again.
10. VIC Int Enable |=(0X01 << 4) Enable interrupt corresponding to timer 0(bit 4 is
dedicated to timer 0 interrupt).
11. VIC VectAddr0 = unsigned timer0_routine, return the address for interrupt service
routine.
12. VIC Vect Cntl0 = (0X24).
13. Enable interrupt.

void read adc

1. Configure ADC with PINSEL1 (AD0.1)


2. VPBDIV = 1 ; PCLK = CCLK
3. Select channel 1 ADC0.

void read adc(unsigned int *value)

1. Select ADC0 channel 1 through PINSEL register.


2. Give Global start command through ADGSR A/D global start register.
3. While DONE bit is set in AD0GDR, put the result from the 6th bit position in value.

Steps to use hardware:

 Connect 9V DC Power supply to the educational practice board for ARM7


 Connect the board with the USB port of the PC using the USB A to B type cable.
 Using the RUN/PROGRAM mode selection switch, set the board in the program mode.
This will be indicated by the red LED.
 Apply Reset condition by pressing the RESET switch to ensure proper communication.
 Using download tool (Flash Magic) downloads the .HEX file to the target board.
 Connect the J1 connector of EPB ARM7 board to PL3 connector of ASK25 using flat
cable. Connect single wire between Pin2 of PL10 connector on ASK25 and Pin 1 of J4
connector on EPBARM7 board.
 Press SW3 on ARM7 board to get the output.
 Using the RUN/PROGRAM mode selection switch, set the board in the run mode. This
will be indicated by the green LED and apply reset to execute the program.

Result:
ADC values would be displayed on LCD. Values will change every one second as you rotate
potentiometer RV3.Note hex output on LCD for 4 different positions of potenciometer.Also
measure same analog input with multimeter.

Questions:

1. Describe the features of ADC in LPC2148.


2. Write an algorithm for interrupt based ADC program.
3. Describe registers related to DAC in LPC2148.

Вам также может понравиться