Seeking more information on NRF52833 ADC, reference, and buffers

Hi,

We are developing a product which is reading RTDs and thermistors from the NRF52833's internal ADC. We're working on compensating for the intrinsic errors of the ADC and gain buffers and have some questions not covered in the product specifications.

Do the ADC gain buffers have offsets associated with them? The datasheet says the ADC has an intrinsic offset of ±2LSB @ 10bit res but doesn't mention whether there are voltage offsets associated with the buffers.

Is there any procedure to internally determine the ADC buffer gains? For example, connecting the buffer inputs directly to the reference voltage?

Can you provide any more detail on what the ADC's internal calibration routine does or what it accounts for?

Are there any details on how the ADC input buffer gain is implemented?

Are there any specs on channel isolation in sequential measurement mode?

Is there a spec for temperature drift of the VDDH/5 divider?

Thank you!

Parents
  • Sorry, another question:

    In Product Spec v1.7, section 6.21.2.3 (SAADC Scan mode) it says "The time it takes to sample all channels is less than the sum of the conversion time of all enabled channels. The conversion time for a channel is defined as the sum of the acquisition time tACQ and the conversion time tCONV."

    Why is the total conversion time less than the sum of the channels? What is skipped? What is the expected conversion time?

    Thanks

  • Do the ADC gain buffers have offsets associated with them? The datasheet says the ADC has an intrinsic offset of ±2LSB @ 10bit res but doesn't mention whether there are voltage offsets associated with the buffers.

    1) The input buffer of the ADC has auto-zero for offset. The offset of the ADC core should be scaled with the gain. 

    Is there any procedure to internally determine the ADC buffer gains? For example, connecting the buffer inputs directly to the reference voltage?

    2) Only for VDD as reference. There is an undocumented TASKS_CALIBRATEGAIN that connects the input to VDD/4 and uses gain 1/4

    Can you provide any more detail on what the ADC's internal calibration routine does or what it accounts for?

    3) The offset shorts the ADC input, and then a digital feedback loop tunes a current DAC in the SAR comparator to compensate for the offset. The offset may introduce a noise component if the TASKS_CALIBRATEOFFSET is triggered often

    Are there any details on how the ADC input buffer gain is implemented?

    4) Sorry, no details, but it's a switched capacitor gain stage with high common mode rejection. 

    Are there any specs on channel isolation in sequential measurement mode?

    5) There is only one core ADC, the muxing is done through T-gates (transmission gate, pull down, transmission gate), so there should be very little cross coupling between channels. 

    Is there a spec for temperature drift of the VDDH/5 divider?

    6) No, but it's a resistive divider, as such, as long as the ADC input settles, should not change with temperature (although the resistors do change with temperature, the relative size does not). The ADC temperature coefficient will dominate.

    jdub said:
    Also - any details on the accuracy of the internal VDD/4 divider which can be used as an ADC reference? We are also finding that when using the VDD/4 reference, our signals are much noisier. Any specs on that noise or advice for reducing it?

    7)  The noise that you're seeing is probably coming from VDD. There is a low pass filter inside the ADC, but that is in the MHz range. 

    jdub said:
    Is the VDDH/5 input only enabled when REG0 is on? I'm working on a device where VDDH and VDD are tied together. The 1% spec on the VDDH/5 divider is better than the 3% spec on the ADC's input gain buffers, so I have been trying to use the VDDH5 input. But it behaves like it's floating (the reading seems arbitrary and the value decreases with sample rate, implying a loading effect)

    8) That does not matter. VDDH/5 divider goes to the input gain buffers. I'm not sure it's enabled without the 5V regulator is enabled.

    jdub said:
    Does the ADC sequence converter fail if you use the CH[X}.CONFIG register's RESP and RESN settings to set inputs at VDD/2 while setting CH[X}.PSEL and NSEL to Not Connected? I can take a valid measurement in this configuration if I sample as a one-off, but if I make this measurement part of a sequence the ADC never finishes.

    9) You need to enable the PSEL/NSEL, but not connect them to anything. Try writing 0xFE to both.

    jdub said:

    In Product Spec v1.7, section 6.21.2.3 (SAADC Scan mode) it says "The time it takes to sample all channels is less than the sum of the conversion time of all enabled channels. The conversion time for a channel is defined as the sum of the acquisition time tACQ and the conversion time tCONV."

    Why is the total conversion time less than the sum of the channels? What is skipped? What is the expected conversion time?

    10) Not sure why it's written like this as it's very confusing. We expect the conversion time to be N x (TACQ + t_conv).

  • Interestingly I tested with both forward and reverse current and I see a bigger difference than expected. I'll update the previous post with the updated code. The results are very good for this ADC, better than expected.

    Edit: Performing an initial offset calibration removes the differences. I'll update results and code, this has been interesting. Edit 2: Tested reference and 2 test resistors on a 5-digit DMM, updated results

    Measured 14-bit value of 905.0 Ohm test resistor is 904.9 Ohms with -0.01% error

    // Internal 0.6v Ref 12-bit S0S1 RTD actual value 905.0 Ohm (reference 2001.4 Ohm) - Forward current measurement
    //        VDD     Iref    RdsOnA    RdsOnB      V1      V2      V3      V4         Vrtd         Vref        Rrtd  Error
    //     ======   ======  ========  ========  ======  ======  ======  ======  ===========  ===========  ========== ======
    // RTD 2982mV,  926 uA,  173 Ohm,  136 Ohm, 2821mV, 1989mV, 1977mV,  126mV,  477 counts, 1055 counts, 904.9 Ohms -0.01%
    // RTD 2979mV,  925 uA,  168 Ohm,  139 Ohm, 2823mV, 1984mV, 1984mV,  129mV,  477 counts, 1054 counts, 905.8 Ohms  0.08%
    // RTD 2978mV,  926 uA,  174 Ohm,  150 Ohm, 2816mV, 1989mV, 1989mV,  139mV,  478 counts, 1055 counts, 906.8 Ohms  0.20%
    // RTD 2981mV,  925 uA,  172 Ohm,  144 Ohm, 2821mV, 1989mV, 1989mV,  134mV,  477 counts, 1054 counts, 905.8 Ohms  0.08%
    
    // Internal 0.6v Ref 12-bit S0S1 RTD actual value 905.0 Ohm (reference 2001.4 Ohm) - Reverse current measurement
    //        VDD     Iref    RdsOnA    RdsOnB      V1      V2      V3      V4         Vrtd         Vref        Rrtd  Error
    //     ======   ======  ========  ========  ======  ======  ======  ======  ===========  ===========  ========== ======
    // RTD 2984mV,  922 uA,  135 Ohm,  183 Ohm,  125mV,  965mV,  970mV, 2815mV,  475 counts, 1051 counts, 904.5 Ohms -0.05%
    // RTD 2980mV,  922 uA,  144 Ohm,  180 Ohm,  133mV,  960mV,  959mV, 2814mV,  475 counts, 1051 counts, 904.5 Ohms -0.05%
    // RTD 2981mV,  923 uA,  144 Ohm,  179 Ohm,  133mV,  961mV,  965mV, 2815mV,  475 counts, 1052 counts, 903.7 Ohms -0.15%
    // RTD 2979mV,  921 uA,  145 Ohm,  170 Ohm,  134mV,  970mV,  965mV, 2822mV,  475 counts, 1050 counts, 905.4 Ohms  0.04%
    
    // Measured 12-bit value of 905.0 Ohm test resistor is 905.2 Ohms with  0.02% error
    
    // Internal 0.6v Ref 14-bit S0S1 RTD actual value 905.0 Ohm (reference 2001.4 Ohm) - Forward current measurement
    //        VDD     Iref    RdsOnA    RdsOnB      V1      V2      V3      V4         Vrtd         Vref        Rrtd  Error
    //     ======   ======  ========  ========  ======  ======  ======  ======  ===========  ===========  ========== ======
    // RTD 2976mV,  923 uA,  169 Ohm,  138 Ohm, 2820mV, 1979mV, 1972mV,  128mV, 1898 counts, 4205 counts, 903.4 Ohms -0.18%
    // RTD 2973mV,  924 uA,  174 Ohm,  136 Ohm, 2812mV, 1975mV, 1977mV,  126mV, 1899 counts, 4211 counts, 902.6 Ohms -0.27%
    // RTD 2968mV,  923 uA,  154 Ohm,  136 Ohm, 2825mV, 1989mV, 1978mV,  126mV, 1897 counts, 4209 counts, 902.0 Ohms -0.33%
    // RTD 2973mV,  923 uA,  167 Ohm,  130 Ohm, 2818mV, 1983mV, 1978mV,  120mV, 1898 counts, 4209 counts, 902.5 Ohms -0.28%
    
    // Internal 0.6v Ref 14-bit S0S1 RTD actual value 905.0 Ohm (reference 2001.4 Ohm) - Reverse current measurement
    //        VDD     Iref    RdsOnA    RdsOnB      V1      V2      V3      V4         Vrtd         Vref        Rrtd  Error
    //     ======   ======  ========  ========  ======  ======  ======  ======  ===========  ===========  ========== ======
    // RTD 2968mV,  924 uA,  130 Ohm,  168 Ohm,  121mV,  954mV,  958mV, 2812mV, 1912 counts, 4213 counts, 908.3 Ohms  0.36%
    // RTD 2973mV,  923 uA,  131 Ohm,  173 Ohm,  121mV,  964mV,  960mV, 2813mV, 1909 counts, 4209 counts, 907.7 Ohms  0.30%
    // RTD 2979mV,  925 uA,  136 Ohm,  175 Ohm,  126mV,  959mV,  963mV, 2817mV, 1908 counts, 4216 counts, 905.8 Ohms  0.08%
    // RTD 2976mV,  924 uA,  132 Ohm,  170 Ohm,  122mV,  953mV,  966mV, 2818mV, 1909 counts, 4214 counts, 906.7 Ohms  0.18%
    
    // Measured 14-bit value of 905.0 Ohm test resistor is 904.9 Ohms with -0.01% error
    

    Measured 14-bit value of 2984.6 Ohm test resistor is 2984.8 Ohms with  0.01% error

    // Internal 0.6v Ref 12-bit S0S1 RTD actual value 2984.6 Ohm (reference 2001.4 Ohm) - Forward current measurement
    //        VDD     Iref    RdsOnA    RdsOnB      V1      V2      V3      V4         Vrtd         Vref        Rrtd  Error
    //     ======   ======  ========  ========  ======  ======  ======  ======  ===========  ===========  ========== ======
    // RTD 2975mV,  558 uA,  168 Ohm,  136 Ohm, 2881mV, 1213mV, 1196mV,   76mV,  951 counts,  636 counts, 2992.7 Ohms  0.27%
    // RTD 2979mV,  559 uA,  189 Ohm,  130 Ohm, 2873mV, 1201mV, 1191mV,   73mV,  950 counts,  637 counts, 2984.8 Ohms  0.01%
    // RTD 2966mV,  559 uA,  152 Ohm,  123 Ohm, 2881mV, 1212mV, 1195mV,   69mV,  950 counts,  637 counts, 2984.8 Ohms  0.01%
    // RTD 2967mV,  558 uA,  170 Ohm,  121 Ohm, 2872mV, 1223mV, 1192mV,   68mV,  950 counts,  636 counts, 2989.5 Ohms  0.16%
    
    // Internal 0.6v Ref 12-bit S0S1 RTD actual value 2984.6 Ohm (reference 2001.4 Ohm) - Reverse current measurement
    //        VDD     Iref    RdsOnA    RdsOnB      V1      V2      V3      V4         Vrtd         Vref        Rrtd  Error
    //     ======   ======  ========  ========  ======  ======  ======  ======  ===========  ===========  ========== ======
    // RTD 2981mV,  563 uA,  127 Ohm,  190 Ohm,   72mV, 1748mV, 1759mV, 2874mV,  954 counts,  641 counts, 2978.7 Ohms -0.20%
    // RTD 2973mV,  563 uA,  126 Ohm,  152 Ohm,   71mV, 1741mV, 1749mV, 2887mV,  955 counts,  641 counts, 2981.8 Ohms -0.09%
    // RTD 2981mV,  562 uA,  199 Ohm,  170 Ohm,  112mV, 1731mV, 1754mV, 2885mV,  954 counts,  640 counts, 2983.3 Ohms -0.04%
    // RTD 2974mV,  563 uA,  122 Ohm,  168 Ohm,   69mV, 1743mV, 1749mV, 2879mV,  954 counts,  641 counts, 2978.7 Ohms -0.20%
    
    // Measured 12-bit value of 2984.6 Ohm test resistor is 2984.3 Ohms with -0.01% error
    
    // Internal 0.6v Ref 14-bit S0S1 RTD actual value 2984.6 Ohm (reference 2001.4 Ohm) - Forward current measurement
    //        VDD     Iref    RdsOnA    RdsOnB      V1      V2      V3      V4         Vrtd         Vref        Rrtd  Error
    //     ======   ======  ========  ========  ======  ======  ======  ======  ===========  ===========  ========== ======
    // RTD 2978mV,  558 uA,  166 Ohm,  134 Ohm, 2885mV, 1211mV, 1202mV,   75mV, 3799 counts, 2544 counts, 2988.7 Ohms  0.14%
    // RTD 2980mV,  559 uA,  178 Ohm,  137 Ohm, 2880mV, 1205mV, 1194mV,   77mV, 3811 counts, 2550 counts, 2991.1 Ohms  0.22%
    // RTD 2980mV,  559 uA,  175 Ohm,  139 Ohm, 2882mV, 1209mV, 1190mV,   78mV, 3806 counts, 2550 counts, 2987.2 Ohms  0.09%
    // RTD 2980mV,  560 uA,  196 Ohm,  123 Ohm, 2870mV, 1201mV, 1198mV,   69mV, 3807 counts, 2554 counts, 2983.3 Ohms -0.04%
    
    // Internal 0.6v Ref 14-bit S0S1 RTD actual value 2984.6 Ohm (reference 2001.4 Ohm) - Reverse current measurement
    //        VDD     Iref    RdsOnA    RdsOnB      V1      V2      V3      V4         Vrtd         Vref        Rrtd  Error
    //     ======   ======  ========  ========  ======  ======  ======  ======  ===========  ===========  ========== ======
    // RTD 2977mV,  562 uA,  128 Ohm,  172 Ohm,   72mV, 1750mV, 1765mV, 2880mV, 3817 counts, 2563 counts, 2980.6 Ohms -0.13%
    // RTD 2970mV,  562 uA,  131 Ohm,  158 Ohm,   74mV, 1742mV, 1751mV, 2881mV, 3816 counts, 2560 counts, 2983.3 Ohms -0.04%
    // RTD 2971mV,  562 uA,  165 Ohm,  151 Ohm,   93mV, 1749mV, 1764mV, 2886mV, 3814 counts, 2562 counts, 2979.4 Ohms -0.17%
    // RTD 2978mV,  562 uA,  133 Ohm,  190 Ohm,   75mV, 1741mV, 1741mV, 2871mV, 3819 counts, 2561 counts, 2984.5 Ohms -0.00%
    
    // Measured 14-bit value of 2984.6 Ohm test resistor is 2984.8 Ohms with  0.01% error
    

  • One last post, switching to floating-point to get accurate % error. Even with small averaging numbers looks very good, provided both forward and reverse current measurements are averaged to cater for residual SAADC offset.

    Measured value of 905.0 Ohm test resistor is 905.2 Ohms with 0.02% error in 12-bit mode <- Edit: got better results

    // Internal 0.6v Ref 12-bit S0S1 RTD actual value 905.0 Ohm (reference 2001.4 Ohm) - Forward current measurement
    //        VDD     Iref    RdsOnA    RdsOnB      V1      V2      V3      V4         Vrtd         Vref        Rrtd  Error
    //     ======   ======  ========  ========  ======  ======  ======  ======  ===========  ===========  ========== ======
    // RTD 2982mV,  926 uA,  173 Ohm,  136 Ohm, 2821mV, 1989mV, 1977mV,  126mV,  477 counts, 1055 counts, 904.9 Ohms -0.01%
    // RTD 2979mV,  925 uA,  168 Ohm,  139 Ohm, 2823mV, 1984mV, 1984mV,  129mV,  477 counts, 1054 counts, 905.8 Ohms  0.08%
    // RTD 2978mV,  926 uA,  174 Ohm,  150 Ohm, 2816mV, 1989mV, 1989mV,  139mV,  478 counts, 1055 counts, 906.8 Ohms  0.20%
    // RTD 2981mV,  925 uA,  172 Ohm,  144 Ohm, 2821mV, 1989mV, 1989mV,  134mV,  477 counts, 1054 counts, 905.8 Ohms  0.08%
    
    // Internal 0.6v Ref 12-bit S0S1 RTD actual value 905.0 Ohm (reference 2001.4 Ohm) - Reverse current measurement
    //        VDD     Iref    RdsOnA    RdsOnB      V1      V2      V3      V4         Vrtd         Vref        Rrtd  Error
    //     ======   ======  ========  ========  ======  ======  ======  ======  ===========  ===========  ========== ======
    // RTD 2984mV,  922 uA,  135 Ohm,  183 Ohm,  125mV,  965mV,  970mV, 2815mV,  475 counts, 1051 counts, 904.5 Ohms -0.05%
    // RTD 2980mV,  922 uA,  144 Ohm,  180 Ohm,  133mV,  960mV,  959mV, 2814mV,  475 counts, 1051 counts, 904.5 Ohms -0.05%
    // RTD 2981mV,  923 uA,  144 Ohm,  179 Ohm,  133mV,  961mV,  965mV, 2815mV,  475 counts, 1052 counts, 903.7 Ohms -0.15%
    // RTD 2979mV,  921 uA,  145 Ohm,  170 Ohm,  134mV,  970mV,  965mV, 2822mV,  475 counts, 1050 counts, 905.4 Ohms  0.04%
    
    // Measured 12-bit value of 905.0 Ohm test resistor is 905.2 Ohms with  0.02% error
    
    // Internal 0.6v Ref 14-bit S0S1 RTD actual value 905.0 Ohm (reference 2001.4 Ohm) - Forward current measurement
    //        VDD     Iref    RdsOnA    RdsOnB      V1      V2      V3      V4         Vrtd         Vref        Rrtd  Error
    //     ======   ======  ========  ========  ======  ======  ======  ======  ===========  ===========  ========== ======
    // RTD 2976mV,  923 uA,  169 Ohm,  138 Ohm, 2820mV, 1979mV, 1972mV,  128mV, 1898 counts, 4205 counts, 903.4 Ohms -0.18%
    // RTD 2973mV,  924 uA,  174 Ohm,  136 Ohm, 2812mV, 1975mV, 1977mV,  126mV, 1899 counts, 4211 counts, 902.6 Ohms -0.27%
    // RTD 2968mV,  923 uA,  154 Ohm,  136 Ohm, 2825mV, 1989mV, 1978mV,  126mV, 1897 counts, 4209 counts, 902.0 Ohms -0.33%
    // RTD 2973mV,  923 uA,  167 Ohm,  130 Ohm, 2818mV, 1983mV, 1978mV,  120mV, 1898 counts, 4209 counts, 902.5 Ohms -0.28%
    
    // Internal 0.6v Ref 14-bit S0S1 RTD actual value 905.0 Ohm (reference 2001.4 Ohm) - Reverse current measurement
    //        VDD     Iref    RdsOnA    RdsOnB      V1      V2      V3      V4         Vrtd         Vref        Rrtd  Error
    //     ======   ======  ========  ========  ======  ======  ======  ======  ===========  ===========  ========== ======
    // RTD 2968mV,  924 uA,  130 Ohm,  168 Ohm,  121mV,  954mV,  958mV, 2812mV, 1912 counts, 4213 counts, 908.3 Ohms  0.36%
    // RTD 2973mV,  923 uA,  131 Ohm,  173 Ohm,  121mV,  964mV,  960mV, 2813mV, 1909 counts, 4209 counts, 907.7 Ohms  0.30%
    // RTD 2979mV,  925 uA,  136 Ohm,  175 Ohm,  126mV,  959mV,  963mV, 2817mV, 1908 counts, 4216 counts, 905.8 Ohms  0.08%
    // RTD 2976mV,  924 uA,  132 Ohm,  170 Ohm,  122mV,  953mV,  966mV, 2818mV, 1909 counts, 4214 counts, 906.7 Ohms  0.18%
    
    // Measured 14-bit value of 905.0 Ohm test resistor is 904.9 Ohms with -0.01% error
    
    
    // Internal 0.6v Ref 12-bit S0S1 RTD actual value 2984.6 Ohm (reference 2001.4 Ohm) - Forward current measurement
    //        VDD     Iref    RdsOnA    RdsOnB      V1      V2      V3      V4         Vrtd         Vref        Rrtd  Error
    //     ======   ======  ========  ========  ======  ======  ======  ======  ===========  ===========  ========== ======
    // RTD 2975mV,  558 uA,  168 Ohm,  136 Ohm, 2881mV, 1213mV, 1196mV,   76mV,  951 counts,  636 counts, 2992.7 Ohms  0.27%
    // RTD 2979mV,  559 uA,  189 Ohm,  130 Ohm, 2873mV, 1201mV, 1191mV,   73mV,  950 counts,  637 counts, 2984.8 Ohms  0.01%
    // RTD 2966mV,  559 uA,  152 Ohm,  123 Ohm, 2881mV, 1212mV, 1195mV,   69mV,  950 counts,  637 counts, 2984.8 Ohms  0.01%
    // RTD 2967mV,  558 uA,  170 Ohm,  121 Ohm, 2872mV, 1223mV, 1192mV,   68mV,  950 counts,  636 counts, 2989.5 Ohms  0.16%
    
    // Internal 0.6v Ref 12-bit S0S1 RTD actual value 2984.6 Ohm (reference 2001.4 Ohm) - Reverse current measurement
    //        VDD     Iref    RdsOnA    RdsOnB      V1      V2      V3      V4         Vrtd         Vref        Rrtd  Error
    //     ======   ======  ========  ========  ======  ======  ======  ======  ===========  ===========  ========== ======
    // RTD 2981mV,  563 uA,  127 Ohm,  190 Ohm,   72mV, 1748mV, 1759mV, 2874mV,  954 counts,  641 counts, 2978.7 Ohms -0.20%
    // RTD 2973mV,  563 uA,  126 Ohm,  152 Ohm,   71mV, 1741mV, 1749mV, 2887mV,  955 counts,  641 counts, 2981.8 Ohms -0.09%
    // RTD 2981mV,  562 uA,  199 Ohm,  170 Ohm,  112mV, 1731mV, 1754mV, 2885mV,  954 counts,  640 counts, 2983.3 Ohms -0.04%
    // RTD 2974mV,  563 uA,  122 Ohm,  168 Ohm,   69mV, 1743mV, 1749mV, 2879mV,  954 counts,  641 counts, 2978.7 Ohms -0.20%
    
    // Measured 12-bit value of 2984.6 Ohm test resistor is 2984.3 Ohms with -0.01% error
    
    // Internal 0.6v Ref 14-bit S0S1 RTD actual value 2984.6 Ohm (reference 2001.4 Ohm) - Forward current measurement
    //        VDD     Iref    RdsOnA    RdsOnB      V1      V2      V3      V4         Vrtd         Vref        Rrtd  Error
    //     ======   ======  ========  ========  ======  ======  ======  ======  ===========  ===========  ========== ======
    // RTD 2978mV,  558 uA,  166 Ohm,  134 Ohm, 2885mV, 1211mV, 1202mV,   75mV, 3799 counts, 2544 counts, 2988.7 Ohms  0.14%
    // RTD 2980mV,  559 uA,  178 Ohm,  137 Ohm, 2880mV, 1205mV, 1194mV,   77mV, 3811 counts, 2550 counts, 2991.1 Ohms  0.22%
    // RTD 2980mV,  559 uA,  175 Ohm,  139 Ohm, 2882mV, 1209mV, 1190mV,   78mV, 3806 counts, 2550 counts, 2987.2 Ohms  0.09%
    // RTD 2980mV,  560 uA,  196 Ohm,  123 Ohm, 2870mV, 1201mV, 1198mV,   69mV, 3807 counts, 2554 counts, 2983.3 Ohms -0.04%
    
    // Internal 0.6v Ref 14-bit S0S1 RTD actual value 2984.6 Ohm (reference 2001.4 Ohm) - Reverse current measurement
    //        VDD     Iref    RdsOnA    RdsOnB      V1      V2      V3      V4         Vrtd         Vref        Rrtd  Error
    //     ======   ======  ========  ========  ======  ======  ======  ======  ===========  ===========  ========== ======
    // RTD 2977mV,  562 uA,  128 Ohm,  172 Ohm,   72mV, 1750mV, 1765mV, 2880mV, 3817 counts, 2563 counts, 2980.6 Ohms -0.13%
    // RTD 2970mV,  562 uA,  131 Ohm,  158 Ohm,   74mV, 1742mV, 1751mV, 2881mV, 3816 counts, 2560 counts, 2983.3 Ohms -0.04%
    // RTD 2971mV,  562 uA,  165 Ohm,  151 Ohm,   93mV, 1749mV, 1764mV, 2886mV, 3814 counts, 2562 counts, 2979.4 Ohms -0.17%
    // RTD 2978mV,  562 uA,  133 Ohm,  190 Ohm,   75mV, 1741mV, 1741mV, 2871mV, 3819 counts, 2561 counts, 2984.5 Ohms -0.00%
    
    // Measured 14-bit value of 2984.6 Ohm test resistor is 2984.8 Ohms with  0.01% error
    

  • Hi hmolesworth, sorry for the slow reply, I hope you had a good holiday.

    Thank you so much for running these experiments. I'm studying what you did and it aligns almost exactly with what we're doing. We use ratiometric measurements and are presently seeing about a ±2C spread in our final temperature values. This is roughly ±0.8ohm at the RTD. The resistance offset is consistent over time, and it varies from unit to unit. So one unit might be off by +0.4ohms consistently, another by -0.2ohms, another is dead on like your demo, etc.

    Main differences:

    - You are measuring both the reference resistor and RTD in differential mode. Due to the topology of our circuit, the RTD has one leg tied to GND, so it must be measured single-ended. I don't expect this to be significant.

    - You have a 4-wire RTD, our RTD is 2-wire but it's soldered to the same circuit board so the intermediate resistance should be small and constant.

    - We have a multi-microfarad cap in parallel with the RTD for noise suppression (I am presently investigating how much the soaking current could be throwing off our reading)

    - We adjust the PGA gain of the ADC for maximum dynamic range (although we are careful to keep the same PGA setting for the reference and RTD measurement)

    - The problematic measurements I'm seeing are on an extremely small form factor product. So creepage/clearance/leakage currents might be a factor here.

    So while I don't see a smoking gun that would account for the differences we see, I find your approach very reassuring, and it's leading me to believe I might be hunting an issue with the overall product/PCBA assembly, not the ADC intrinsically. Thank you again!

  • Good to hear from you, hopefully you got a good break.

    "The resistance offset is consistent over time, and it varies from unit to unit" is almost certainly a calibration issue, more about this below.

    "the RTD has one leg tied to GND, so it must be measured single-ended. I don't expect this to be significant" This is a huge issue, given that reversing the current flow allowing automatic residual offset compensation is not available. This means that SAADC calibration is essential, and the calibration must be performed at the same gain and sampling values as each measurement. SAADC offset calibration is known to be slightly dodgy, and must be repeated for any gain or temperature change. The best solution is to not tie the RTD to GND, unless the RTD itself is physically manufactured with a GND connection, in itself highly suspicious.

    "it's soldered to the same circuit board so the intermediate resistance should be small and constant" Pretty irrelevant, what matters is any common-mode current (current to/from other devices) using the same copper/vias as the RTD and reference resistor measurement. The SAADC, in addition, does not have a dedicated Gnd which makes things worse.

    "We have a multi-microfarad cap in parallel with the RTD" How many uF and what type? Any capacitor across the RTD requires an identical capacitor (repeat identical) across the reference; it can not be Tant or electrolytic and if ceramic must nave a voltage rating at least double the anticipated working voltage. Anything above 100nF is pointless; balanced capacitance on RTD and reference is much more important. Internal RTD capacitance must also be accounted for.

    "We adjust the PGA gain of the ADC for maximum dynamic range" The best performance (my opinion) is with gain at 1/6; anything higher degrades SAADC performance. Regardless, the SAADC calibration must be performed at the chosen gain as the SAADC offset changes with gain.

    "So creepage/clearance/leakage currents might be a factor" doubtful.

    Assuming the Gnd is fixed in the RTD and is immovable, use 3-wire sensing instead. I'll change my circuit to RTD Gnd and 3-wire and post the results and code later if I get time.

    As an endnote, ratiometric doesn't just mean comparing reference with RTD, but also comparing forward- and reverse-current measurements of reference and RTD since the SAADC (as with all ADCs) offsets are never really eliminated without doing this. Also it is often preferred to use VDD/4 and remove all capacitance across RTD and reference resistors to get true ratiometric results, regardless of reference voltage. In all cases, best to trigger the SAADC to start while the CPU and Radio are both quiet, a case for PPI.

    It would be helpful to see the front-end schematic and SAADC settings. Good luck :-)

  • I tested with 2-wire RTD and as expected the results are much poorer and vary from calibration to calibration as the residual offset is not handled. There are two ways to address that.

    Edit: 3 ways. I got quite good results by simply reversing the differential pin selection on the SAADC (no hardware change) to compensate for the residual SAADC offset: Updated results

    Measured 14-bit value of 905.0 Ohm 2-Wire test resistor is 905.3 Ohms with  0.03% error and much better stability/repeatability:

    // Internal 0.6v Ref 14-bit S0S1 2-Wire RTD actual value 905.0 Ohm (reference 2001.4 Ohm) - Pos-Neg ADC
    // VDD mV Iref uA  RdsOn  V1 mV V2 mV V3 mV    Vrtd    Vref   Rrtd  Error
    // ====== ======= ======  ===== ===== =====  ======  ====== ====== ======
    //   2983    1510     29   2939   923     4  3098.8  6878.1  901.7 -0.37%
    //   2983    1516     27   2942   914    -2  3124.2  6906.0  905.4  0.04%
    //   2973    1513     25   2934   911    -2  3110.4  6892.0  903.2 -0.19%
    //   2985    1515     33   2935   918     2  3123.8  6903.0  905.7  0.08%
    //
    // Internal 0.6v Ref 14-bit S0S1 2-Wire RTD actual value 905.0 Ohm (reference 2001.4 Ohm) - Neg-Pos ADC
    // VDD mV Iref uA  RdsOn  V1 mV V2 mV V3 mV    Vrtd    Vref   Rrtd  Error
    // ====== ======= ======  ===== ===== =====  ======  ====== ====== ======
    //   2981    1517     34   2929   911    -1  3134.1  6912.8  907.4  0.27%
    //   2979    1514     28   2936   910     0  3121.4  6899.7  905.4  0.05%
    //   2978    1514     24   2941   918     1  3121.7  6899.3  905.6  0.06%
    //   2981    1517     27   2939   918     4  3135.8  6912.8  907.9  0.32%
    //
    // Measured 14-bit value of 905.0 Ohm 2-Wire test resistor is 905.3 Ohms with  0.03% error
    

    The schematic/Circuit diagram:

    // RTD Measurement - 2- and 3-wire Unidirectional current
    //                          + -------------------------------------------------------------------+
    //                          |  nRF52832/nRF52833/nRF52840                                        |
    //                          |                                                                    |
    //                          |    VDD               VDD                 VDD                       |
    //                          |   --#--             --#--               --#--                      |
    //                          |     |                 |                   |                        |
    //                          |    _|__               |   Excitation      |   Option               |
    //                          |    / \                +-|   On            +-|   13k                |
    //                          |   /-+-\                 |<- H0   H1         |<- Pullup             |
    //                          |     |                 +-|   160R 35R      +-|   (not used)         |
    //         Excitation  P0.04|     |                 |                   |                        |
    //         +----------------O-----#------#----------#-------------------#------------ In         |
    //         |                |     |      |          |   Excitation      |   Option               |
    //         |                |   __|__  -----        +-|   Off           +-|   13k                |
    //         |                |    / \   -----          |<- L0   L1         |<- Pulldown           |
    //         |                |   /-+-\    |3pF       +-|   160R 35R      +-|   (not used)         |
    //         |                |     |      |          |                   |                        |
    //         |                |   =====  =====      =====               =====                      |
    //         |                |    ===    ===        ===                 ===                       |
    //         |                |     =      =          =                   =                        |
    //         |                |                                                                    |
    //         |                |    VDD                                      VDD                    |
    //         |                |   --#--                                    --#--                   |
    //         |                |    _|__                                      |   160k              |
    //         |                |    / \                                       +-| Bias Hi/Lo/Both   |
    //         |                |   /-+-\                                        |<-                 |
    //         |                |     |   PIN_VOLTAGE_1                        +-|                   |
    //         |          P0.28 |     |   AIN4         |----'T'-Mux-----|      |            P SAADC  |
    //         #--------#-------O-----#-----#----------+ +----#-------+ +--#---#------#------#-->    |
    //         |        |       |     |     |          | |    |       | |  |   |      |      |       |
    //         |        |       |   __|__ -----        ----   +-|    ----- |   +-|   +++     |       |
    //         |        |       |    / \  -----         |       |<--+  |   |     |<- | |   -----     |
    //  Rref  +++ 100nF |       |   /-+-\   |3pF        |     +-|   |  |   |   +-|   | |   -----     |
    //  2k0   | |     -----     |     |     |           +---- |--------#   |   |     +++     | 2.5pF |
    //  1%    | |     -----     |   ===== =====               |     |  |   |   |      |1M0   |       |
    // (0.1%) +++       |       |    ===   ===              =====   |  |   | =====  =====  =====     |
    //         |        |       |     =     =                ===    |  |   |  ===    ===    ===      |
    //         |        |       |                             =    Select  |   =      =      =       |
    //         |        |       |         PIN_VOLTAGE_2                    |                         |
    //         |        | P0.29 |         AIN5         |----'T'-Mux-----|  |                         |
    //         #--------#-------O-----#-----#----------+ +----#-------+ +--#  VDD                    |
    //         |        |       |                                          | --#--                   |
    //    RTD +++ 100nF |       |                                          |   |   160k              |
    //        | |     -----     |                                          |   +-| Bias Hi/Lo/Both   |
    //        | |     -----     |                                          |     |<-                 |
    //        +++       |       |         PIN_VOLTAGE_3                    |   +-|                   |
    //         |        | P0.31 |         AIN7         |----'T'-Mux-----|  |   |            N SAADC  |
    //         #--------#-------O-----#-----#----------+ +----#-------+ +--#~~~#------#------#-->    |
    //         |                |                 Note V3 can be negative  |   |      |      |       |
    //         |                |                                          |   +-|   +++     |       |
    //         |          VDD   |    VDD                                   |     |<- | |   -----     |
    //         |         --#--  |     |                                    |   +-|   | |   -----     |
    //         |           +----O-----#   PIN_VOLTAGE_0                    |   |     +++     | 2.5pF |
    //         |                |     |   AIN_VDD      |----'T'-Mux-----|  |   |      |1M0   |       |
    //         |                |     +-----#----------+ +----#-------+ +--+ =====  =====  =====     |
    //         |                |                                             ===    ===    ===      |
    //         |                |                                              =      =      =       |
    //         |                |    GND                                       P: Single-ended       |
    //         #----------------O-----+                                        P&N: Differential     |
    //         |                |     |                                                              |
    //       =====              |   =====                                                            |
    //        ===               |    ===                                                             |
    //         =                |     =                                                              |
    //                          +--------------------------------------------------------------------+
    //
    // Capacitor min value = (3pF+2.5pF)*2^14=80nF
    // Vref = differential voltage V1 and V2 in SAADC counts
    // Vrtd = differential voltage V2 and V3 in SAADC counts
    // Rrtd = (Vrtd * Rref)/Vref Ohms
    

    The code:

    #define SAADC_RESOLUTION_VAL   SAADC_RESOLUTION_VAL_14bit  // 12- or 14-bit in this code
    #define PIN_EXCITATION_A  4 // Red lead A to remote RTD
    //      PIN_VOLTAGE_0   VDD // VDD as source of excitation
    #define PIN_VOLTAGE_1    28 // AIN4 White lead from remote RTD (PIN_EXCITATION_A end)
    #define PIN_VOLTAGE_2    29 // AIN5 White lead from remote RTD (PIN_EXCITATION_B end)
    #define PIN_VOLTAGE_3    31 // AIN7 Red lead B to remote RTD and Reference resistor
    #define PIN_VOLTAGE_4    30 // AIN6 Reference resistor and PIN_EXCITATION_B
    
    // Input range = (VDD/4V)/(1/6) = 4.5 V with VDD=3V VDD/4 Ref do not use 100nF caps
    // Input range = (0.6 V)/(1/6)  = 3.6 V with 100nF caps regardless of VDD
    // Differential mode has 1 bit less than single-ended due to sign bit
    #if (SAADC_RESOLUTION_VAL == SAADC_RESOLUTION_VAL_12bit)
     #define SAADC_COUNTS_PER_VOLT_SE   1138  // 12-bit Mode Singe-ended:  4096/3.6V
     #define SAADC_COUNTS_PER_VOLT_DIFF  569  // 12-bit Mode Differential: 2048/3.6V
     const uint8_t SAADC_ResolutionStr[] = "12-bit";
    #elif (SAADC_RESOLUTION_VAL == SAADC_RESOLUTION_VAL_14bit)
     #define SAADC_RESOLUTION_VAL SAADC_RESOLUTION_VAL_14bit
     #define SAADC_COUNTS_PER_VOLT_SE   4551  // 14-bit Mode Singe-ended: 16384/3.6V
    // #define SAADC_COUNTS_PER_VOLT_DIFF 2276  // 14-bit Mode Differential: 8192/3.6V
     #define SAADC_COUNTS_PER_VOLT_DIFF 3413  // 14-bit Mode Differential: 8192/2.4V
     const uint8_t SAADC_ResolutionStr[] = "14-bit";
    #else
     #error SAADC_RESOLUTION_VAL   not 12- or 14-bit in this code
    #endif
    
    // Do an initial calibration as the offset shows up in comparing +ve and -ve current measurements
    static bool mAmCalibrated = false;
    static float mMeasurementError = 0.0f;
    
    static void RequestCalibration(void)
    {
       // Request a recalibration on any gain or mode changes
       mAmCalibrated = false;
    }
    
    // The accumulator is controlled in the OVERSAMPLE register. When using oversampling, 2^OVERSAMPLE input
    // samples are averaged before the sample result is transferred to memory. Hence, the SAMPLE task must be
    // triggered 2^OVERSAMPLE times for each output value
    static int16_t GetRTD_Voltage(uint32_t AnalogueChannelP, uint32_t AnalogueChannelN)
    {
       uint16_t result = 9999;
       uint32_t timeout = 512;
       volatile int16_t buffer[8];
       uint32_t i=0;  // SAADC Channel
       // Can use internal ref SAADC_CH_CONFIG_REFSEL_Internal with 100nF caps or VDD ratiometric SAADC_CH_CONFIG_REFSEL_VDD1_4 with no caps
       // Check if single-ended or differential SAADC mode
       if (AnalogueChannelN == SAADC_CH_PSELN_PSELN_NC)
       {
          // Configure SAADC singled-ended channel, Internal reference (0.6V) and 1/6 gain (range 3.6V), no pull-up or pull-down
          NRF_SAADC->CH[i].CONFIG = (SAADC_CH_CONFIG_GAIN_Gain1_6    << SAADC_CH_CONFIG_GAIN_Pos)   |
                                    (SAADC_CH_CONFIG_MODE_SE         << SAADC_CH_CONFIG_MODE_Pos)   |
                                    (SAADC_CH_CONFIG_REFSEL_Internal << SAADC_CH_CONFIG_REFSEL_Pos) |
                                    (SAADC_CH_CONFIG_RESN_Bypass     << SAADC_CH_CONFIG_RESN_Pos)   |
                                    (SAADC_CH_CONFIG_RESN_Bypass     << SAADC_CH_CONFIG_RESP_Pos)   |
                                    (SAADC_CH_CONFIG_TACQ_10us       << SAADC_CH_CONFIG_TACQ_Pos);
       }
       else
       {
          // Configure SAADC differential channel, Internal reference (0.6V) and 1/4 gain (range 2.4V), no pull-up or pull-down
          NRF_SAADC->CH[i].CONFIG = (SAADC_CH_CONFIG_GAIN_Gain1_4    << SAADC_CH_CONFIG_GAIN_Pos)   |
                                    (SAADC_CH_CONFIG_MODE_Diff       << SAADC_CH_CONFIG_MODE_Pos)   |
                                    (SAADC_CH_CONFIG_REFSEL_Internal << SAADC_CH_CONFIG_REFSEL_Pos) |
                                    (SAADC_CH_CONFIG_RESN_Bypass     << SAADC_CH_CONFIG_RESN_Pos)   |
                                    (SAADC_CH_CONFIG_RESN_Bypass     << SAADC_CH_CONFIG_RESP_Pos)   |
                                    (SAADC_CH_CONFIG_TACQ_10us       << SAADC_CH_CONFIG_TACQ_Pos);
       }
       NRF_SAADC->RESOLUTION = SAADC_RESOLUTION_VAL << SAADC_RESOLUTION_VAL_Pos;
       // Analog positive and negative input channels have strange numbering:
       //  PSELP_NC           0UL  Not connected
       //  PSELP_AnalogInput0 1UL  AIN0
       //  PSELP_AnalogInput1 2UL  AIN1
       //  PSELP_AnalogInput2 3UL  AIN2
       //  PSELP_AnalogInput3 4UL  AIN3
       //  PSELP_AnalogInput4 5UL  AIN4
       //  PSELP_AnalogInput5 6UL  AIN5
       //  PSELP_AnalogInput6 7UL  AIN6
       //  PSELP_AnalogInput7 8UL  AIN7
       //  PSELP_VDD          9UL  VDD
       NRF_SAADC->CH[i].PSELP = AnalogueChannelP << SAADC_CH_PSELP_PSELP_Pos;
       NRF_SAADC->CH[i].PSELN = AnalogueChannelN << SAADC_CH_PSELN_PSELN_Pos;
       // Note the SAMPLE task must be triggered 2^OVERSAMPLE times for each output value
       NRF_SAADC->OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Over32x;
       // Enable SAADC
       NRF_SAADC->ENABLE = 1;
       NRF_SAADC->RESULT.PTR = (uint32_t)buffer;
       NRF_SAADC->RESULT.MAXCNT = 1;
       //NRF_SAADC->RESULT.AMOUNT
       // Do an initial calibration as the offset shows up in comparing +ve and -ve current measurements
       // Any gain changes require recalibration
       if(!mAmCalibrated)
       {
          NRF_SAADC->EVENTS_CALIBRATEDONE = 0;
          NRF_SAADC->TASKS_CALIBRATEOFFSET = 1;
          while (!NRF_SAADC->EVENTS_CALIBRATEDONE) ;
          mAmCalibrated = true;
          // Clear event, though maybe not actually necessary
          NRF_SAADC->EVENTS_CALIBRATEDONE = 0;
       }
       NRF_SAADC->EVENTS_END = 0;
       NRF_SAADC->EVENTS_DONE = 0;
       NRF_SAADC->EVENTS_RESULTDONE = 0;
       NRF_SAADC->TASKS_START = 1;
       // Assume could be up to 256 samples, but don't bother to check actual number
       mSaadcSampleCount = 0;
       while(true)
       {
          NRF_SAADC->TASKS_SAMPLE = 1;
          __DSB();
          while(!NRF_SAADC->EVENTS_DONE) ;
          // Update sample count for reports
          mSaadcSampleCount++;
          if (NRF_SAADC->EVENTS_RESULTDONE || timeout == 0) break;
          NRF_SAADC->EVENTS_DONE = 0;
          timeout--;
       }
       // Don't need NRF_SAADC->EVENTS_END for now
       NRF_SAADC->TASKS_STOP = 1;
       NRF_SAADC->EVENTS_STARTED = 0;
       NRF_SAADC->EVENTS_END = 0;
       NRF_SAADC->EVENTS_DONE = 0;
       NRF_SAADC->EVENTS_RESULTDONE = 0;
       // Disable command
       NRF_SAADC->ENABLE = 0;
       if (timeout != 0)
       {
          // Calculate mVolt value with rounding, assume 16-bit unsigned for prints
          result = (uint16_t)((((int32_t)buffer[0] * 1000L)+(SAADC_COUNTS_PER_VOLT_SE/2)) / SAADC_COUNTS_PER_VOLT_SE);
       }
       if (AnalogueChannelN == SAADC_CH_PSELN_PSELN_NC)
       {
          // Display in mVolts
          return result;
       }
       else
       {
          // Display and calculate in signed SAADC counts for best resolution
          return buffer[0];
       }
    }
    
    #define AVERAGING_NUMBER  4 // Averaging now also done with SAADC oversampling
    #define REPORTS_NUMBER    8 // Numer of printed results for analysis
    const float Rref_Ohm  = 2001.4f;  // Ohm
    const float Rtest_Ohm =  905.0f;  //  905.0 Ohm, 1597.3 Ohm, 2984.6 Ohm.
    float Rrtd = 0.0f;
    float Rrtd_Sum = 0.0f;
    float Vrtd_f = 0.0f;
    float Vref_f = 0.0f;
    
    void Test2WireRTD_ResistanceMeasurement(void)
    {
       char RtdInfoPacket[240] = "?";
       int16_t BatteryVolts0 = 0, BatteryVolts1 = 0, BatteryVolts2 = 0, BatteryVolts3 = 0;
       mClocksInit();
       mRtcInit();
       // Take some samples forward current and then some reverse
       for (uint32_t SampleCount=0; SampleCount<REPORTS_NUMBER; SampleCount++)
       {
          int32_t Vrtd = 0;
          int32_t Vref = 0;
          uint32_t FET_RdsOnA = 1;
          // Configuration               Direction                Input                          Pullup                 Drive Level        Sense Level
          // ==========================  =======================  =============================  =====================  =================  =======================
          nrf_gpio_cfg(PIN_EXCITATION_A, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL,   NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
          // Turn on forward current through RTD and Reference
          nrf_gpio_pin_set(PIN_EXCITATION_A);
          if (SampleCount == 0)
          {
             snprintf(RtdInfoPacket, sizeof(RtdInfoPacket)-1, "\r\n// Internal 0.6v Ref %s S0S1 2-Wire RTD actual value %0.1f Ohm (reference %0.1f Ohm) - Pos-Neg ADC\r\n", SAADC_ResolutionStr, Rtest_Ohm, Rref_Ohm);
             uartSend(RtdInfoPacket, strlen(RtdInfoPacket));
             snprintf(RtdInfoPacket, sizeof(RtdInfoPacket)-1, "// VDD mV Iref uA  RdsOn  V1 mV V2 mV V3 mV    Vrtd    Vref   Rrtd  Error\r\n");
             uartSend(RtdInfoPacket, strlen(RtdInfoPacket));
             snprintf(RtdInfoPacket, sizeof(RtdInfoPacket)-1, "// ====== ======= ======  ===== ===== =====  ======  ====== ====== ======\r\n");
             uartSend(RtdInfoPacket, strlen(RtdInfoPacket));
          }
          else if (SampleCount == REPORTS_NUMBER/2)
          {
             snprintf(RtdInfoPacket, sizeof(RtdInfoPacket)-1, "//\r\n// Internal 0.6v Ref %s S0S1 2-Wire RTD actual value %0.1f Ohm (reference %0.1f Ohm) - Neg-Pos ADC\r\n", SAADC_ResolutionStr, Rtest_Ohm, Rref_Ohm);
             uartSend(RtdInfoPacket, strlen(RtdInfoPacket));
             snprintf(RtdInfoPacket, sizeof(RtdInfoPacket)-1, "// VDD mV Iref uA  RdsOn  V1 mV V2 mV V3 mV    Vrtd    Vref   Rrtd  Error\r\n");
             uartSend(RtdInfoPacket, strlen(RtdInfoPacket));
             snprintf(RtdInfoPacket, sizeof(RtdInfoPacket)-1, "// ====== ======= ======  ===== ===== =====  ======  ====== ====== ======\r\n");
             uartSend(RtdInfoPacket, strlen(RtdInfoPacket));
          }
          // Short arbitrary delay to allow current to stabalise after turning on
          for (uint32_t i=0; i<10000UL; i++) {}
          // Differential RTD and reference resistor voltage values
          Vrtd = 0;
          Vref = 0;
          // Request a recalibration on any gain or mode changes
          RequestCalibration();
          for (uint32_t i=0; i<AVERAGING_NUMBER; i++)
          {
             // Differential measurements Pos-Neg or Neg-Pos
             if (SampleCount < REPORTS_NUMBER/2)
             {
                Vrtd += GetRTD_Voltage(SAADC_CH_PSELP_PSELP_AnalogInput5, SAADC_CH_PSELP_PSELP_AnalogInput7);
                Vref += GetRTD_Voltage(SAADC_CH_PSELP_PSELP_AnalogInput4, SAADC_CH_PSELP_PSELP_AnalogInput5);
             }
             else
             {
                Vrtd += GetRTD_Voltage(SAADC_CH_PSELP_PSELP_AnalogInput7, SAADC_CH_PSELP_PSELP_AnalogInput5);
                Vref += GetRTD_Voltage(SAADC_CH_PSELP_PSELP_AnalogInput5, SAADC_CH_PSELP_PSELP_AnalogInput4);
             }
          }
          Vrtd_f = Vrtd /(float)AVERAGING_NUMBER;
          Vref_f = Vref /(float)AVERAGING_NUMBER;
          // Keep using integer value for current
          Vref /= AVERAGING_NUMBER;
          // Differential measurements Pos-Neg or Neg-Pos, compensate for pseudo-negative
          if (SampleCount >= REPORTS_NUMBER/2)
          {
             Vrtd_f = 0.0f - Vrtd_f;
             Vref_f = 0.0f - Vref_f;
             Vref   = 0 - Vref;
          }
          // Request a recalibration on any gain or mode changes
          RequestCalibration();
          // Single-ended measurement voltages for testing
          BatteryVolts0 = GetRTD_Voltage(SAADC_CH_PSELP_PSELP_VDD, SAADC_CH_PSELN_PSELN_NC);
          BatteryVolts1 = GetRTD_Voltage(SAADC_CH_PSELP_PSELP_AnalogInput4, SAADC_CH_PSELN_PSELN_NC);
          BatteryVolts2 = GetRTD_Voltage(SAADC_CH_PSELP_PSELP_AnalogInput5, SAADC_CH_PSELN_PSELN_NC);
          BatteryVolts3 = GetRTD_Voltage(SAADC_CH_PSELP_PSELP_AnalogInput7, SAADC_CH_PSELN_PSELN_NC);
          // Rrtd = (Vrtd_f * Rref)/Vref Ohms
          float Rrtd = (Vrtd_f * Rref_Ohm)/Vref_f;
          // Accumulate for sum of both forward and reverse measurements
          Rrtd_Sum += Rrtd;
          // Calculate % error
          mMeasurementError = (Rrtd - Rtest_Ohm) * 100.0f/Rtest_Ohm;
          // Calculate mVolt value of Vref using rounding, differential mode
          uint32_t Vref_mV = (((Vref * 1000)+(SAADC_COUNTS_PER_VOLT_DIFF/2)) / SAADC_COUNTS_PER_VOLT_DIFF);
          // Current Iref = Vref/Rref  uA
          uint32_t Iref_uA = (uint32_t)roundf((Vref_mV * 1000)/Rref_Ohm);
          // RdsOn = Vref_mV/Iref_uA Ohms
          FET_RdsOnA = ((BatteryVolts0 - BatteryVolts1) * 1000) / Iref_uA;
          snprintf(RtdInfoPacket, sizeof(RtdInfoPacket)-1, "//  %5hd   %5u  %5u  %5hd %5hd %5hd  %6.1f  %6.1f %6.1f % 0.2f%%\r\n", BatteryVolts0, Iref_uA, FET_RdsOnA, BatteryVolts1, BatteryVolts2, BatteryVolts3, Vrtd_f, Vref_f, Rrtd, mMeasurementError);
          uartSend(RtdInfoPacket, strlen(RtdInfoPacket));
       }
       // Accumulate for sum of both forward and reverse measurements
       Rrtd_Sum /= (float)REPORTS_NUMBER;
       // Calculate % error
       mMeasurementError = (Rrtd_Sum - Rtest_Ohm) * 100.0f/Rtest_Ohm;
       // Measured 12-bit value of 905.0 Ohm test resistor is 905.2 Ohms with  0.02% error
       // Measured 12-bit value of 2984.6 Ohm test resistor is 2984.3 Ohms with -0.01% error
       snprintf(RtdInfoPacket, sizeof(RtdInfoPacket)-1, "//\r\n// Measured %s value of %4.1f Ohm 2-Wire test resistor using %u samples is %4.1f Ohms with % 0.2f%% error\r\n", SAADC_ResolutionStr, Rtest_Ohm, mSaadcSampleCount*AVERAGING_NUMBER, Rrtd_Sum, mMeasurementError);
       uartSend(RtdInfoPacket, strlen(RtdInfoPacket));
       // Hold
       while(true) {}
    }
    

    So the (other) two ways to improve 2-wire results are to either have a separate differential channel to measure another calibration resistor in both forward and reverse current directions which allows calculation of the residual offset, and the best way I'll post separately with a schematic/circuit diagram as this post is getting a bit long. This last method gives the best results available for the SAADC in 4-wire or 2-wire mode (tomorrow maybe).

Reply
  • I tested with 2-wire RTD and as expected the results are much poorer and vary from calibration to calibration as the residual offset is not handled. There are two ways to address that.

    Edit: 3 ways. I got quite good results by simply reversing the differential pin selection on the SAADC (no hardware change) to compensate for the residual SAADC offset: Updated results

    Measured 14-bit value of 905.0 Ohm 2-Wire test resistor is 905.3 Ohms with  0.03% error and much better stability/repeatability:

    // Internal 0.6v Ref 14-bit S0S1 2-Wire RTD actual value 905.0 Ohm (reference 2001.4 Ohm) - Pos-Neg ADC
    // VDD mV Iref uA  RdsOn  V1 mV V2 mV V3 mV    Vrtd    Vref   Rrtd  Error
    // ====== ======= ======  ===== ===== =====  ======  ====== ====== ======
    //   2983    1510     29   2939   923     4  3098.8  6878.1  901.7 -0.37%
    //   2983    1516     27   2942   914    -2  3124.2  6906.0  905.4  0.04%
    //   2973    1513     25   2934   911    -2  3110.4  6892.0  903.2 -0.19%
    //   2985    1515     33   2935   918     2  3123.8  6903.0  905.7  0.08%
    //
    // Internal 0.6v Ref 14-bit S0S1 2-Wire RTD actual value 905.0 Ohm (reference 2001.4 Ohm) - Neg-Pos ADC
    // VDD mV Iref uA  RdsOn  V1 mV V2 mV V3 mV    Vrtd    Vref   Rrtd  Error
    // ====== ======= ======  ===== ===== =====  ======  ====== ====== ======
    //   2981    1517     34   2929   911    -1  3134.1  6912.8  907.4  0.27%
    //   2979    1514     28   2936   910     0  3121.4  6899.7  905.4  0.05%
    //   2978    1514     24   2941   918     1  3121.7  6899.3  905.6  0.06%
    //   2981    1517     27   2939   918     4  3135.8  6912.8  907.9  0.32%
    //
    // Measured 14-bit value of 905.0 Ohm 2-Wire test resistor is 905.3 Ohms with  0.03% error
    

    The schematic/Circuit diagram:

    // RTD Measurement - 2- and 3-wire Unidirectional current
    //                          + -------------------------------------------------------------------+
    //                          |  nRF52832/nRF52833/nRF52840                                        |
    //                          |                                                                    |
    //                          |    VDD               VDD                 VDD                       |
    //                          |   --#--             --#--               --#--                      |
    //                          |     |                 |                   |                        |
    //                          |    _|__               |   Excitation      |   Option               |
    //                          |    / \                +-|   On            +-|   13k                |
    //                          |   /-+-\                 |<- H0   H1         |<- Pullup             |
    //                          |     |                 +-|   160R 35R      +-|   (not used)         |
    //         Excitation  P0.04|     |                 |                   |                        |
    //         +----------------O-----#------#----------#-------------------#------------ In         |
    //         |                |     |      |          |   Excitation      |   Option               |
    //         |                |   __|__  -----        +-|   Off           +-|   13k                |
    //         |                |    / \   -----          |<- L0   L1         |<- Pulldown           |
    //         |                |   /-+-\    |3pF       +-|   160R 35R      +-|   (not used)         |
    //         |                |     |      |          |                   |                        |
    //         |                |   =====  =====      =====               =====                      |
    //         |                |    ===    ===        ===                 ===                       |
    //         |                |     =      =          =                   =                        |
    //         |                |                                                                    |
    //         |                |    VDD                                      VDD                    |
    //         |                |   --#--                                    --#--                   |
    //         |                |    _|__                                      |   160k              |
    //         |                |    / \                                       +-| Bias Hi/Lo/Both   |
    //         |                |   /-+-\                                        |<-                 |
    //         |                |     |   PIN_VOLTAGE_1                        +-|                   |
    //         |          P0.28 |     |   AIN4         |----'T'-Mux-----|      |            P SAADC  |
    //         #--------#-------O-----#-----#----------+ +----#-------+ +--#---#------#------#-->    |
    //         |        |       |     |     |          | |    |       | |  |   |      |      |       |
    //         |        |       |   __|__ -----        ----   +-|    ----- |   +-|   +++     |       |
    //         |        |       |    / \  -----         |       |<--+  |   |     |<- | |   -----     |
    //  Rref  +++ 100nF |       |   /-+-\   |3pF        |     +-|   |  |   |   +-|   | |   -----     |
    //  2k0   | |     -----     |     |     |           +---- |--------#   |   |     +++     | 2.5pF |
    //  1%    | |     -----     |   ===== =====               |     |  |   |   |      |1M0   |       |
    // (0.1%) +++       |       |    ===   ===              =====   |  |   | =====  =====  =====     |
    //         |        |       |     =     =                ===    |  |   |  ===    ===    ===      |
    //         |        |       |                             =    Select  |   =      =      =       |
    //         |        |       |         PIN_VOLTAGE_2                    |                         |
    //         |        | P0.29 |         AIN5         |----'T'-Mux-----|  |                         |
    //         #--------#-------O-----#-----#----------+ +----#-------+ +--#  VDD                    |
    //         |        |       |                                          | --#--                   |
    //    RTD +++ 100nF |       |                                          |   |   160k              |
    //        | |     -----     |                                          |   +-| Bias Hi/Lo/Both   |
    //        | |     -----     |                                          |     |<-                 |
    //        +++       |       |         PIN_VOLTAGE_3                    |   +-|                   |
    //         |        | P0.31 |         AIN7         |----'T'-Mux-----|  |   |            N SAADC  |
    //         #--------#-------O-----#-----#----------+ +----#-------+ +--#~~~#------#------#-->    |
    //         |                |                 Note V3 can be negative  |   |      |      |       |
    //         |                |                                          |   +-|   +++     |       |
    //         |          VDD   |    VDD                                   |     |<- | |   -----     |
    //         |         --#--  |     |                                    |   +-|   | |   -----     |
    //         |           +----O-----#   PIN_VOLTAGE_0                    |   |     +++     | 2.5pF |
    //         |                |     |   AIN_VDD      |----'T'-Mux-----|  |   |      |1M0   |       |
    //         |                |     +-----#----------+ +----#-------+ +--+ =====  =====  =====     |
    //         |                |                                             ===    ===    ===      |
    //         |                |                                              =      =      =       |
    //         |                |    GND                                       P: Single-ended       |
    //         #----------------O-----+                                        P&N: Differential     |
    //         |                |     |                                                              |
    //       =====              |   =====                                                            |
    //        ===               |    ===                                                             |
    //         =                |     =                                                              |
    //                          +--------------------------------------------------------------------+
    //
    // Capacitor min value = (3pF+2.5pF)*2^14=80nF
    // Vref = differential voltage V1 and V2 in SAADC counts
    // Vrtd = differential voltage V2 and V3 in SAADC counts
    // Rrtd = (Vrtd * Rref)/Vref Ohms
    

    The code:

    #define SAADC_RESOLUTION_VAL   SAADC_RESOLUTION_VAL_14bit  // 12- or 14-bit in this code
    #define PIN_EXCITATION_A  4 // Red lead A to remote RTD
    //      PIN_VOLTAGE_0   VDD // VDD as source of excitation
    #define PIN_VOLTAGE_1    28 // AIN4 White lead from remote RTD (PIN_EXCITATION_A end)
    #define PIN_VOLTAGE_2    29 // AIN5 White lead from remote RTD (PIN_EXCITATION_B end)
    #define PIN_VOLTAGE_3    31 // AIN7 Red lead B to remote RTD and Reference resistor
    #define PIN_VOLTAGE_4    30 // AIN6 Reference resistor and PIN_EXCITATION_B
    
    // Input range = (VDD/4V)/(1/6) = 4.5 V with VDD=3V VDD/4 Ref do not use 100nF caps
    // Input range = (0.6 V)/(1/6)  = 3.6 V with 100nF caps regardless of VDD
    // Differential mode has 1 bit less than single-ended due to sign bit
    #if (SAADC_RESOLUTION_VAL == SAADC_RESOLUTION_VAL_12bit)
     #define SAADC_COUNTS_PER_VOLT_SE   1138  // 12-bit Mode Singe-ended:  4096/3.6V
     #define SAADC_COUNTS_PER_VOLT_DIFF  569  // 12-bit Mode Differential: 2048/3.6V
     const uint8_t SAADC_ResolutionStr[] = "12-bit";
    #elif (SAADC_RESOLUTION_VAL == SAADC_RESOLUTION_VAL_14bit)
     #define SAADC_RESOLUTION_VAL SAADC_RESOLUTION_VAL_14bit
     #define SAADC_COUNTS_PER_VOLT_SE   4551  // 14-bit Mode Singe-ended: 16384/3.6V
    // #define SAADC_COUNTS_PER_VOLT_DIFF 2276  // 14-bit Mode Differential: 8192/3.6V
     #define SAADC_COUNTS_PER_VOLT_DIFF 3413  // 14-bit Mode Differential: 8192/2.4V
     const uint8_t SAADC_ResolutionStr[] = "14-bit";
    #else
     #error SAADC_RESOLUTION_VAL   not 12- or 14-bit in this code
    #endif
    
    // Do an initial calibration as the offset shows up in comparing +ve and -ve current measurements
    static bool mAmCalibrated = false;
    static float mMeasurementError = 0.0f;
    
    static void RequestCalibration(void)
    {
       // Request a recalibration on any gain or mode changes
       mAmCalibrated = false;
    }
    
    // The accumulator is controlled in the OVERSAMPLE register. When using oversampling, 2^OVERSAMPLE input
    // samples are averaged before the sample result is transferred to memory. Hence, the SAMPLE task must be
    // triggered 2^OVERSAMPLE times for each output value
    static int16_t GetRTD_Voltage(uint32_t AnalogueChannelP, uint32_t AnalogueChannelN)
    {
       uint16_t result = 9999;
       uint32_t timeout = 512;
       volatile int16_t buffer[8];
       uint32_t i=0;  // SAADC Channel
       // Can use internal ref SAADC_CH_CONFIG_REFSEL_Internal with 100nF caps or VDD ratiometric SAADC_CH_CONFIG_REFSEL_VDD1_4 with no caps
       // Check if single-ended or differential SAADC mode
       if (AnalogueChannelN == SAADC_CH_PSELN_PSELN_NC)
       {
          // Configure SAADC singled-ended channel, Internal reference (0.6V) and 1/6 gain (range 3.6V), no pull-up or pull-down
          NRF_SAADC->CH[i].CONFIG = (SAADC_CH_CONFIG_GAIN_Gain1_6    << SAADC_CH_CONFIG_GAIN_Pos)   |
                                    (SAADC_CH_CONFIG_MODE_SE         << SAADC_CH_CONFIG_MODE_Pos)   |
                                    (SAADC_CH_CONFIG_REFSEL_Internal << SAADC_CH_CONFIG_REFSEL_Pos) |
                                    (SAADC_CH_CONFIG_RESN_Bypass     << SAADC_CH_CONFIG_RESN_Pos)   |
                                    (SAADC_CH_CONFIG_RESN_Bypass     << SAADC_CH_CONFIG_RESP_Pos)   |
                                    (SAADC_CH_CONFIG_TACQ_10us       << SAADC_CH_CONFIG_TACQ_Pos);
       }
       else
       {
          // Configure SAADC differential channel, Internal reference (0.6V) and 1/4 gain (range 2.4V), no pull-up or pull-down
          NRF_SAADC->CH[i].CONFIG = (SAADC_CH_CONFIG_GAIN_Gain1_4    << SAADC_CH_CONFIG_GAIN_Pos)   |
                                    (SAADC_CH_CONFIG_MODE_Diff       << SAADC_CH_CONFIG_MODE_Pos)   |
                                    (SAADC_CH_CONFIG_REFSEL_Internal << SAADC_CH_CONFIG_REFSEL_Pos) |
                                    (SAADC_CH_CONFIG_RESN_Bypass     << SAADC_CH_CONFIG_RESN_Pos)   |
                                    (SAADC_CH_CONFIG_RESN_Bypass     << SAADC_CH_CONFIG_RESP_Pos)   |
                                    (SAADC_CH_CONFIG_TACQ_10us       << SAADC_CH_CONFIG_TACQ_Pos);
       }
       NRF_SAADC->RESOLUTION = SAADC_RESOLUTION_VAL << SAADC_RESOLUTION_VAL_Pos;
       // Analog positive and negative input channels have strange numbering:
       //  PSELP_NC           0UL  Not connected
       //  PSELP_AnalogInput0 1UL  AIN0
       //  PSELP_AnalogInput1 2UL  AIN1
       //  PSELP_AnalogInput2 3UL  AIN2
       //  PSELP_AnalogInput3 4UL  AIN3
       //  PSELP_AnalogInput4 5UL  AIN4
       //  PSELP_AnalogInput5 6UL  AIN5
       //  PSELP_AnalogInput6 7UL  AIN6
       //  PSELP_AnalogInput7 8UL  AIN7
       //  PSELP_VDD          9UL  VDD
       NRF_SAADC->CH[i].PSELP = AnalogueChannelP << SAADC_CH_PSELP_PSELP_Pos;
       NRF_SAADC->CH[i].PSELN = AnalogueChannelN << SAADC_CH_PSELN_PSELN_Pos;
       // Note the SAMPLE task must be triggered 2^OVERSAMPLE times for each output value
       NRF_SAADC->OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Over32x;
       // Enable SAADC
       NRF_SAADC->ENABLE = 1;
       NRF_SAADC->RESULT.PTR = (uint32_t)buffer;
       NRF_SAADC->RESULT.MAXCNT = 1;
       //NRF_SAADC->RESULT.AMOUNT
       // Do an initial calibration as the offset shows up in comparing +ve and -ve current measurements
       // Any gain changes require recalibration
       if(!mAmCalibrated)
       {
          NRF_SAADC->EVENTS_CALIBRATEDONE = 0;
          NRF_SAADC->TASKS_CALIBRATEOFFSET = 1;
          while (!NRF_SAADC->EVENTS_CALIBRATEDONE) ;
          mAmCalibrated = true;
          // Clear event, though maybe not actually necessary
          NRF_SAADC->EVENTS_CALIBRATEDONE = 0;
       }
       NRF_SAADC->EVENTS_END = 0;
       NRF_SAADC->EVENTS_DONE = 0;
       NRF_SAADC->EVENTS_RESULTDONE = 0;
       NRF_SAADC->TASKS_START = 1;
       // Assume could be up to 256 samples, but don't bother to check actual number
       mSaadcSampleCount = 0;
       while(true)
       {
          NRF_SAADC->TASKS_SAMPLE = 1;
          __DSB();
          while(!NRF_SAADC->EVENTS_DONE) ;
          // Update sample count for reports
          mSaadcSampleCount++;
          if (NRF_SAADC->EVENTS_RESULTDONE || timeout == 0) break;
          NRF_SAADC->EVENTS_DONE = 0;
          timeout--;
       }
       // Don't need NRF_SAADC->EVENTS_END for now
       NRF_SAADC->TASKS_STOP = 1;
       NRF_SAADC->EVENTS_STARTED = 0;
       NRF_SAADC->EVENTS_END = 0;
       NRF_SAADC->EVENTS_DONE = 0;
       NRF_SAADC->EVENTS_RESULTDONE = 0;
       // Disable command
       NRF_SAADC->ENABLE = 0;
       if (timeout != 0)
       {
          // Calculate mVolt value with rounding, assume 16-bit unsigned for prints
          result = (uint16_t)((((int32_t)buffer[0] * 1000L)+(SAADC_COUNTS_PER_VOLT_SE/2)) / SAADC_COUNTS_PER_VOLT_SE);
       }
       if (AnalogueChannelN == SAADC_CH_PSELN_PSELN_NC)
       {
          // Display in mVolts
          return result;
       }
       else
       {
          // Display and calculate in signed SAADC counts for best resolution
          return buffer[0];
       }
    }
    
    #define AVERAGING_NUMBER  4 // Averaging now also done with SAADC oversampling
    #define REPORTS_NUMBER    8 // Numer of printed results for analysis
    const float Rref_Ohm  = 2001.4f;  // Ohm
    const float Rtest_Ohm =  905.0f;  //  905.0 Ohm, 1597.3 Ohm, 2984.6 Ohm.
    float Rrtd = 0.0f;
    float Rrtd_Sum = 0.0f;
    float Vrtd_f = 0.0f;
    float Vref_f = 0.0f;
    
    void Test2WireRTD_ResistanceMeasurement(void)
    {
       char RtdInfoPacket[240] = "?";
       int16_t BatteryVolts0 = 0, BatteryVolts1 = 0, BatteryVolts2 = 0, BatteryVolts3 = 0;
       mClocksInit();
       mRtcInit();
       // Take some samples forward current and then some reverse
       for (uint32_t SampleCount=0; SampleCount<REPORTS_NUMBER; SampleCount++)
       {
          int32_t Vrtd = 0;
          int32_t Vref = 0;
          uint32_t FET_RdsOnA = 1;
          // Configuration               Direction                Input                          Pullup                 Drive Level        Sense Level
          // ==========================  =======================  =============================  =====================  =================  =======================
          nrf_gpio_cfg(PIN_EXCITATION_A, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL,   NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
          // Turn on forward current through RTD and Reference
          nrf_gpio_pin_set(PIN_EXCITATION_A);
          if (SampleCount == 0)
          {
             snprintf(RtdInfoPacket, sizeof(RtdInfoPacket)-1, "\r\n// Internal 0.6v Ref %s S0S1 2-Wire RTD actual value %0.1f Ohm (reference %0.1f Ohm) - Pos-Neg ADC\r\n", SAADC_ResolutionStr, Rtest_Ohm, Rref_Ohm);
             uartSend(RtdInfoPacket, strlen(RtdInfoPacket));
             snprintf(RtdInfoPacket, sizeof(RtdInfoPacket)-1, "// VDD mV Iref uA  RdsOn  V1 mV V2 mV V3 mV    Vrtd    Vref   Rrtd  Error\r\n");
             uartSend(RtdInfoPacket, strlen(RtdInfoPacket));
             snprintf(RtdInfoPacket, sizeof(RtdInfoPacket)-1, "// ====== ======= ======  ===== ===== =====  ======  ====== ====== ======\r\n");
             uartSend(RtdInfoPacket, strlen(RtdInfoPacket));
          }
          else if (SampleCount == REPORTS_NUMBER/2)
          {
             snprintf(RtdInfoPacket, sizeof(RtdInfoPacket)-1, "//\r\n// Internal 0.6v Ref %s S0S1 2-Wire RTD actual value %0.1f Ohm (reference %0.1f Ohm) - Neg-Pos ADC\r\n", SAADC_ResolutionStr, Rtest_Ohm, Rref_Ohm);
             uartSend(RtdInfoPacket, strlen(RtdInfoPacket));
             snprintf(RtdInfoPacket, sizeof(RtdInfoPacket)-1, "// VDD mV Iref uA  RdsOn  V1 mV V2 mV V3 mV    Vrtd    Vref   Rrtd  Error\r\n");
             uartSend(RtdInfoPacket, strlen(RtdInfoPacket));
             snprintf(RtdInfoPacket, sizeof(RtdInfoPacket)-1, "// ====== ======= ======  ===== ===== =====  ======  ====== ====== ======\r\n");
             uartSend(RtdInfoPacket, strlen(RtdInfoPacket));
          }
          // Short arbitrary delay to allow current to stabalise after turning on
          for (uint32_t i=0; i<10000UL; i++) {}
          // Differential RTD and reference resistor voltage values
          Vrtd = 0;
          Vref = 0;
          // Request a recalibration on any gain or mode changes
          RequestCalibration();
          for (uint32_t i=0; i<AVERAGING_NUMBER; i++)
          {
             // Differential measurements Pos-Neg or Neg-Pos
             if (SampleCount < REPORTS_NUMBER/2)
             {
                Vrtd += GetRTD_Voltage(SAADC_CH_PSELP_PSELP_AnalogInput5, SAADC_CH_PSELP_PSELP_AnalogInput7);
                Vref += GetRTD_Voltage(SAADC_CH_PSELP_PSELP_AnalogInput4, SAADC_CH_PSELP_PSELP_AnalogInput5);
             }
             else
             {
                Vrtd += GetRTD_Voltage(SAADC_CH_PSELP_PSELP_AnalogInput7, SAADC_CH_PSELP_PSELP_AnalogInput5);
                Vref += GetRTD_Voltage(SAADC_CH_PSELP_PSELP_AnalogInput5, SAADC_CH_PSELP_PSELP_AnalogInput4);
             }
          }
          Vrtd_f = Vrtd /(float)AVERAGING_NUMBER;
          Vref_f = Vref /(float)AVERAGING_NUMBER;
          // Keep using integer value for current
          Vref /= AVERAGING_NUMBER;
          // Differential measurements Pos-Neg or Neg-Pos, compensate for pseudo-negative
          if (SampleCount >= REPORTS_NUMBER/2)
          {
             Vrtd_f = 0.0f - Vrtd_f;
             Vref_f = 0.0f - Vref_f;
             Vref   = 0 - Vref;
          }
          // Request a recalibration on any gain or mode changes
          RequestCalibration();
          // Single-ended measurement voltages for testing
          BatteryVolts0 = GetRTD_Voltage(SAADC_CH_PSELP_PSELP_VDD, SAADC_CH_PSELN_PSELN_NC);
          BatteryVolts1 = GetRTD_Voltage(SAADC_CH_PSELP_PSELP_AnalogInput4, SAADC_CH_PSELN_PSELN_NC);
          BatteryVolts2 = GetRTD_Voltage(SAADC_CH_PSELP_PSELP_AnalogInput5, SAADC_CH_PSELN_PSELN_NC);
          BatteryVolts3 = GetRTD_Voltage(SAADC_CH_PSELP_PSELP_AnalogInput7, SAADC_CH_PSELN_PSELN_NC);
          // Rrtd = (Vrtd_f * Rref)/Vref Ohms
          float Rrtd = (Vrtd_f * Rref_Ohm)/Vref_f;
          // Accumulate for sum of both forward and reverse measurements
          Rrtd_Sum += Rrtd;
          // Calculate % error
          mMeasurementError = (Rrtd - Rtest_Ohm) * 100.0f/Rtest_Ohm;
          // Calculate mVolt value of Vref using rounding, differential mode
          uint32_t Vref_mV = (((Vref * 1000)+(SAADC_COUNTS_PER_VOLT_DIFF/2)) / SAADC_COUNTS_PER_VOLT_DIFF);
          // Current Iref = Vref/Rref  uA
          uint32_t Iref_uA = (uint32_t)roundf((Vref_mV * 1000)/Rref_Ohm);
          // RdsOn = Vref_mV/Iref_uA Ohms
          FET_RdsOnA = ((BatteryVolts0 - BatteryVolts1) * 1000) / Iref_uA;
          snprintf(RtdInfoPacket, sizeof(RtdInfoPacket)-1, "//  %5hd   %5u  %5u  %5hd %5hd %5hd  %6.1f  %6.1f %6.1f % 0.2f%%\r\n", BatteryVolts0, Iref_uA, FET_RdsOnA, BatteryVolts1, BatteryVolts2, BatteryVolts3, Vrtd_f, Vref_f, Rrtd, mMeasurementError);
          uartSend(RtdInfoPacket, strlen(RtdInfoPacket));
       }
       // Accumulate for sum of both forward and reverse measurements
       Rrtd_Sum /= (float)REPORTS_NUMBER;
       // Calculate % error
       mMeasurementError = (Rrtd_Sum - Rtest_Ohm) * 100.0f/Rtest_Ohm;
       // Measured 12-bit value of 905.0 Ohm test resistor is 905.2 Ohms with  0.02% error
       // Measured 12-bit value of 2984.6 Ohm test resistor is 2984.3 Ohms with -0.01% error
       snprintf(RtdInfoPacket, sizeof(RtdInfoPacket)-1, "//\r\n// Measured %s value of %4.1f Ohm 2-Wire test resistor using %u samples is %4.1f Ohms with % 0.2f%% error\r\n", SAADC_ResolutionStr, Rtest_Ohm, mSaadcSampleCount*AVERAGING_NUMBER, Rrtd_Sum, mMeasurementError);
       uartSend(RtdInfoPacket, strlen(RtdInfoPacket));
       // Hold
       while(true) {}
    }
    

    So the (other) two ways to improve 2-wire results are to either have a separate differential channel to measure another calibration resistor in both forward and reverse current directions which allows calculation of the residual offset, and the best way I'll post separately with a schematic/circuit diagram as this post is getting a bit long. This last method gives the best results available for the SAADC in 4-wire or 2-wire mode (tomorrow maybe).

Children
No Data
Related