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.
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,
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