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