Difference between revisions of "ADC"
m |
|||
(16 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
In case of AVR/PIC/ARM or other high end controllers the inbuilt adc is used. | 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. | In case of 8051/8052 as it doesn't have an inbuilt adc, ADC0809(8-bit) adc is used. | ||
+ | |||
+ | |||
Line 10: | Line 12: | ||
{{#Widget:LibTable}} | {{#Widget:LibTable}} | ||
|- | |- | ||
− | | | + | |Definition || void ADC_Init() |
|- | |- | ||
| Input Arguments || none | | Input Arguments || none | ||
Line 27: | Line 29: | ||
==ADC_GetAdcValue== | ==ADC_GetAdcValue== | ||
− | {| | + | {| {{Widget:LibCol}} |
{{#Widget:LibTable}} | {{#Widget:LibTable}} | ||
|- | |- | ||
− | | | + | |Definition ||<syntaxhighlight> uint16_t ADC_GetAdcValue(uint8_t var_adcChannel_u8)</syntaxhighlight> |
|- | |- | ||
− | | Input Arguments || | + | | Input Arguments || uint8_t : channel number |
|- | |- | ||
− | | Return Value|| | + | | 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. | | Description || This function does the ADC conversion for the Selected Channel and returns the converted 10bit result. | ||
Line 46: | Line 48: | ||
==User guide== | ==User guide== | ||
− | + | <html> | |
− | + | <script src="https://gist.github.com/Amritach/c2832a936ab1faf3117e.js"></script> | |
− | < | + | </html> |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | {{DISQUS}} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
Latest revision as of 18:07, 30 May 2015
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} | |
} |