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/EK-TM4C123GXL: Improving execution time performance in code composer studio code

Part Number: EK-TM4C123GXL

Tool/software: Code Composer Studio

Hello, I have a question regarding how to improve execution time performance in Code Composer Studio code.

First, some background information on this project.

  1. My teammates and I are trying to create a microcontroller-based device that can cross-correlate two signals together.
  2. We are cross-correlating an array filled with data from the ADC with an array created through software (called the analyzing array).
  3. Each array is 4096 elements large.

The problem is that execution times are very poor for the cross-correlation, taking up to a minute and a half to complete a cross-correlation operation. My team and I have tried various fixes, to no effect.

  • We tried reducing the magnitude of the values inside the ADC data array. In other words, we tried reducing the value in each array element from 2500 down to about 50. This did not affect the run time.
  • The ADC data array holds unsigned 16 bit integers (uint16_t). I thought that this might be an issue, so I cross-correlated the analyzing and data arrays together, with both arrays created through software. With the data array holding 16 bit integers and the analyzing array holding 8 bit integers, the cross-correlation was successfully completed in just a few seconds. So, the array data types do not seem to affect the run time.
  • I have set the optimization level to whole program optimizations.

Are there methods for improving this execution time? Are there problems with the ADC that might slow down the microcontroller?

  • HI,

      I don't think there is enough information to comment on your problem. I have a few questions:

      - What is your ADC sampling rate? 1MSPS? Check and make sure you sample at 1MPS. 

      - How many ADC channels are you sampling?

      - Which Sequencer do you use?

      - Are you using ADC interrupt mode or polling mode? I will suggest you use interrupt mode. If you use polling mode then while you are polling then how would you process your analyzing array?

      - Are you using DMA or not? I will suggest you use DMA so the CPU is not intervened.

      - Can you only fill your data array (4096 elements) from the ADC only and measure the time? Don't do any analyzing array. This will give us a clue as to how long it take for the ADC to fill your 4096 buffer. You said it takes a minute and a half to correlate between the two arrays. If the measured time of your data array is significantly shorter than 1 minute and half then you want to investigate your code how you synchronize between the two arrays.

  • Thanks for getting back to me.

    1. The sampling rate of the ADC is set to 333 kS/s instead of the Tiva's default of 2 MS/s. This is because of the requirements of our project.
    2. We are using 1 ADC channel.
    3. As to the sequencer and polling mode, I will have to get back to you on that.
    4. It takes about 1 second (perhaps shorter) to fill the data array with 4096 values.

    What do you mean "synchronize between the two arrays"?

  • Hi,

     First of all, if you are running at 333kS/s then it should take much less than a second to fill the 4096-element array. 333 kS/s means it will should only take in the ms to complete the 4096 buffer.iEven it if takes about 1 second, it is still magnitude smaller than a minute and half. 

    - Can you show your code how you set up the ADC for measurements?

    - Do you have the correct clock setting for the device and the ADC?

    - If you said the runtime is the same even for a 50-element array then it is really weird. Why don't you try 4 elements. The ADC should only take the amount of time to measure 4 samples. It should generate an interrupt when it is done. The processor should move the 4 sampled values from the ADC FIFO to your array buffer. You may have something that is not setup correctly that indicates the conversion complete. The bottom line is that the time to measure 4 elements, 50, 2500 or 4096 samples should be linear. There is no way it takes the same amount of time to measure 4096 elements compared to 50 elements or 4 elements.  

      

    1. I meant that the array fills in less than a second, most likely in the ms range. I don't know exactly how quickly the array fills.
    2. To clarify, I meant that the values inside the array were either 0 or 50, not that the array itself was 50 elements large.
    3. Can you elaborate more on what you mean by conversion complete?

  • Hi,

      Please refer to the ADCRIS register. This register holds a flag for each sample sequencer. When a sample sequencer finishes the ADC sampling, the respective flag is set indicating a conversion complete. If you enable interrupt, then the CPU can be interrupted when the conversion complete flag is set. 

  • Hello Charles,

    I am one of the members of the team working on the cross-correlator. First, I would like to inform you that we are using the software tool TivaWare for CCS. I would like to answer some of your previous questions to catch you up with what we have.

    • We are only sampling one ADC channel (Analog-to-digital converter input 1)
    • We are using sample sequencer 0
    • We are triggering the ADC with a timer. The timer is triggering the ADC every 3µs.
    • We are using the uDMA. This is how we are transferring the conversions from the ADC to the buffers, we are using the PING PONG transfer mode, to the array where are storing 4096 conversions.
      • Without the cross-correlation algorithm, we found that 4096 elements are collected instantly – somewhere in the ms because the length of time of the signal we are measuring is approximately 12 ms.
      • The ADC clock is at the default value of 16MHz.

    Testing the ADC and cross-correlation algorithms separately, we find that the run time is fast, however when combined it takes significantly longer. We are speculating that the MCU does not know when to calculate the cross-correlation after all the conversions are completed which is why it is taking a long time.

    Here is how we have the ADC configured: 

  • Hi,

      I think you want to check your timer. Your application uses the timer to trigger the ADC sampling. Are you sure you are triggering every 3us? 

    Muhammad Rezuna said:
    We are speculating that the MCU does not know when to calculate the cross-correlation after all the conversions are completed

      I don't understand what your mean that the MCU does not know when to calculate. It is your application. You have full control on when to process your data when the the conversion is complete. I have no knowledge what your algorithm is. When the 4096 array buffer is filled, what do you do? What trigger your code to start the correlation? You want investigate on that. Also a scope will be helpful to help you debug. After the uDMA completes the transfer it will generate an interrupt. You can try to toggle a GPIO pin in the uDMA ISR to get some idea how long it takes before the next 4096 elements are filled. You can use another GPIO to indicate when the correlation starts and finishes. 

  • We have narrowed down the problem somewhat. We have disabled all interrupts after the ADC is done taking in data, and that cut the execution time down to 45 seconds instead of a minute and a half.

    However, after trying different things, we are still stuck on why it is taking 45 seconds. It should take much faster than that.

    1. We tried increasing and decreasing the array sizes, but it did not seem to make a large enough difference in the execution time.
    2. We tried reducing the integer type to uint8_t instead of uint16_t, but that did not seem to make a large enough difference.
    3. We timed how long the ADC takes to collect data, and the ADC collects data extremely quickly.
    4. We timed how long the cross-correlation function itself takes to complete, and that function seems to be where the majority of the time is taken up.

    Are there things that might slow down code, whether it's related to the ADC or the microcontroller in general?

  •   What is the cross-correlation function? Looks like you need to understand why this function is taking abnormally long time. I have no visibility into your function and I can't help you much. Is this function in some type of loop? Why is this function taking long time when the array size is reduced?