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.

Problem with SAR channel2 on the TMS320VC5505

Other Parts Discussed in Thread: TMS320VC5505, TMS320C5515

Hi

I work  on the TMS320VC5505  and I want to use the SAR to measure the battery's voltage. I have done it  without use CSL. I use the channel1. And I don't understand the value in SARDATA. For example: if I supply my board with 2.6V, my voltage is divided by two before enter in GPAI0 with a divider (two resistor of 100K).

I should obtain in SARDATA . (1024 / 3.6)*1.3 / 8=46.2 but I have 207. Are There some registers to set to activate the divider ?have I  done some errors in my calcul ?

My other problem is that for a same voltage, my value in SARDATA fluctuate. Thus for 2.6V my value fluctuate between 203 and 207! Is it normal ?

For finish I wanted to use the channel2 because I don't want to divid by eight my value but I have always 1023 in SARDATA?

 

 

This is my code :

For initialize:

void Init_SAR(void)
{
    *SARCTRL = 0x1C00;          // Select channel 1 througth GPAIN0
    *SARCLKCTRL = 0x7fff;       
 
    *SARPINCTRL = 0x3402;     // SARPINCTRL       SAR A/D Reference and Pin Control Register

                                                // HALF : disable

                                                // GND0ON : enable

                                                //AVDDMEAS : disable

                                                // TOUCHSCREENMODE :disable

                                                //REFAVDDSEL :Reference Voltage based on Bandgap

                                                // REFLVSEL         0:Bandgap-Based Reference Voltage set to 0.8V.

                                                //SARPWRUP         0:SAR analog Powered down.

                                                //PWRUPBIAS         1:Powered Up. Required setting for performing A/D conversions.

    *SARGPOCTRL = 0;

}

For activate :

Void SAR(void)

{

            *SARPINCTRL = 0x3402;      
             *SARCTRL = 0x9C00;                                     //start conversion

                       
            do    //  check that the conversion has started !
            {
                val = *SARDATA;

            }while(!(val & 0x8000));

}

For read :

Void SAR_isr(Void)                     
{
    int testval;
    int i;
    LgUns val,mvolt_value ;
    val = *SARDATA;
    val=val    & 0x03ff;

}

 

Thanks for your help

 

Julien

  • Julien,

    The ADC Data (after conversion) = (Vin/Vref) x 1024.

    With your configuration:

    - Vin: 1.3/8

    - Vref: 0.8

    So, the ADC data will be ~ 208. So, the number you got was correct. The fluctuation will be combination of the fluctuation of the input volate, the reference voltage, and linearity of the ADC. If you use the half mode, the fluctuation will be reduced.

    Regards,

    Peter Chung

     

  • Thanks for your quickly answer,

     I am agree with you I have the well values in channel1. But I  don't understand values that I read with channel2. For example this are values that I obtain with channel2:

        * 3V -> 360
        * 3.2V ->362
        * 3.4V ->363
        * 3.4V-> 364

    The ADC DATA should be (1024/ Vref)*Vin/ DIV with VREF=1.3V, DIV=4( HALF is true and  I have one divider by 2 on  the input)

        *  3V -> ADC DATA =590
        * 3.2v-> ADC DATA =630
        * 3.4v ->ADC DATA =669
        * 3.6   ->ADC DATA = 708

    This is piece of my code :

    Initialization :

    void Init_SAR(void)
    {
        int select_ref_volt;
        *SARCTRL = 0x2C00;                      // select AIN2, which is GPAIN0
        *SARCLKCTRL = 0x0031;                  // 100/50 = 2MHz
        *SARGPOCTRL = 0;

        select_ref_volt=2;
        switch(select_ref_volt)
        {
            case 0 :
            *SARPINCTRL = 0x3407;                   // Vref 0.8
            break;
            case 1 :
            *SARPINCTRL = 0x3607;                   // Vref 1.0
            break;
            case 2 :

            *SARPINCTRL = 0x3107;                   //  SARPINCTRL       SAR A/D Reference and Pin Control Register for VREF=1.3v

                                                    // HALF : enable

                                                    // GND0ON : enable

                                                    //AVDDMEAS : disable

                                                    // TOUCHSCREENMODE :disable

                                                    //REFAVDDSEL   :Reference Voltage based on VDD_ANA

                                                    // REFLVSEL         0:Bandgap-Based Reference Voltage set to 0.8V.

                                                    //SARPWRUP         0:SAR analog Powered down.

                                                    //PWRUPBIAS         1:Powered Up. Required setting for performing A/D conversions.

            break;
        }

    For activate :

    Void SAR(void)
    {
            int val;

            *SARCTRL = 0xAC00;         // launch conversion
               
                do    // check that the conversion has started
                {
                    val = *SARDATA;
                }while(!(val & 0x8000));
       }   

    Interrupt for read :

    Void SAR_isr(Void)                        // Function for task created with Config Tool.
    {
        int     val;
       
        val = *SARDATA;              
         val=val & 0x03ff;   

    }    

     

    Thanks a lot for your help

    Julien

  • Julien,

    Have you tried the configuration suggested by the sectino 2.4 Battery Measurement in the SAR user's guide? http://focus.ti.com/lit/ug/sprufp1/sprufp1.pdf

    Regards,

    Peter Chung

     

  • Peter,

    I am very sorry, I have worked  on a other a project and I have forgotten to response you. I had ever tried the configuration suggested on the documentation and it works very well. Thanks.

    I have now an other problem. I would like to use the same code on the TMS320C5515 but I have an offset. around 400mV  on the value read by the SAR but not on the pin when I measure with a voltmeter. I have not seen any différences between the TMS320c5515 and the TMS320V5505 exept the initialization on the PRCR register.

    Thanks for your answer and sorry again

    Julien