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}}
 
|-
 
|-
|Defination || '''void ADC_Init()'''
+
|Definition || void ADC_Init()
 
|-
 
|-
 
| Input Arguments || none
 
| Input Arguments || none
Line 27: Line 29:
  
 
==ADC_GetAdcValue==
 
==ADC_GetAdcValue==
{| class="wikitable"  style="colspan:1; background-color:#4682B4;"
+
{| {{Widget:LibCol}}
 
{{#Widget:LibTable}}
 
{{#Widget:LibTable}}
 
|-
 
|-
|Defination || '''uint16_t ADC_GetAdcValue(uint8_t channel)'''
+
|Definition ||<syntaxhighlight> uint16_t ADC_GetAdcValue(uint8_t var_adcChannel_u8)</syntaxhighlight>
 
|-
 
|-
| Input Arguments || '''uint8_t(channel number).'''
+
| Input Arguments || uint8_t : channel number
 
|-
 
|-
| Return Value|| '''uint16_t(10 bit ADC result)'''
+
| 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==
Program to demonstrate multi(4) channel ADC, 10bit(0-1023) adc value is displayed on lcd
+
<html>  
 
+
<script src="https://gist.github.com/Amritach/c2832a936ab1faf3117e.js"></script>
<syntaxhighlight>
+
</html>
#include "lcd.h"  //User defined LCD library which contains the lcd routines
+
#include "adc.h"  //User defined library which contains the adc routines
+
 
+
 
+
/* start the main program */
+
void main()
+
{
+
  uint16_t adc_result0,adc_result1;
+
 
+
 
+
  LCD_Init(8,LCD_16x2);  /* Initialize the lcd before displaying any thing on the lcd */
+
 
+
 
+
  ADC_Init();  /* Initialize the adc before starting the conversion */
+
 
+
    LCD_DisplayString(" 2-Channel ADC ");
+
+
+
 
+
  while(1)      /* Display the adc channel zero,One values continuously */  
+
    {
+
 
+
adc_result0= ADC_GetAdcValue(0);  /*Get the adc values of the first four channels(0-3) */
+
adc_result1= ADC_GetAdcValue(1);
+
  
     
+
{{DISQUS}}
        LCD_GoToLine(LCD_LineOne);    /*Display the adc values on LCD*/
+
LCD_Printf("C0:%d C1:%d ",adc_result0,adc_result1);       
+
   
+
    }
+
  }
+
</syntaxhighlight>
+

Latest revision as of 18:07, 30 May 2015

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
  1. uint16_t ADC_GetAdcValue(uint8_t var_adcChannel_u8)
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);
}
}