Hi all,
I am using MSP430F5872. In this, I am trying to read the internal temperature sensor value from ADC12 channel 30
Queries:
1)My first query is whether this channel number is right?. If No then which is correct channel number to read internal temperature value.
2)On what basis we should select Internal Voltage Reference and with respect to it what should be the calibration value?
3)I am not able to read the correct value from this channel. Apart from this, I am reading ADC channel 12 with the external reference voltage 3.3V which is providing me correct value.
Below is my code.
#define CALADC12_12V_30C *((unsigned int *)0x1A1A) // Temperature Sensor Calibration-30 C
#define CALADC12_12V_85C *((unsigned int *)0x1A1C) // Temperature Sensor Calibration-85 C
void ADC_config()
{
ADC12CTL0 &= (~ADC12ENC); // disable ADC conversion
while(REFCTL0 & REFGENBUSY); // If ref generator busy, WAIT
REFCTL0 |= REFVSEL_0 | REFON; // Select internal ref = AVcc & Internal Reference ON
ADC12MEM0 = 0;
ADC12CTL0 = ADC12SHT0_2 | ADC12ON;
ADC12CTL1 = ADC12SHP; // ADCCLK = MODOSC; sampling timer
ADC12CTL2 |= ADC12RES_2; // conversion results will in 12-bit
ADC12IER0 |= ADC12IE0;
ADC12CTL3 = ADC12TCMAP;
ADC12MCTL0 = ADC12VRSEL_1 + ADC12INCH_30;
ADC12MCTL0_H |= 0x00;
while(!(REFCTL0 & REFGENRDY)); // Wait for reference generator to settle
ADC12CTL0 |= ADC12ENC | ADC12SC; // Sampling and conversion start
__bis_SR_register(LPM0_bits + GIE) ; // LPM0, ADC10_ISR
}
void start_adc()
{
do
{
ADC12CTL0 |= ADC12ENC | ADC12SC; // Sampling and conversion start
}while(0);
}
uint32_t read_temp(void)
{
start_adc();
temperatureDegC = (u32AdcValue- CALADC12_12V_30C) * (85 - 30)) /(CALADC12_12V_85C - CALADC12_12V_30C) + 30;
return temperatureDegC;
}
/*******************************ADC Interrupt(ISR)*****************************/
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch (__even_in_range(ADC12IV, ADC12IV_ADC12RDYIFG))
{
case ADC12IV_NONE: break; // Vector 0: No interrupt
case ADC12IV_ADC12OVIFG: break; // Vector 2: ADC12MEMx Overflow
case ADC12IV_ADC12TOVIFG: break; // Vector 4: Conversion time overflow
case ADC12IV_ADC12HIIFG: break; // Vector 6: ADC12BHI
case ADC12IV_ADC12LOIFG: break; // Vector 8: ADC12BLO
case ADC12IV_ADC12INIFG: break; // Vector 10: ADC12BIN
case ADC12IV_ADC12IFG0: // Vector 12: ADC12MEM0 Interrupt
/***************Action on ADC********************/
u8adcconversiondone_g=TRUE;
u32AdcValue = ADC12MEM0;
__bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
break; // Clear CPUOFF bit from 0(SR)
case ADC12IV_ADC12RDYIFG: break; // Vector 76: ADC12RDY
default: break;
}
}
Please suggest a solution to my problem.
Thanks In Advance.