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.

Problem on ADC TM4C1294



Hello,

I'm having some problemson the ADC of TM4C1294

The ADC can not go to the interrupt, I have tested many times. I considered many codes on this forum and followed them. I also changed the sequence from 0 to 3 and ADC0 to ADC1. However, the ADC's interrupt didn't occur.

May be I could be lacked anywhere. Can anybody help me with this. Thanks so much.

In the startup file:

    ADC0SS3IntHandler,                      // ADC Sequence 3

Here is my code:


#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/adc.h"
#include "driverlib/rom.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"

#include "driverlib/uart.h"
#include "utils/uartstdio.h"

void ADC0SS3IntHandler(void);
// ****** Variables ******
uint32_t ADC0Value[1];

// Definitions
void
ConfigureUART(void)
{
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	GPIOPinTypeUART(GPIO_PORTA_BASE,GPIO_PIN_0|GPIO_PIN_1);
	UARTConfigSetExpClk(UART0_BASE,16000000,115200,(UART_CONFIG_WLEN_8| UART_CONFIG_STOP_ONE|UART_CONFIG_PAR_NONE));

	UARTStdioConfig(0,115200,16000000);
}
void systemSetup(void){
    // *** Clock
    SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

    // *** Peripheral Enable
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlDelay(10);

    // *** ADC0
    ADCSequenceConfigure(ADC0_BASE,3,ADC_TRIGGER_PROCESSOR,0);
    ADCSequenceStepConfigure(ADC0_BASE,3,0,ADC_CTL_CH0|ADC_CTL_IE|ADC_CTL_END);
    ADCSequenceEnable(ADC0_BASE,3);
    ADCIntRegister(ADC0_BASE,3,&ADC0SS3IntHandler);
    // *** GPIO
    GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_3);

    // *** Interrupts
    IntEnable(INT_ADC0SS3);
    ADCIntEnable(ADC0_BASE,3);
    IntMasterEnable();
}

// Main program
int main(void) {
    systemSetup();
    ConfigureUART();
	  UARTprintf("connected");
    while(1){

    	ADCProcessorTrigger(ADC0_BASE,3);
        UARTprintf("trigger ok \n\r");
    	SysCtlDelay(160000);
    }
}

// Interrupts
void ADC0SS3IntHandler(void){
    ADCIntClear(ADC0_BASE,3);
    UARTprintf("having interrupt \n\r");
    ADCSequenceDataGet(ADC0_BASE,3,ADC0Value); // Get Data from ADC and store it in ADC0Value
    if (ADC0Value[0] > 0) UARTprintf("having connect\n\r");

}

  • Mr Phu said:
    ADCIntRegister(ADC0_BASE,3,&ADC0SS3IntHandler);

    Try without the "&"

    - kel

  • Hi Markel Robregado,
    Thanks for your reply.
    However, It still does not go to the interrupt.

    -Phu
  • Hello Mr,

    The function SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); is not meant for TM4C129. The equivalent function for TM4C129 is SysCtlClockFreqSet. Also if you are using the EK or DK for TM4C129 then the crystal is 25MHz.

    Regards
    Amit
  • Hi Amit,

    Thanks for your reply.

    I used it (16MHz clock) for other projects but it seems to be work well (only not working on ADC peripheral). So I can not understand how it wrong. I'm using EK series.

    I see: "The Connected LaunchPad uses a 25 MHz crystal (Y1) to drive the main TM4C1294NCPDTI internal clock circuit". May be that means I can not use 16MHz for this chip.

    I'm working with self balance scooter project. Which clock frequency should I use?

    Another question is: when I use SysCtlClockFreqSet, Does system clock can be set?

    I will try with yours and reply soon.

    Thanks so much,

    -Phu

  • Hello Phu,

    Since the connected launchpad has 25Mhz crystal, using 16MHz is not valid. You will realize this the moment you use the PLL with Main Oscillator which will end up locking the device due to over clocking. Please read through the comments for SysCtlClockFreqSet and TivaWare API documentation as to why this must be used for TM4C129.

    I can't say what frequency to use as that is up-to your code and application.

    Now in the original code, when you run the same what happens?

    Regards
    Amit
  • Hello Amit,

    That's a big problem of me. I did not consider clearly the user's guide and worked with tiva by the same way with msp430.

    Thanks for solved it. I will repair my old projects.

    One more, thanks so much Amit.

    -Phu
  • Hello Phu,

    So did it solve the issue or not?

    Regards
    Amit
  • Amit,

    It has been working very well but there was some noises. The smallest value is ~30 and the highest value is ~4034.

    I'm thinking about how to solve it. I got 10 values and divided the sum to 10 but no efficiency.

    -Phu

  • Hello Phu,

    You need to keep the input constant to make sure that the value being measured can be quantified for noise. What is the source that you are sampling? The total input impedance must not exceed 500Ohms. If it exists then you need to update the Sample and Hold register to increase the sampling time for the input signal.

    Regards
    Amit
  • Hi Amit,

    I'm using a volume resistor 5K Ohm (potentionmeter) as the input of ADC. It is supplied by 3,3V source on chip.

    Do you have any idea for me to solve the noises? I need to read correctly. 

    Thanks,

    -Phu.

  • Hello Phu,

    First of all you would need to enable the sample and hold circuit using the ADCSSTH register. Then as I suggested apply a DC voltage via the pot to see what is reading range. If the range has a lot of large excursions then you would need to consider isolating the analog from nearby noise source like clock and high speed lines.

    Regards
    Amit