LPC 17xx ADC: Done by

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

LPC 17xx ADC

DONE BY
PRIYANGA KR
AP/ECE
ADC
❏ The ADC Peripheral is an important part of modern Microcontrollers

❏ It helps us in interfacing the Analog Devices like Sensors to the MCU.


Introduction
❏ ADC is short for Analog to Digital Converter.

❏ ADC converts an analog signal to a digital signal.

❏ Ex: Audio recording system, Temperature, Sound, Image, Pressure, etc.,

❏ All modern ADC implementations are IC based to reduce the complexity of matched
components.
Features
❏ The LPC1768 MCU consists of an 8-channel 12-bit Successive Approximation type
Analog to Digital Converter.

❏ 12-bit is the resolution of the ADC, which represents the number of discrete values an
ADC can produce for a given analog reference voltage.

❏ ADC in LPC1768 is having a resolution of 12-bits, it can produce 2^12 discrete values
for a range of analog voltages, which is usually between 0V and 3.3V.

❏ Resolution in terms of Voltage = VREFP – VREFN / 2M.


Resolution of ADC = 3.3/(2^{12}) = 3.3/4096 =0.000805 = 0.8mV$$
LPC1768 ADC Pins
Adc Channel Port Pin Pin Functions Associated PINSEL Register
AD0 P0.23 0-GPIO, 1-AD0[0], 2-I2SRX_CLK, 3-CAP3[0] 14,15 bits of PINSEL1
AD1 P0.24 0-GPIO, 1-AD0[1], 2-I2SRX_WS, 3-CAP3[1] 16,17 bits of PINSEL1
AD2 P0.25 0-GPIO, 1-AD0[2], 2-I2SRX_SDA, 3-TXD3 18,19 bits of PINSEL1
AD3 P0.26 0-GPIO, 1-AD0[3], 2-AOUT, 3-RXD3 20,21 bits of PINSEL1
AD4 P1.30 0-GPIO, 1-VBUS, 2- , 3-AD0[4] 28,29 bits of PINSEL3
AD5 P1.31 0-GPIO, 1-SCK1, 2- , 3-AD0[5] 30,31 bits of PINSEL3
AD6 P0.3 0-GPIO, 1-RXD0, 2-AD0[6], 3- 6,7 bits of PINSEL0
AD7 P0.2 0-GPIO, 1-TXD0, 2-AD0[7], 3- 4,5 bits of PINSEL0

VREFP, VREFN Positive and Negative Reference Voltages for both ADC and DAC (Isolated 3.3V and 0V)

VDDA, VSSA ADC Power Pins (Isolated 3.3V and 0V)


LPC1768 ADC Registers
Register Function Description

ADCR A/D Control Register. Used to Start ADC, Select Operating Mode, Channel
Selection, Set Clock Division.

ADGDR A/D Global Data Register. Contains the Data of the most recent A/D Conversion

ADINTEN A/D Interrupt Enable Register. Used to enable interrupt when a channel completes
conversion.

ADDR0 – A/D Channel Data Register. These registers hold the result of the recent conversion in
ADDR7 that respective channel.

ADSTAT A/D Status Register. Holds the status of all ADC Channels.

ADTRM A/D Trim Register. Contains Trim values for ADC an DAC.
ADC Modes
❏ Two ways in which the ADC Module can work
❏ Software Controlled Mode
❏ Burst Mode (or Hardware Mode)

❏ In Software Controlled Mode, only one channel must be made active during a
conversion and at a time only one conversion is possible. To convert again, you have to
repeat the process.

❏ In Hardware Scan Mode or Burst Mode, the conversions will happen continuously on
any number of channels starting from LSB (AD0.0) then progressing towards MSB
(AD0.7).
ADC Register Configuration
ADCR

31:28 27 26:24 23:22 21 20:17 16 15:8 7:0

Reserved EDGE START Reserved PDN Reserved BURST CLCKDIV SEL

ADGDR

31 27 26:24 23:16 15:4 3:0

DONE OVERRUN CHN Reserved RESULT Reserved


Software-Controlled Mode
❏ The Power Control for Peripherals Register or PCONP is used enable or disable a
peripheral block. The ADC is disabled on reset. So, first enable ADC by setting the 12th
bit in PCONP register.

❏ LPC_SC->PCONP |= (1<<12);

❏ LPC_ADC->ADCR |= (1<<21);

❏ AD0.0 channel and set the ADC Clock Divider as 1.


LPC_ADC->ADCR |= (1<<0) | (1<<8);
Contd...
❏ LPC_ADC->ADCR |= (1<<24);

❏ while((LPC_ADC->ADDR0 & (1<<31)) == 0);

❏ int result = ((LPC_ADC->ADDR0 >> 4) & 0xFFF);


Burst Mode
❏ The power setup in PCONP register and ADCR register and the clock divider settings
remain the same even in burst mode.

❏ LPC_SC->PCONP |= (1<<12);

❏ LPC_ADC->ADCR |= (1<<21) | (1<<8);

❏ LPC_ADC->ADCR |= (1<<0) | (1<<1);

❏ LPC_ADC->ADCR |= (1<<16);
Contd...
❏ unsigned long value ADGDR = LPC_ADC->ADGDR;

❏ int channel = ((valueADGDR >> 24) & 0x07);

❏ int result = ((valueADGDR >> 4) & 0xFFF);


References
https://www.electronicshub.org/how-to-use-adc-in-lpc1768/

https://www.exploreembedded.com/wiki/LPC1768:_ADC_Programming

http://www.ocfreaks.com/lpc1768-adc-programming-tutorial/

https://openlabpro.com/guide/adc-module-lpc1768/

You might also like