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/TMS320F28335: How to subtract two ADCRESULT in one code line?

Part Number: TMS320F28335

Tool/software: Code Composer Studio

I sample two signals at the sampling rate of 8000Hz. I need to subtract signal 2 from signal 1, but I don't want to create two variables so I do the following code:

Udig[i] = (AdcRegs.ADCRESULT0>>4) - (AdcRegs.ADCRESULT2>>4);

But the result of Udig[I] is not the difference between them, but it's the data from (AdcRegs.ADCRESULT0>>4)

I want to ask if the calculation of multiple ADCRESULT registers in one line is possible? And which is the most optimal way to do so?

  • Liem Quoc,

    I don't see anything logically wrong with your code statement.  I suspect that either the ADCRESULT2 value is not ready when the statement executes or the compiler is getting tripped up somehow.

    You can optimize and simplify the statement by reading the results from AdcMirror instead of AdcRegs so that the bit-shifting is not necessary.

    -Tommy