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.

How to setup max ADC sample rate for EK-TM4C1294XL

Other Parts Discussed in Thread: EK-TM4C1294XL, ENERGIA

Hi All

I am trying to raise ADC sample rate for EK-TM4C1294XL via followed codes

SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS); // setup the adc speed

SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); // enable the peripheral

but the ADC sample rate is aprox 10Ksps still

How to raise ADC sample rate?

Thank you

  • Hello Cosonaller,

    1. What is the configuration being done for the System Clock, and the ADCCC register?
    2. How are you triggering the parts and making measurements at the speed of conversion? If it is processor trigger then it needs to be changed to Always trigger mode.

    Regards
    Amit
  • Hello Amit,
    Firstly thank you very much for your instant message.
    I am trying use energia like arduino IDE, I'am so sorry, I can't answer your question because of I used to arduino due before and I don't need setup that value.
    I figure out easily that case via example code on http://www.djerickson.com/arduino/ as described below.

    REG_ADC_MR = (REG_ADC_MR & 0xFFF0FFFF) | 0x00020000;

    adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST);


    /* The normal adc startup time*/
    #define ADC_STARTUP_NORM 40
    /* The fast adc startup time*/
    #define ADC_STARTUP_FAST 12
  • eheh, i used Energia too. It can limit you allot if you want to take real advantage of your MCU power. Can i advise you to start programming the Tiva with CCS and TivaWare library? https://sites.google.com/site/luiselectronicprojects/tutorials/tiva-tutorials

    I will try to provide normal Energia configs:

    The system clock is configured like so EDIT had the wrong setup, didn't see it was a tm4c1294 instead of a tm4c123

        SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ|SYSCTL_OSC_MAIN|SYSCTL_USE_PLL|SYSCTL_CFG_VCO_480), F_CPU);

    This is how the ADC read is done, normally

    uint16_t analogRead(uint8_t pin) {
        uint8_t port = digitalPinToPort(pin);
        uint16_t value[1];
        uint32_t channel = digitalPinToADCIn(pin);
        if (channel == NOT_ON_ADC) { //invalid ADC pin
            return 0;
        }
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
        ROM_GPIOPinTypeADC((uint32_t) portBASERegister(port), digitalPinToBitMask(pin));
        ROM_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
        ROM_ADCSequenceStepConfigure(ADC0_BASE, 3, 0, channel | ADC_CTL_IE | ADC_CTL_END);
    	ROM_ADCHardwareOversampleConfigure(ADC0_BASE,0);
        ROM_ADCSequenceEnable(ADC0_BASE, 3);
    
        ROM_ADCIntClear(ADC0_BASE, 3);
        ROM_ADCProcessorTrigger(ADC0_BASE, 3);
        while(!ROM_ADCIntStatus(ADC0_BASE, 3, false)) {
        }
    	ROM_ADCIntClear(ADC0_BASE, 3);
        ROM_ADCSequenceDataGet(ADC0_BASE, 3, (unsigned long*) value);
        return value[0];
    }

  • Hello Cosonaller

    While Luis has a point on the use of Energia, you must know what the value are being set up for. Else the value ends up being a non-optimized value. Please check the address 0x400FE0B0, 0x400FE160-168 and send back the values. Similarly check the offset 0xFC8 in the ADC instance that is being set.

    Luis,

    Processor Trigger will not lead to maximum sampling rate due to inherent latency in the completion of first sample and triggering of the next sample

    Regards
    Amit
  • Hello everyone again,

    Thank you for this valuable information. I will be able to try on tomorrow and share their reason here.

    see you

  • Thank you Amit, pushing the ADC to the limit is still in my TODO list, so i really don't know much besides very basic use. Will have to probably check back here in the forum when i start using it more (i have been taking notes from other post thought)
  • Hello Luis Afonso (3615432)  and Amit Ashara (310847)  I'm trying the code and I were measure the reading speed. But speed is 8 us for 100 reading, still.

    #include "Energia.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/adc.h"
    unsigned long start_times[100];
    unsigned long stop_times[100];
    unsigned long values[100];
    void setup()
    {
       SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ|SYSCTL_OSC_MAIN|SYSCTL_USE_PLL|SYSCTL_CFG_VCO_480), F_CPU); 
    Serial.begin(9600);
    
    }
        
    void loop()
    {
     unsigned int i;
    
      // capture the values to memory
      for(i=0;i<100;i++) {
        start_times[i] = micros();
        values[i] = analogRead(2);
        stop_times[i] = micros();
      }
    
      // print out the results
      Serial.println("\n\n--- Results ---"); 
      for(i=0;i<100;i++) {
        Serial.print(values[i]);
        Serial.print(" elapse = ");
        Serial.print(stop_times[i] - start_times[i]);
        Serial.print(" us\n");
      }
      delay(6000);
    }
      uint16_t analogRead(uint8_t pin) {
        uint8_t port = digitalPinToPort(pin);
        uint16_t value[1];
        uint32_t channel = digitalPinToADCIn(pin);
        if (channel == NOT_ON_ADC) { //invalid ADC pin
            return 0;
        }
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
        ROM_GPIOPinTypeADC((uint32_t) portBASERegister(port), digitalPinToBitMask(pin));
        ROM_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
        ROM_ADCSequenceStepConfigure(ADC0_BASE, 3, 0, channel | ADC_CTL_IE | ADC_CTL_END);
        ROM_ADCHardwareOversampleConfigure(ADC0_BASE,0);
        ROM_ADCSequenceEnable(ADC0_BASE, 3);
    
        ROM_ADCIntClear(ADC0_BASE, 3);
        ROM_ADCProcessorTrigger(ADC0_BASE, 3);
        while(!ROM_ADCIntStatus(ADC0_BASE, 3, false)) {
        }
        ROM_ADCIntClear(ADC0_BASE, 3);
        ROM_ADCSequenceDataGet(ADC0_BASE, 3, (unsigned long*) value);
        return value[0];
    }

  • Hello Cosonaller

    I hope you have realized the mistake in the code. The code is not measuring the conversion time but the time from configuration of the ADC to the conversion and all over again. The actual code should have configured the ADC once and then just used the ADCProcessorTrigger to the data return. Even this will not give you the 1MSPS you desire as there is sufficient idle time after conversion on a/c of the code. Instead you should be putting in always trigger and when the while loop is false, toggle a gpio and go back to the while loop.

    The gpio toggle then can be monitored on a scope/LA

    Regards
    Amit