ADC of ARM MBED (LPC1768) - MBED
ADC of ARM MBED (LPC1768) - MBED
ADC (Analog to Digital converter) is most widely used device in embedded systems which is designed especially to convert analog
signal into digital signal. ARM MBED LPC1768 has in-built 12-bit ADC.
MBED LPC1768 has on-board 6 ADC channels (analog inputs) i.e. p15 – p20 which is shown in below image,
In the MBED board, there are total 12-bit 6 Analog Input available from p15 to p20 and 1 Analog output pin is available on p18.
The function for analog input is as follows.
Analog Input:
AnalogIN (pin)
Create an AnalogIN Object for pin that we are using as analog input.
pin: give the pin name which we read as an input (from p15 to p20).
Ex. AnalogIn sensor_one(p15)
ADC.read()
This statement is used for to read the analog input voltage in the float value from 0.0 to 1.0 volt.
Ex. sensor_one.read();
ADC.read_u16()
This statement is used for to read the analog input voltage in the unsigned value from 0x0 to 0xFFFF.
Ex. sensor_one.read_u16();
Note: AnalogIn() reads the voltage as a fraction of the system voltage The value is a floating point from 0.0 (VSS) to 1.0 (VCC).
For example, if you have a 3.3V system and the applied voltage is 1.65V, then AnalogIn() reads 0.5 as the value.
Interfacing Diagram
Connect a potentiometer to the p20 pin of ARM mbed board as shown in above figure and monitor the on-board LED1.
Example
ADC read’s the changeable potentiometer values and comparing it, as well as print these values on serial monitor.
When ADC value is greater than 0.3 volt then LED1 will turn ON.
And when ADC value is less than 0.3 volt then LED1 will turn OFF.
Program
#include "mbed.h"
AnalogIn ain(A5);
DigitalOut dout(LED1);
int main(void)
while (1) {
dout = 1;
} else {
dout = 0;
wait(0.2f);