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.

CCS/TM4C1294NCPDT: TM4C1294 ADC sample problems

Part Number: TM4C1294NCPDT

Tool/software: Code Composer Studio

Hi together,

i want to convert 3 analog inputs over 1 sequencer with the following settings.

When I debug my code, than it look like I have a problem with the FIFO.

With the first Interrupt there were stored 3 values in the “adcBuffer2” variable. And in the next interrupts the adcBuffer2 stored 6 values. I don’t understand why this happened.

Have you any idears?

//
// Library Generals
//
#include "stdbool.h"
#include <stdio.h>
#include <stdint.h>

//
// Library TivaWare
//
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/adc.h"
#include "inc/tm4c1294ncpdt.h"
#include "inc/hw_memmap.h"

//
// Library own
//
#include "adc2.h"

//
// Globale Variablen
//
uint32_t adcBuffer2[30];
uint32_t adcGetValues;

//
// Interrupt Handler ADC0SS0
//
void ADC0IntHandler(void) {
	uint32_t test = 0;


	// Clear interrupt Flag
	ADCIntClear(ADC0_BASE, 0);

	ADCSequenceDataGet(ADC0_BASE, 0, adcBuffer2);


	adcGetValues=1;


}


void main(void) {

	adcGetValues=0;


	uint32_t sysclock_read=0;
	sysclock_read=SysCtlClockFreqSet(SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480, 120000000);
	printf("Systemclock is set to: %d\n", sysclock_read);

	// ADC Init
	adc2_init();


	IntPrioritySet(INT_ADC0SS0, 0x00);

	//
	// ADC0SS0 Interrupt source
	//
	ADCIntRegister(ADC0_BASE, 0, ADC0IntHandler);

	//
	// Register Interrupt to NVIC
	//
	IntRegister(INT_ADC0SS0, ADC0IntHandler);

	//
	// ADC0 enable
	//
	ADCIntEnable(ADC0_BASE, 0);



	//
	// Interrupt ADC0SS0 enable
	//
	IntEnable(INT_ADC0SS0);

	//
	// Enable Global Interrupts
	//
	IntMasterEnable();

	//
	// Sequencer enable
	//
	ADCSequenceEnable(ADC0_BASE, 0);

	while(1){


		if (adcGetValues==1) {
			ADCSequenceDisable(ADC0_BASE, 0);
			ADCIntDisable(ADC0_BASE, 0);
			IntDisable(INT_ADC0SS0);

			//ADCSequenceDisable(ADC0_BASE, 0);


/*
			printf("ADC Value1: %d\n", adcBuffer2[0]);
			printf("ADC Value2: %d\n", adcBuffer2[1]);
			printf("ADC Value3: %d\n", adcBuffer2[2]);
*/
			adcGetValues = 0;

			ADCIntEnable(ADC0_BASE, 0);
			IntEnable(INT_ADC0SS0);
			ADCSequenceEnable(ADC0_BASE, 0);


		}


	}

}

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>

#include "inc/tm4c1294ncpdt.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/comp.h"

#include "func.h"



adc2_init(){

	uint32_t adcClock=0, adcDiv=0;

	//
	// Enable the ADC0 peripheral
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); wait();

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); wait();
	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

	//
	// Configure the ADC to use PLL at 480 MHz with Full rate devided by 30 to get 16 MHz
	//
	ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PLL | ADC_CLOCK_RATE_FULL, 30);

	ADCSequenceDisable(ADC0_BASE, 0);

	//
	// Read the current ADC configuration
	//
	adcClock=ADCClockConfigGet(ADC0_BASE, &adcDiv);
	printf("ADC clock is: 0x%x, div: 0x%x\n", adcClock, adcDiv);

	//
	// Hardware averageing: by a faktor of 2 -> 2,4,8,16,32,64
	//
	ADCHardwareOversampleConfigure(ADC0_BASE, 0);

	//
	// ADC voltage-lvl reference set to intern
	//
	ADCReferenceSet(ADC0_BASE, ADC_REF_INT);

	//
	// ADC Sequencer config: Source ADC0, Sequencer 0, Trigger: always, priority: 0
	//
	ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_ALWAYS, 0);

	//
	// ADC Sequencer step
	// 1. Source-ADC -> ADC0_BASE
	// 2. Source-Sequencer -> 0
	// 3. Sample-Value depends in the depth of the FIFO, by Sequencer 0 it is up to 7 (0-7)
	// 4. Config-> select input-channel AINx, interrupt specification
	//
	ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
	ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1);
	ADCSequenceStepConfigure(ADC0_BASE, 0, 2, (ADC_CTL_CH2 | ADC_CTL_IE | ADC_CTL_END));

}

  • Well, this order cannot be correct. You've enabled the interrupt source before you've initialized and enabled the interrupt.

    xenon185 said:
    // ADC Init adc2_init(); IntPrioritySet(INT_ADC0SS0, 0x00); // // ADC0SS0 Interrupt source // ADCIntRegister(ADC0_BASE, 0, ADC0IntHandler); // // Register Interrupt to NVIC // IntRegister(INT_ADC0SS0, ADC0IntHandler); // // ADC0 enable // ADCIntEnable(ADC0_BASE, 0); // // Interrupt ADC0SS0 enable // IntEnable(INT_ADC0SS0);

    Robert

    BTW, neither idear nor idears is a word. The word you meant to use was probably ideas.

  • Thanks for your reply. 

    Now I changed the order too your explanation. 

    But my problem with more data into the buffer then steps still exists. When i  debug the code see in the picture above.

    
    
    //
    // Interrupt ADC0SS0 enable
    //
    IntEnable(INT_ADC0SS0);
    
    //
    // ADC0 enable
    //
    ADCIntEnable(ADC0_BASE, 0);

    i wish your all a very happy christmas time.

  • I am not sure, but suspect that it has to do with configuring the sequence to trigger always and then disabling and re-enabling the sequence. By the time to disable the sequence after the first three samples have been taken, the ADC has been triggered to start another three samples. You disable the sequence, but it was already started. So I think when you re-enable the sequence, you get then three more samples, which gives six samples in the buffer.

    Consider setting the sequence to "ADC_TRIGGER_PROCESSOR" and then call the function ADCProcessorTrigger() each time you are ready to take three more samples. You will not need to disable and re-enable the sequence.