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.

CCS/CC3200: How to read analog values for sensors in cc3200?

Part Number: CC3200
Other Parts Discussed in Thread: LM35

Tool/software: Code Composer Studio

Hi,

I am trying to connect the temperature sensor LM35DZ. I am taking the reference from ADC Demo. But, i am not getting correct values. Can you please look into the code?

What am I doing wrong?

        //
        // Initialize Array index for multiple execution
        //
        uiIndex=0;

        //
        // Read inputs from user
        //
//        if(!ReadFromUser(&uiAdcInputPin))
//        {
//          UART_PRINT("\n\rInvalid Input. Please try again. \n\r");
//          continue;
//        }

#ifdef CC3200_ES_1_2_1
        //
        // Enable ADC clocks.###IMPORTANT###Need to be removed for PG 1.32
        //
        HWREG(GPRCM_BASE + GPRCM_O_ADC_CLK_CONFIG) = 0x00000043;
        HWREG(ADC_BASE + ADC_O_ADC_CTRL) = 0x00000004;
        HWREG(ADC_BASE + ADC_O_ADC_SPARE0) = 0x00000100;
        HWREG(ADC_BASE + ADC_O_ADC_SPARE1) = 0x0355AA00;
#endif

        uiAdcInputPin= PIN_59;
        //
        // Pinmux for the selected ADC input pin
        //
        MAP_PinTypeADC(uiAdcInputPin,PIN_MODE_255);

        //
        // Convert pin number to channel number
        //
        switch(uiAdcInputPin)
        {
            case PIN_58:
                uiChannel = ADC_CH_1;
                break;
            case PIN_59:
                uiChannel = ADC_CH_2;
                break;
            case PIN_60:
                uiChannel = ADC_CH_3;
                break;
            default:
                break;
        }

        //
        // Configure ADC timer which is used to timestamp the ADC data samples
        //
        MAP_ADCTimerConfig(ADC_BASE,2^17);

        //
        // Enable ADC timer which is used to timestamp the ADC data samples
        //
        MAP_ADCTimerEnable(ADC_BASE);

        //
        // Enable ADC module
        //
        MAP_ADCEnable(ADC_BASE);

        //
        // Enable ADC channel
        //

        MAP_ADCChannelEnable(ADC_BASE, uiChannel);

        while(uiIndex <132)
        {
            if(MAP_ADCFIFOLvlGet(ADC_BASE, uiChannel))
            {
                ulSample = MAP_ADCFIFORead(ADC_BASE, uiChannel);
                pulAdcSamples[uiIndex++] = ulSample;
            }


        }

        MAP_ADCChannelDisable(ADC_BASE, uiChannel);

        uiIndex = 0;

        
        float output_voltage,temperature;
        UART_PRINT("\n\rVoltage is %f\n\r",((pulAdcSamples[4] >> 2 ) & 0x0FFF)*1.457/4096);
        output_voltage=((pulAdcSamples[4] >> 2 ) & 0x0FFF)*1.457/4096;
        temperature=output_voltage*100;
        UART_PRINT("\n\r temperature = %f",temperature);
        UART_PRINT("\n\r");

Thanks

  • Hi,

    Are you using the CC3200 launchpad, or are you using your own custom board?

    For the CC3200 ADC, some helpful advice can be found in this wiki page: http://processors.wiki.ti.com/index.php/CC3200_ADC_Appnote. I suggest you take a look if you haven't already, as it gives design tips as well as info on characteristics of the ADC.

    One important detail of the ADC to note is that it cannot read voltages above 1.4V. Usage of a resistor divider + capacitor scaling circuit is required if you are trying to measure higher voltages. Have you taken that into account?

    Your code looks correct on the ADC HW side, however your code displaying your voltage/temperature might have an issue. You are taking an int value in pulAdcSamples, then manipulating it into float without casting it as a float. In the latest v.1.4 of the CC3200 SDK, the ADC example has the following: 

    UART_PRINT("\n\rVoltage is %f\n\r",(((float)((pulAdcSamples[4+uiIndex] >> 2 ) & 0x0FFF))*1.4)/4096);

    If you cast to float like the example above, do you get the expected voltage values?

    Regards,

    Michael

  • Hi ,

    I am using both CC3200 Launchpad as well as my own custom board.

    I will use voltage divider circuit to reduce the voltage from +5v to +1.4V for ADC pins which will attach with LM35 sensor.

    Okay, I will do type cast to float and check.

    Is there anything else, I have to keep in my mind while reading the analog values and convert into the temperature?

    Thanks

  • Hi,

    The ADC appnote should have some additional considerations that you may want to take a look at, such as regarding droop correction that may apply to your system. 

    Regards,

    Michael

  • Hi,

    I assume that you have resolved your issue since I have not heard back from you. If not, feel free to post a response to this thread, or open a new thread regarding this issue.

    Regards,
    Michael