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.
Hi TI community members,
Please explain Line 305 and Line 309 in my code and please verify though CCS. The variable yk doesn't show either 1 or -1 in any case if input 0Volt and 3Volt is applied separately. I couldn't figure out the problem after using breakpoints at line 309. Please see the expression window and watch yk results in the pictures below,
Since
Line 305-> Voltage1[ConversionCount] = AdcRegs.ADCRESULT0 >>4;
Line 309 gives yk-> yk = ((float) AdcRegs.ADCRESULT0 - 2048.0f) / 2047.0f;
As we know from line 305. Voltage1 is an array[0-9] which will become equal to 0 at 0Volt input (ADCINA0) is applied. Similarly if Voltage1 [0-9] will become equal to 4095 at 3Volt input (ADCINA0) is applied.
In this way, line 309 must have two extreme values yk = +/-1 by calculating, which I don't see in the expression window. Please suggest the answers for this issue.
(Remember Voltage1 is updating the results from 0-9 bitwise when I use breakpoints setup and debug it each time)
Pictures are attached below:
Picture1 :
Picture2:
Thanks
Kind Regards
Arsalan
Arsalan,
The ADCRegs are left justified, or you can also thing of this as a Q4 value, but this is why you see the >>4 when writing them to the array.
When you are casting ADCRegs as a float, you would still need to account for the Q4 nature of the data in the register before using it in your formula. There is an alternate set of ADC result registers, ADCMirrorRegs, that have the ADC Result right justified already if you want to avoid the above.
If you change your code to assign yk = ((float) AdcRegs.ADCRESULT0>>4; or yk = ((float) AdcRegs.ADCMirrorRegs.ADCRESULT0; can we verify that the compiler is transforming this correctly as well before using it in the control loop?
Best,
Matthew
Hi MatthewPate,
Thanks for your reply. The problem has been solved when i see AdcRegs.ADCRESULT0 value in decimal which gives 63320 which I should divide by 2^4 =16 to get 4095.
Therefore the yk expression should be like this: yk = (((float) AdcRegs.ADCRESULT0) / 16.0f - 2048.0f) / 2047.0f
then i got the values of yk = +/-1.
Thanks
Kind Regards
Arsalan