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.

ADC TM4C123GH6PM

Other Parts Discussed in Thread: TM4C123GH6PM

Hi,

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"				// HEADER FILES
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"


uint32_t ui32ADC0Value[4];			// TO STORE THE VALUE IN VARIABLE ui32ADC0Value FOR EVERY SAMPLING
volatile uint32_t ui32TempAvg;		// AVERAGE VALUE OF SAMPLED SIGNAL WILL BE STORE IN VARIABLE ui32TempAvg
volatile uint32_t ui32TempValueC;
volatile uint32_t ui32TempValueF;

int main(void)
{

	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); // SYSTEM CLOCK AT 40MHZ

	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);			// ENABLE ADC0 MODULE

	ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); 	// ADC0 MODULE, TRIGGER IS PROCESSOR EVENT, SEQUENCER 0 IS CONFIGURED
	ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);			// ADC0 MODULE, SEQUENCER 0 , FOR 1 SAMPLING, INPUT IS INTERNAL TERMPERATURE SENSOR
	ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);			// ADC0 MODULE, SEQUENCER 0 , FOR 2 SAMPLING, INPUT IS INTERNAL TERMPERATURE SENSOR
	ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);			// ADC0 MODULE, SEQUENCER 0 , FOR 3 SAMPLING, INPUT IS INTERNAL TERMPERATURE SENSOR
	ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);	// ADC0 MODULE, SEQUENCER 0 , FOR 4 SAMPLING,INPUT IS INTERNAL TERMPERATURE SOR,
																	

			//	AND TO DENOTE THAT THIS IS LAST SAMPLING CONVERSIONA AND INTERRUPT IS ENABLED, TO DENOTE THE CONVERSION IS OVER OR NOT
	ADCSequenceEnable(ADC0_BASE, 1);								// ENABLE THE SEQUENCE 1 FOR ADC0

	while(1)
	{
	   ADCIntClear(ADC0_BASE, 1);									// CLEAR INTERRUPT FLAG FOR ADC0, SEQUENCER 1
	   ADCProcessorTrigger(ADC0_BASE, 1);							// TRIGGER IS GIVEN FOR ADC 0 MODULE,SEQUENCER 1

	   while(!ADCIntStatus(ADC0_BASE, 1, false))					// CHECK WHETHER THE CONVERSION IS OVER OR NOT
	   {
	   }

	   ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);				// STORE THE CONVERTED VALUE FOR ALL DIFFERENT SAMPLING IN ARRAY ui32ADC0Value
	   ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3])/4; // TAKING THE AVERAGE
	   ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;		// CONVERSION FOR CELSIUS
	   ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;				// CONVERSION FOR FAHRENHEIT
	}
}

I have doubt in the above code : 

1) Is it possible to get the ADC value without enabling interrupt ? (ADC_CTL_IE)

2)  ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);     - This line denotes that the input signal is sampled once ??? is it correct.

Need a explanation for the lines below

ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
  • Hello Haresh

    Yes, it is required to set the ADC_CTL_IE so that the ADCRIS bit gets set. However setting the ADC_CTL_IE does not mean that an interrupt will be generated. That will happen only when the ADCIM is set and also the NVIC is enabled for acknowledging the Interrupt from ADC.

    Every sequencer has a defined number of steps. In case of Sequencer-1 it is 4. Each step is one sample and as you mentioned that it will sampled once. In the mentioned lines, the ADC0 Sequencer 1 is configured for ADC conversion when the processor writes to the ADCPSSI register for the specific sequencer. When it is written the Sequencer shall convert the Temp Sense value 4 times, give an interrupt and stop for the next trigger.

    Regards
    Amit
  • Hi Amit,

    ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS); -> this lines denotes ADC0, Sequencer1 , sampling will be 2 ???

    ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS); -> this lines denotes ADC0, Sequencer1 , sampling will be 3 ???

    ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_TS); -> this lines denotes ADC0, Sequencer1 , sampling will be 4 ???
  • Hello Haresh,

    Yes, that is correct. That would be the order as well of sampling and read out from the FIFO. Also the last sample must have the END bit set.

    Regards
    Amit
  • Hi,

    I need to give 5v input to a analog pin in TIVA TM4C123GH6PM, but in the datasheet it was given as 3.3V as the input supply.

    So, what is the procedure to give a analog input more than 3.3 V ? 

  •  use a clipper circuit like this one but instead of giving 5 volt at the positive side of the diode give 3.3volt

    Use High speed diodes if u r analog signal is of frequency more than 1 Mhz

  • Hello Hareesh,

    The Vref for conversion can only be upto 3.3V. You would need to have a voltage divider (do follow it up with op-amp buffer) to scale the 5V to 3.3V range.

    Regards
    Amit
  • Hi Amit,

    So for one of my applications I have a signal conditioning citcuit giving an O/P in the range of 0-5V. The datasheet says the gpio pins are tolerant to 5V and the adc block has a 5V clamp. So I can directly connect the signal to the adc pin right? ( I don't mind the readings saturating beyond 3.3V). I just want to clarify this whether I am correct before I design the PCB.

    Regards,

    Shitij Avlani

  • Hi Shitij Avlani,

    Yes the GPIO are tolerant to 5V but the ADC isn't only the GPIO module is Tolerant to 5V. Giving 5V to ADC may damage the ADC. So its better to implement a simple Clipping Circuit.

    Regards
  • Shitij Avlani said:
    So for one of my applications I have a signal conditioning citcuit giving an O/P in the range of 0-5V.

    Is the signal conditioning circuit with an O/P in the range 0-5V the only analogue input used?

    The reason for asking is that the description of the GPIO Analog Mode Select (GPIOAMSEL) register in the TM4C123GH6PM datasheet says:

    The GPIOAMSEL register controls isolation circuits to the analog side of a unified I/O pad. Because the GPIOs may be driven by a 5-V source and affect analog operation, analog circuitry requires isolation from the pins when they are not used in their analog function

    And section 10.1 Signal Description says:

    The AINx analog signals have internal circuitry to protect them from voltages over VDD (up to the maximum specified in Table 24-1 on page 1358), but analog performance specifications are only guaranteed if the input signal swing at the I/O pad is kept inside the range 0 V < VIN < VDD.

    i.e. if the signal conditioning circuit outputs 5V on one AINx analog input, other analog inputs may not perform to specification.

  • Basically I Have designed an ECG AFE. Due to certain mistakes in procurement, the opamps we purchased cant operate at 3.3V so my signal output range is 0-5V. I cant replace these opamps since they are very expensive, as they have no meet the CMRR, voltage offset and noise specifications. I have eight such channels that need to be sampled. There is no other analog input so all are in the 0-5 range.
    When the data sheet mentions performance specifications will not be guaranteed, what does it encompass? Will accuracy, linearity and sensitivity remain the same? If not what shall be the variation?

  • Shitij Avlani said:
    When the data sheet mentions performance specifications will not be guaranteed, what does it encompass?

    Based upon the available information in the datasheet it is not clear what the performance impact will be. Hopefully someone from TI will be able to give a definitive answer.

  • I forgot to mention this but I have adjusted the gain such that the signal remains between 0-3.3V. It only crosses 3.3V when the electrodes are connected, disconnected or adjusted due to the filter time constants and remains there for no more than a few seconds. under normal operation where the readings are of value the signal remains between 0-3.3V. In that case the adc performance shouldn't change right? My reason for asking this question was whether that occasional saturation of the signal to 5V would harm the microcontroller in any way. So in your opinion should there be any issue, even with the adc performance?
  • Shitij Avlani said:
    under normal operation where the readings are of value the signal remains between 0-3.3V. In that case the adc performance shouldn't change right?

    Agreed that the ADC performance shouldn't change while the signals remains between 0-3.3V.

    Shitij Avlani said:
    My reason for asking this question was whether that occasional saturation of the signal to 5V would harm the microcontroller in any way.

    The analog inputs are documented as 5V tolerant. The only limitation is that if 5V is applied to an input while Vdd is not present, such a condition should be limited to a maximum of 5000 hours (at 27C) or 10000 hours (at 85C) over the lifetime of the device. 

  • Thank you so much for your help