Line 46: Line 46:
  
 
==User guide==
 
==User guide==
Program to demonstrate multi(4) channel ADC, 10bit(0-1023) adc value is displayed on lcd
 
 
 
<syntaxhighlight>
 
<syntaxhighlight>
 +
Program to demonstrate multi(4) channel ADC, 10bit(0-1023) adc value is displayed on lcd
 
#include "lcd.h"  //User defined LCD library which contains the lcd routines
 
#include "lcd.h"  //User defined LCD library which contains the lcd routines
 
#include "adc.h"  //User defined library which contains the adc routines
 
#include "adc.h"  //User defined library which contains the adc routines
Line 54: Line 53:
  
 
/* start the main program */
 
/* start the main program */
void main()  
+
int  main()
 
{
 
{
  uint16_t adc_result0,adc_result1;
+
uint16_t adc_result0,adc_result1;
 +
 
 +
 
 +
LCD_Init(8,2,16);  /* Initialize the lcd(8-bit 2X16type) */
 +
 
 +
 
 +
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 ch0, ch1*/
 +
adc_result1= ADC_GetAdcValue(1);
 +
 
  
 
+
LCD_GoToLine(E_LcdLineTwo);   /*Display the adc values on LCD*/
  LCD_Init(8,LCD_16x2); /* Initialize the lcd before displaying any thing on the lcd */
+
LCD_Printf("C0:%d C1:%d ",adc_result0,adc_result1);
 +
}
  
 
+
return 0;
  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);
+
  
     
 
        LCD_GoToLine(LCD_LineOne);    /*Display the adc values on LCD*/
 
LCD_Printf("C0:%d C1:%d ",adc_result0,adc_result1);       
 
   
 
    }
 
  }
 
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 19:12, 25 December 2014

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}}
Defination 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}}
Defination uint16_t ADC_GetAdcValue(uint8_t channel)
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

Program to demonstrate multi(4) channel ADC, 10bit(0-1023) adc value is displayed on lcd
#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 */
int  main()
{
	uint16_t adc_result0,adc_result1;
 
 
	LCD_Init(8,2,16);  /* Initialize the lcd(8-bit 2X16type) */
 
 
	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 ch0, ch1*/
		adc_result1= ADC_GetAdcValue(1);
 
 
		LCD_GoToLine(E_LcdLineTwo);    /*Display the adc values on LCD*/
		LCD_Printf("C0:%d C1:%d ",adc_result0,adc_result1);
	}
 
	return 0;
}