ADC
Contents
[hide]ADC
This library provides the functions for initializing the adc and to get the raw adc values. In case of AVR/PIC/ARM or other high end controllers the inbuilt adc is used. In case of 8051/8052 as it doesn't have an inbuilt adc, ADC0809(8-bit) adc is used.
ADC_Init
{{#Widget:LibTable}}Definition | void ADC_Init() |
Input Arguments | none |
Return Value | none |
Description | This function initializes the ADC module. |
Usage | void main()
{ ADC_Init(); } |
ADC_GetAdcValue
{{#Widget:LibTable}}Definition |
|
Input Arguments | uint8_t : channel number |
Return Value | uint16_t(10 bit ADC result) |
Description | This function does the ADC conversion for the Selected Channel and returns the converted 10bit result.
The adc value per bit depends on the resolution of the ADC. For AVR/PIC(10-bit adc) the adc value per lsb will be 5/1023=0048v |
Usage | uint16_t adc_result;
adc_result = ADC_GetAdcValue(0); //Adc value for channel 0 |
User guide
#include<lpc17xx.h> | |
#include "lcd.h" //User defined LCD library which contains the lcd routines | |
#include "delay.h" //User defined library which contains the delay routines | |
#include "adc.h" | |
void main() | |
{ | |
uint16_t pot_value,ldr_value, temp_raw, temp_final; | |
float voltage; | |
SystemInit(); //Clock and PLL configuration | |
/* Setup/Map the controller pins for LCD operation | |
RS RW EN D0 D1 D2 D3 D4 D5 D6 D7*/ | |
LCD_SetUp(P2_0,P2_1,P2_2,P1_20,P1_21,P1_22,P1_23,P1_24,P1_25,P1_26,P1_27); | |
LCD_Init(2,16); /* Specify the LCD type(2x16) for initialization*/ | |
ADC_Init(); /* Initialize the ADC */ | |
while(1) | |
{ | |
pot_value = ADC_GetAdcValue(0); /* Read pot value connect to AD0(P0_23) */ | |
ldr_value = ADC_GetAdcValue(1); /* Read LDR value connect to AD1(P0_24) */ | |
temp_raw = ADC_GetAdcValue(2); /* Read Temp value connect to AD2(P0_25) */ | |
/* Converting the raw adc value to equivalent temperature with 3.3v as ADC reference using 12bit resolution. | |
Step size of ADC= (3.3v/2^12)= 3.3/4096 = 0.0008056640625 = 0.0806mv | |
For every degree celcius the Lm35 provides 10mv voltage change. | |
1 degree celcius = 10mv = 10mv/0.0806mv = 12.41 uinits | |
Hence the Raw ADC value can be divided by 12.41 to get equivalent temp | |
*/ | |
temp_final = temp_raw/12.41; | |
/* Vin = (Adc_value * REF)/ 2^12 */ | |
voltage = (pot_value * 3.3)/ 4096.0; | |
LCD_GoToLine(0); | |
LCD_Printf("P:%4d %f",pot_value,voltage); | |
LCD_Printf("\nL:%4d T:%4d",ldr_value,temp_final); | |
} | |
} |

Delay
DELAY This library provides the functions to generate the required delays. Basically it does the looping for the specified count to generate the delay. If the compiler provides the inbuilt...

ADC
ADC This library provides the functions for initializing the adc and to get the raw adc values. In case of AVR/PIC/ARM or other high end controllers the inbuilt adc is used. In case of 8051/8052...