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.

Tiva TM4C123G ADC Setup hangs

Expert 1030 points
Other Parts Discussed in Thread: TM4C123GH6PM

Hi. I've been trying to get my tiva's adc setup, but while stepping through the code it hangs and loops endlessly in FaultISR() when it gets to a certain point, viz., any function/routine that starts with ADC...(). The relevant code is as follows:

	/*
	 * Setup PortE
	 * APB 0x4002:4000
	 * AHB 0x4005:C000
	 */
	if (SysCtlPeripheralPresent(SYSCTL_PERIPH_GPIOE)) {
	  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);  // ADC for Vin  and Batt monitor
	  GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, (GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3));	//
	  GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, (GPIO_PIN_0 | GPIO_PIN_4 | GPIO_PIN_5));	//
		if (SysCtlPeripheralPresent(SYSCTL_PERIPH_ADC0)) {
			SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	    GPIOPadConfigSet(GPIO_PORTE_BASE, (GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_ANALOG);
	    GPIOPinTypeADC(GPIO_PORTE_BASE, (GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3));	//
		  ADCClockConfigSet(ADC0_BASE, (ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_HALF), 1);
	    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
	    //ADCSequenceStepConfigure(ADC0_BASE, 0, 0, (ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH0));
	    //ADCIntClear(ADC0_BASE);
		  //ADCIntRegister(ADC0_BASE, 0x0000, ADC0IntHandler);
	    //ADCSequenceEnable(ADC0_BASE, 0);
	    //ADCProcessorTrigger(ADC0_BASE, 0);
		}
		if (SysCtlPeripheralPresent(SYSCTL_PERIPH_PWM0)) {
			SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
		  GPIOPinConfigure(GPIO_PE4_M0PWM4);
		  GPIOPinConfigure(GPIO_PE5_M0PWM5);
	    //GPIOPinTypePWM(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5);	//
		}
	}

My clock setup, if it's relevant, is as follows:

    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);

I have noticed that while every other function name, eg., SysCtlPeripheralPresent(), is highlighted in some purplish color, the ones beginning with ADC are not, eg., ADCClockConfigSet(). I'm using CCS6, by-the-way. I have included adc.h and the code does compile without errors or warnings.

This is my first attempt at programming a tiva and I'm not sure if some of the function calls are redundant.

Thanks for any help.

  • Hi halo,

    What frequency are you trying to achieve? You are using SYSCTL_USE_OSC , this if i am not mistaken makes it so your clock is just the external crystal. Your external is 8Mhz? The ADC needs at leas 16Mhz to work (check page 221 in the datasheet)

    Try using 

     SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);

    This will configure the clock to 200Mhz/2.5=80MHz

     

    If you are new to Tiva check this out: https://sites.google.com/site/luiselectronicprojects/tutorials/tiva-tutorials

  • Hello Halo,

    1. The ADC cannot work when the system clock is less than the System Clock. This is specifically mentioned in the data sheet. It will not however create a bus fault.

    2. In most likelihood the FAULT is being triggered by the Peripheral being accessed after being enabled. Might I suggest putting a SysCtlDelay(10)

    If it still goes to FAULT ISR, please have a look at the FAULTSTAT and FAULTADDR register at address 0xE000ED28 and 0xE000ED38

    Regards

    Amit

  • Hi Luis and Amit,

    I thought that, since the ADC clock is using the PIOSC which is 16MHz, using it for the ADC while the main oscillator is 8Mhz would be all-right. I'll try your suggestion of introducing a delay and looking at 0xE000ED38. I'll get back to you.

  • Hi Amit. I've looked at the clock diagram, Fig 5-5 on page 222 of the document DS-TM4C123GH6PM-15842.2741 (SPMS376E), and it seems to me that the PIOSC can be used as the ADC clock if the ADCCC register field is properly set. Is this not correct?

    By the way, I have also found that the constant ADC_CTL_VREF_M in hw_adc.h (line 416) is defined differently from what it is in tm4c123gh6pm.h (line 5461). I believe that the latter version is correct (page 850 of tm4c123gh6pm.pdf).

    Thanks for your help.

  • Actually, you're right. I see in section 13.3.2.6 on page 806 of tm4c123gh6pm.pdf that to use the PIOSC for the ADC  you first need to turn on the PLL. So, given that I have an 8 MHz XTAL that I want to use to clock the PLL, how do I go about it? I'm going to have to look at SysCtlClockSet() more closely. Regards, Harry.

  • Hello Halo,

    The following API call will give you the 80MHz system clock from the PLL and 8MHz crystal

        SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_8MHZ);

    Regards

    Amit