My temperature sensor values are very unreliable (these are the temp values I am getting):
Temperature: 30.0
Temperature: 30.21
Temperature: 32.59
Temperature: 32.16
Temperature: 27.83
Temperature: 28.48
Temperature: 31.72
Temperature: 28.91
Temperature: 32.59
Temperature: 28.91
Temperature: 32.8
Temperature: 28.48
Temperature: 30.0
Temperature: 28.05
Temperature: 28.05
Temperature: 30.21
Temperature: 27.83
Temperature: 30.86
Temperature: 29.78
Temperature: 33.02
Temperature: 31.29
Temperature: 30.43
Temperature: 32.8
Temperature: 28.48
Temperature: 29.78
Temperature: 32.37
Temperature: 28.27
Temperature: 30.86
Temperature: 31.29
Temperature: 30.43
Temperature: 30.64
Temperature: 30.21
Temperature: 29.56
Temperature: 29.13
Temperature: 28.7
Temperature: 27.83
Temperature: 28.05
Temperature: 33.24
Temperature: 30.64
Temperature: 30.0
Temperature: 32.59
Temperature: 27.62
Temperature: 29.56
Temperature: 29.13
Temperature: 31.51
Temperature: 28.05
Temperature: 27.83
Temperature: 29.13
Temperature: 29.56
Temperature: 27.62
As you can see the temperature sensor values jump around like crazy. I have tried many solutions from increasing my sample and hold time, changing the clock, decreasing sample hold time, staying awake the whole time rather than going into LPM3 mode. Ive looked at all the sample code and still no luck. With the same exact code, the dev board performs 10x better with the temp sensor accuracy below 1 degC. Is there a reason for the temp sensor being so unreliable? Below is my code that I am using.
// Convert the temperature to degrees C
void ConvertTempToDegC()
{
DegC = (CurrentTemperature - ((float) (CALADC_25V_30C))) * CAL_TEMP_BITS_PER_C + 30;
I2C.Temp = DegC * 100;
}
// Adjust the bias based on temperature if enabled
void AdjustTemperatureBias()
{
ConvertTempToDegC();
if (I2C.Control.TemperatureEnable) {
SetTempBiasAdjustment();
}
}
// Soft Start Analog Pin Configuration
void SoftStartInit(void)
{
P1SEL0 |= BIT1;
P1SEL1 |= BIT1;
SAC0DAC = DACSREF_1; // Select int Vref as DAC reference
SAC0DAT = 0x00;
SAC0DAC |= DACEN; // Enable DAC
SAC0OA = NMUXEN + PMUXEN + PSEL_1 + NSEL_1; //Select positive and negative pin input
SAC0OA |= OAPM; // Select low speed and low power mode
SAC0PGA = MSEL_1; // Set OA as buffer mode
SAC0OA |= SACEN + OAEN; // Enable SAC and OA
}
// Timer Configuration
void TimerInit(void)
{
TB0CCTL0 |= CCIE; // TBCCR0 interrupt enabled
TB0CCR0 = 65535/20;
TB0CTL = TBSSEL__ACLK | MC__UP; // ACLK, UP mode
}
// Temperature/ADC Configuration
void TemperatureInit(void)
{
// Configure ADC - Pulse sample mode; ADCSC trigger
ADCCTL0 |= ADCSHT_8 | ADCON; // ADC ON,temperature sample period>30us
ADCCTL1 |= ADCSHP | ADCSSEL0; // s/w trig, single ch/conv, MODOSC
ADCCTL2 &= ~ADCRES; // clear ADCRES in ADCCTL
ADCCTL2 |= ADCRES_2; // 12-bit conversion results
ADCMCTL0 |= ADCSREF_1 | ADCINCH_12; // ADC input ch A12 => temp sense
ADCIE |=ADCIE0; // Enable the Interrupt request for a completed ADC_B conversion
CAL_TEMP_BITS_PER_C = ((float) (105 - 30)) / ((float) (CALADC_25V_105C - CALADC_25V_30C));
}
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
// Configure one FRAM waitstate as required by the device datasheet for MCLK
// operation beyond 8MHz _before_ configuring the clock system.
FRCTL0 = FRCTLPW | NWAITS_1;
__bis_SR_register(SCG0); // disable FLL
CSCTL3 |= SELREF__REFOCLK; // Set REFO as FLL reference source
CSCTL1 = DCOFTRIMEN_1 | DCOFTRIM0 | DCOFTRIM1 | DCORSEL_5;// DCOFTRIM=5, DCO Range = 16MHz
CSCTL2 = FLLD_0 + 121; // DCOCLKDIV = 4MHz
__delay_cycles(3);
__bic_SR_register(SCG0); // enable FLL
CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK; // set default REFO(~32768Hz) as ACLK source, ACLK = 32768Hz
// default DCOCLKDIV as MCLK and SMCLK source
SoftStartInit();
TimerInit();
TemperatureInit();
PMMCTL0_H = PMMPW_H; // Unlock the PMM registers
PMMCTL2 = INTREFEN | REFVSEL_2 | TSENSOREN; // Enable internal 2.5V reference
while(!(PMMCTL2 & REFGENRDY)){}; // Poll till internal reference settles
TI_USCI_I2C_slaveinit(start_cb, transmit_cb, receive_cb, 0x48); // init the slave
PM5CTL0 &= ~LOCKLPM5;
__bis_SR_register(LPM3_bits | GIE); // go into low power mode
while(1) {
if (WakeReason.TimerB) {
AdjustTemperatureBias();
WakeReason.TimerB = 0;
}
__bis_SR_register(LPM0_bits); // go into low power mode
}
}