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.

TMS320F2810: Source code LVDT interface with TMS320F2810

Part Number: TMS320F2810

Hello.

Sorry. I do not know English and I use translate.google.com

Help me pls.

Block 1.

1)*CMPR1 = PWM_duty; // write new PWM duty cycle
2)ADC_result = *ADCRESULT0; // store ADC reading
3)ADC_input = ADC_result ^ BIT15; // bipolar input
4)*PIEACK = PIEACK_GROUP3; // acknowledge PIE group 3
5)*EVAIFRB = 0x0001; // reset T2PINT flag

Block 2.

/* input offset removal */
1)ADC_input = (ADC_result >> 4) & 0x0FFF; // unsigned scaled input
2)AvgSumDelta = ADC_input − *(AvgRec.dptr); // signed reading difference
3)AvgSum += AvgSumDelta; // adjust running sum
4)*AvgRec.dptr = ADC_input; // replace oldest value
5)NextIntPoint(&AvgRec); // modify data pointer
6)InputOffset = (int)(AvgSum >> 7); // scaled offset
7)NormInput = (ADC_input − InputOffset) << 4; // normalised ADC reading

1.  What does it mean? (Block1 lines 2 and 3) && (Block2 lines 1 and 2).

Why were the lines Block 1 lines 2 and 3 ? If ADC_input changed in Block 2.

2. Why is linearization simply an addition? Not Linear interpolation ?

Thank you.

  • Anton,

    Is this working code that you are trying to interpret?  Where did it come from?

    There is no way for us to explain its implementation without knowing what it is supposed to do.  If this is not from a TI software example, we may not be able to help.

    -Tommy

  • TMS320F2810: Source code LVDT interface with TMS320F2810 [https://e2e.ti.com/support/microcontrollers/c2000/f/171/t/677810]

    This thread has been locked.

    And I press button "Ask a related question".

    My question was addressed to Richard Poley [https://e2e.ti.com/members/22638]

    He is the author of this code.
  • Anton,

    The application note is pretty old now so it's testing my memory!

    1. Probably block 1, line 2 was an over-sight. I may have had that in some original code version and just not removed it. As you pointed out, the variable "ADC_input" is being over-written in block 2, line 1, so it isn't having any effect.

    2. The linearity correction method used is not very good. Linear interpolation would have been better. I did not fully implement or test this part because at the time I did not have access to calibration equipment.

    Thanks for pointing these out.

    Regards,

    Richard
  • You told in the thread that ADC data is shifted left and used XOR to receive int16_t.
    But in the block 2 it is not in such a way.
    Therefore I have a question #1.
    Thank you for your answer.
  • Anton,

    Well, I don't recall exactly and I'm not guaranteeing there isn't a mistake in the code.  What I said was: "..I used a IQ24 format for most of the variables including InputVoltage, but NormInput is a signed 16-bit integer representing the corrected and left justified 12-bit ADC reading:

    NormInput = (ADC_input - InputOffset) << 4;"

    This is line 7 in block 2 of your post. 

    In block 2, the ADC input is right shifted so it represents a 12-bit unsigned integer (the ADC result on F2812 is left justified).  Then, a running total of 128 readings is maintained in the long integer AvgSum, and the average found by dividing by 128 = 2^7 in block 2 line 6.  This part seems correct.

    In line 7, the average is removed from the most recent ADC reading and the result left shifted by 4, so at this point the reading is a left justified unsigned integer.

    I think the following line was intended to yield a signed I12Q20 integer, but the sign bit seems to be wrong:

    InputVoltage = (_iq)((long) NormInput<<5);

    I am not sure about this.  If you are going to apply the code you will need to check it carefully.  It worked when I last used it, but it's not impossible a tweak was made and not tested after.

    Regards,

    Richard