Part Number: EK-TM4C1294XL
Tool/software: Code Composer Studio
I think there is a bug when reading internal sensor or something missing.
if anyone help, we can fix this.
if i set the GPIO_PORTE_BASE, GPIO_PIN_3 to HIGH before initializing internal temperature sensor, everything is good , reading temperature as expected.
But, if not set, there is a difference reading analog values between set or not set.
You can see the following source code.
How can we fix this ?
/*
* hal_adc.c
*
* Created on: 9 May 2016
* Author: selami
*/
#include <hal_adc_0.h>
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_generictypes.h"
#include "inc/hw_memmap.h"
#include "inc/hw_ints.h"
#include "inc/hw_gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/adc.h"
#include "driverlib/sysctl.h"
//*****************************************************************************
//
// This is the data acquisition module. It performs acquisition of data from
// selected channels, starting and stopping data logging, storing acquired
// data.
//
// PINS -- >> E3 AIN0
//*****************************************************************************
void internal_TemperatureSensorInit(void)
{
//
// The ADC0 peripheral must be enabled for use.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralReset(SYSCTL_PERIPH_ADC0);
//
// Enable sample sequence 3 with a processor signal trigger. Sequence 3
// will do a single sample when the processor sends a singal to start the
// conversion. Each ADC module has 4 programmable sequences, sequence 0
// to sequence 3. This example is arbitrarily using sequence 3.
//
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
//
// Configure step 0 on sequence 3. Sample the temperature sensor
// (ADC_CTL_TS) and configure the interrupt flag (ADC_CTL_IE) to be set
// when the sample is done. Tell the ADC logic that this is the last
// conversion on sequence 3 (ADC_CTL_END). Sequence 3 has only one
// programmable step. Sequence 1 and 2 have 4 steps, and sequence 0 has
// 8 programmable steps. Since we are only doing a single conversion using
// sequence 3 we will only configure step 0. For more information on the
// ADC sequences and steps, reference the datasheet.
//
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_TS | ADC_CTL_IE |
ADC_CTL_END);
//
// Since sample sequence 3 is now configured, it must be enabled.
//
ADCSequenceEnable(ADC0_BASE, 3);
//
// Clear the interrupt status flag. This is done to make sure the
// interrupt flag is cleared before we sample.
//
ADCIntClear(ADC0_BASE, 3);
}
float internal_TemperatureSensorRead(void)
{
//
// These variables are used to store the temperature conversions for
// Celsius and Fahrenheit.
//
float Vtens;
//
// This array is used for storing the data read from the ADC FIFO. It
// must be as large as the FIFO for the sequencer in use. This example
// uses sequence 3 which has a FIFO depth of 1. If another sequence
// was used with a deeper FIFO, then the array size must be changed.
//
uint32_t pui32ADC0Value[1];
//
// These variables are used to store the temperature conversions for
// Celsius and Fahrenheit.
//
static float fTempValueC = 0;
static float fTempValueF;
float TempValueC;
//
// Trigger the ADC conversion.
//
ADCProcessorTrigger(ADC0_BASE, 3);
//
// Wait for conversion to be completed.
//
while(!ADCIntStatus(ADC0_BASE, 3, false))
{
}
//
// Clear the ADC interrupt flag.
//
ADCIntClear(ADC0_BASE, 3);
//
// Read ADC Value.
//
ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value);
Vtens = (float)( ((float )pui32ADC0Value[0] * 3.3) / 4096);
//
// Use non-calibrated conversion provided in the data sheet. Make
// sure you divide last to avoid dropout.
//
// TEMP = 75*(2.7 - VTSENS) - 55
TempValueC = 75 * (2.7 - Vtens) - 55;
//filter
fTempValueC = fTempValueC + (TempValueC - fTempValueC) * 0.25;
return fTempValueC;
}
void test_Internal_Temperature()
{
GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_3);
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_3, GPIO_PIN_3);
internal_TemperatureSensorInit();
while(1)
{
internal_TemperatureSensorRead();
}
}

