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.

Porting software application from 14-bit ADC to 16-bit ADC

Other Parts Discussed in Thread: MSP430P325, MSP430F4784

Hello,

 

I am porting a software application from MSP430P325 (now obsolete) to MSP430F4784.

MSP430P325 has 14-bit ADC and MSP430F4784 has 16-bit ADC.

Software application implements an algorithm to compute power (P = V x I) in fixed point format.

Results of mathematical operations on both MCUs differ.

e.g.,

On 14-bit MCU :

Summation of 1600 samples of ADC = 4605099

Temp = Summation of 1600 samples of ADC / 1600

           = 4605099 / 1600

           = 399

On 16-bit MCU :

Summation of 1600 samples of ADC = 15760850

Temp = Summation of 1600 samples of ADC / 1600

            = 15760850 / 1600

            = 341

Above calculations show results of 14-bit and 16-bit ADC differ.

How to match 16-bit ADC results with those of 14-bit ADC ?

 

Thank you,

Sunil

  • Hi Sunil

    Assuming those are decimal numbers, neither of the results are correct.

    By my calculator, 4605099 / 1600 = 2878.2 (to 1 decimal place), not 399.

    Also 15760850 / 1600 = 9850.5 (to I decimal place), not 341.

    The standard unsigned integer using 16 bits can contain values from 0 up to 65,535 and no more.  To hold larger numbers, you need more bits. A 32 bit unsigned integer can contain values from 0 to 4,294,967,295 (these values are found from raising 2 to the power of 'number of bits', e.g. 2^32 and then remembering that this is the number of separate values, which starts with zero and so the largest number is always one less.  E.g. a 3 bit number holds 2^3 = 8 values, which are 0,1,2,3,4,5,6 and 7, largest number = 7 and not 8).

    It seems that you are running some kind of averaging on what the ADC reads over 1600 samples, which has nothing to do with the power calculation you mentioned.

    Are you sure you have allowed for big enough numbers to hold the variables?  In C, you would need to declare the variable as a 'long' (preferably 'unsigned long' if you are not expecting any negative numbers to be in there), and this would then be 32 bits in length.

    The division by 1600 is likely to be processor intensive if there is no divider unit on the chip - I'm not familiar with that chip so don't know whether it has one or not.  If your number of samples summed is one of: 2, 4, 8, 16, 32 etc (i.e. a number which is a power of two) then your division could be done with bit shifts, which might be quicker.  You have a choice of 1024 samples ( which is 2^10) or 2048 samples (which is 2^11), unfortunately 1600 is not a power of two.  To divide a 'sum of 1024 samples' by 1024, you shift it 10 places to the right.  (Each shift of one place divides it by two).  This might be quicker to do than a proper division.

    Tony 

  • Hi Tony,

    Thank you for your response.

    My point is following:

    Suppose:

    UScale = 11538

    For 14-bit ADC,                                                            For 16-bit ADC,

    Usum_total = 4605099                                              Usum_total = 15760850

    then

    For 14-bit ADC,                                                            For 16-bit ADC,

    Usum_total / Uscale                                                  Usum_total / Uscale

    = 4605099 / 11538                                                     = 15760850 / 11538

    = 12118                                                                        = 41475

     

    I want to know how to scale the results of both ADC outputs such that the ratio Usum_total / Uscale is equal for both ADCs ?

    i.e., for 14-bit ADC, Usum_total = 12118 and for 16-bit ADC, Usum_total should be 12118, keeping denominator constant.

     

    Thank you,

    Sunil

  • Hello Sunil

    Assuming that both ADCs have the same reference and the same input signal, which for convenience can be assumed to be at the 50% mark, i.e. halfway between 0 and maximum possible value, then a 16-bit ADC will return a result that has two more least-significant bits than a 14-bit ADC.  After all, that's the purpose of having a higher resolution ADC - to give you more bits that represent a 'finer' result.

    So for a 50% input signal, a 14-bit ADC will give you a result of (2^14 * 0.5 = ) 8192 decimal, whereas a 16-bit ADC will give you a result of (2^16 * 0.5 = ) 32768 decimal.

    You will see that the result of the 16-bit ADC is four times larger than the result of the 14-bit ADC.  This is due to the two additional bits on the end.  Each additional bit has the effect of giving a result that is 2 time bigger.

    If you want to interpret the result of the 16-bit ADC as if it were the result of a 14-bit ADC, you could simply divide the result by 4.  Looking at the numbers you have, the sum of 16 bit ADCs is 15760850.  Dividing this by 4 gives 3940213, which looks a lot more like your result from the 14-bit ADC (were these two results from the same sampled signal?)

    After dividing by 4, when you then divide by Uscale, you should get the same result as if a 14-bit ADC had been used.  Doing a divide by 4 effectively loses resolution - but that's OK because you aren't interested in the additional resolution of the least-significant two bits.  You are going to divide anyway by a much larger number (Uscale).

    Alternatively you could just divide by (4 * Uscale), i.e. divide by 46152 instead of Uscale, which effectively divides by 4 and then divides by Uscale but in one calculation.

    By the way, when doing the ADC calcs it is normal to subtract one from the 'power' calculation before multiplying by the input signal ratio.  E.g. the calculations above should really be ((2^16) - 1) * voltage ratio.  That won't make a lot of difference in your case though.

    Hope that helps!

**Attention** This is a public forum