This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C5505 ADC

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

  • Hi,

    Team is working on and will update your request shortly.

    Thanks & regards,

    SIvaraj K

  • Hi,

    Your Configuration looks ok. You are using VDD_ANA as a reference and not internal Bandgap reference with respect to this configuration looks ok.

      Few inputs required from you:

    • Is this your custom board ?
    • Can you try performing single conversion and check ?
    • Did you try vary the input voltage, what value are you observing ?

      Also, Refer to the below mentioned forum , this provides useful information (including calibration).

      http://e2e.ti.com/support/dsp/c5000/f/109/p/280024/977988.aspx#977988

      http://e2e.ti.com/support/dsp/c5000/f/109/p/90672/326116.aspx#326116

    Regards

        Vasanth

     

  • Vasantha, 

    Thanks for your reply, i got a output. 

    1. Yes it is my custom board

    2. yeah i checked single conversion 

    3. yeah i varied the input., and checked i got output., My VDD_ANA is 1.3. so i varied 0 to 1.3 using Trimpot.

    I Faced difficulties in using CHO,CH1,CH2,CH3 because these channels has additional circuit between pin and SAR so i used CH4 i.e, GPAIN2. At this pin successfully i got a output for ADC. Done little modification in code i pasted the code here for future engineers.

    ADC.h --- 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
    | ( 4 << 12 ) // select Channel 1
    | ( 1 << 11 ) // 0 - Normal mode, 1 - multi channel mode
    | ( 0 << 10 ); // continuous start
    SARCLKCTRL =49; // 2Mhz 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
    */
    }

    Main.c --- file

    void main(void)
    {
    USBSTK5515_init(); // Enable clock to all peripherals 
    SPI_Init(); // Initialize the SPI0
    adc_init();
    SARCTRL |= 0x8000; // ADC conversion start

    DAC_CS_HIGH();

    for(i=0;i<51;i++)
    {
    xval[i]=0;
    }

    while(1)
    {
    // READ ADC SAMPLE 
    while((SARDATA & 0x8000)==1 );
    value = SARDATA;
    adc_value = (0x03FF & value);

    }

    }

  • Could you try the following changes?

    SARCTRL = 0
    | ( 0 << 15 ) // ADC conversion start
    | ( 000,010,011,etc. for [12:14] ) // select Channel 1  --------->Try other channels
    | ( 0 << 11 ) // 0 - Normal mode, 1 - multi channel mode --------->Normal mode
    | ( 1 << 10 ); // continuous start ---------> 1 conversion

    SARCLKCTRL = 149; // 1Mhz Clock
    SARPINCTRL = 0
    | ( 0 << 14 ) // 12-15 always of data register //Keep ADCBUSY bit15 active and not permanently cleared
    | ( 1 << 13 ) // power up bias
    | ( 1 << 12 ) // analog power to sar
    | ( 1 << 8 ) // Ref V - VDD_ANA
    | ( 0 << 1 ); // 1 ch0 grounded , 0 ch0 is not grounded GNDON  //Try not grounding channel0

    Best Regards.

  • KRaviS, 

     Sure i will try and post. right now i have to finish my task. so am go ahead with that. Sure one day my update will be here...

  • Hi,

      From your reply looks like it worked for you when used other channel. I am glad it worked for you.

    Regards

     Vasanth