hi,
am reading ADC wrote code in c. am connecting Dc input with Potentiometer at 0 to 1.3 voltage variation. it is ten bit adc means for maximum referrence i want to get 1024., but am getting only 130., what is the reason this? kindly cross check my codings and tell about mistake i made in this , y am not getting maximum resolution bit for 1.3 reference.
#include "stdio.h"
#include "usbstk5515.h"
#include "Adc.h"
int adc_value;
unsigned int value;
extern void adc_init( );
void main( void )
{
/* Initialize BSL */
USBSTK5515_init( );
adc_init();
SARCTRL |= 0x8000; // ADC conversion start
while(1)
{
while((SARDATA & 0x8000)==1 );
value = SARDATA;
adc_value = 0x03FF & value; //
printf("\n Adc Value = %d ",value);
}
}
//////////////////////////////////////////////////////////////////////////////////////Header File//////////////////////////////////////////////////////////////////////////
/* ------------------------------------------------------------------------ *
* ADC Module *
* ------------------------------------------------------------------------ */
#define SARCTRL *(volatile ioport Uint16*)(0x7012)
#define SARDATA *(volatile ioport Uint16*)(0x7014)
#define SARCLKCTRL *(volatile ioport Uint16*)(0x7016)
#define SARPINCTRL *(volatile ioport Uint16*)(0x7018)
#define SARGPOCTRL *(volatile ioport Uint16*)(0x701A)
void adc_init()
{
SARCTRL = 0
| ( 0 << 15 ) // ADC conversion start
| ( 1 << 12 ) // select Channel 1
| ( 1 << 11 ) // 0 - Normal mode, 1 - multi channel mode
| ( 0 << 10 ); // continuous start
SARCLKCTRL = 149; // 1Mhz Clock
SARPINCTRL = 0
| ( 1 << 14 ) // 12-15 always of data register
| ( 1 << 13 ) // power up bias
| ( 1 << 12 ) // analog power to sar
| ( 1 << 8 ) // Ref V - VDD_ANA
| ( 1 << 1 ); // 1 ch0 grounded , 0 ch0 is not grounded GNDON
SARGPOCTRL = 0;
/* | ( 1 << 3 ) // GPAIN3 Driven high
| ( 1 << 2 ) // GPAIN2 Driven high
| ( 1 << 1 ) // GPAIN1 Driven high
| ( 1 << 0 ); // GPAIN0 Driven high
*/
}
Many Thanks,
Thiyagarajan.S