Calculating Accuracy of Basic ADC Circuit - Page 1
Forum section: electronics / beginners

author: bitshift
author_rank: Regular Contributor
timestamp: September 14, 2015, 06:41:31 pm
content: Hey guys,I'm trying to calculate the accuracy of a basic circuit depicted in the following schematic:A sine wave with a 250V amplitude and a 2.5V DC bias is attenuated by a factor of 101 by the resistor divider. The signal is then fed into a 12 bit ADC with a 5V reference.I would like to calculate the accuracy of this system with the following component specs:Resistors1% tolerance25 ppm per degree C tempco-25 to 85 degrees CVoltage Reference1% initial accuracy20 ppm per degree C tempco-25 to 85 degrees CADC+- 1 LSB INLIgnore offset and gain errorsThe error calculation for the voltage going into the ADC is as follows:Worst case resistance deviation = (1/100 + (85 - 25) * 25e-6) = 0.0115 or 1.15% // (where 1/100 is for 1% tolerance and (85 - 25) * 25e-6 is for temperature drift)Voltage into ADC = R2(1 - 0.0115) / (R1(1 + 0.0115) + R2(1 - 0.0115)) * Vin // Errors are given opposite signs for maximum deviation in the ratio of the resistors.The maximum error in the reference voltage would be:Worst Case Error in Reference Voltage = 5 * (1/100 + (85 - 25) * 20e-6) = 0.0262VI get lost when trying to calculate the total error. I am unsure how to tie in the error from the voltage reference to the +- 1 LSB INL of the ADC. How would one go about computing the total error?

author: JoeN
author_rank: Frequent Contributor
timestamp: September 14, 2015, 07:51:33 pm
content: I am not an expert but I will say it seems you are telling the simulation that your reference is only good to 1%. 1% is going to be a big error margin for even a lowly 12 bit ADC. That's 2048/100 = 20 LSBs, right? Who cares if the ADC is accurate to 1 LSB if your reference is off by 20 LSB. Now, of course if that is a really decent reference like an ADR45xx, ADR4xx (or equivalent from Linear, TI, etc) you can trim it to a very accurate and stable voltage far better than 1% (probably better than .01%) with an op-amp and I am sure make it better than that 12 bit ADC. Then the ADC will be the limiting factor, not the reference. Then I think you would want to provide the simulation with the real error margin on your reference for calculation.Just a guess.

author: michaeliv
author_rank: Frequent Contributor
timestamp: September 14, 2015, 08:32:20 pm
content: Ex: Your voltage is 100.000000VYou are looking for the worst case scenario which would happen if:Temperature is at 85c - Tolerance of resistors becomes 1.0115%R1 is 1011500 OhmR2 is 9885 Ohm- Voltage is now 0.968v , 3.2% off of expected 1VVoltage reference Is 1.0112% including temp coefficient, voltage is 5.056 instead of 5vYour ADC will measure the voltage and find it to be 0.1914556962 of the reference voltage and it will ideally report it as 784 out of the 4096 steps it has.But because it has 1 LSB accuracy, it will report it as 783.You will interpret the result as 783/4096 * 5v = 0.955810545, which give you a total error of 4.4189455%PS that's not the worse case, but very close to it. To find the worse case, you need to increase the input voltage a bit above 100V (and have the output remain the same). Then you will get the maximum error.

author: JoeN
author_rank: Frequent Contributor
timestamp: September 15, 2015, 12:15:26 am
content: 4096 steps not 2048, sorry, I got was off by one power there.

author: bitshift
author_rank: Regular Contributor
timestamp: September 15, 2015, 06:43:07 am
content: Thank you for the explanation michaelivFollowing the same example with a much smaller voltage:Voltage = 10VDue to tolerance in resistors voltage into the ADC is now 0.0968v , 3.2% off of expected 0.1V.With the voltage reference at the worst case 5.056V the ADC will see 0.0191455696202532 of the reference voltage. It will report 78/4096 but because of the +- 1 LSB INL it will report 77/4096. The result will be interpreted as 5 * 77 / 4096 = 0.093994140625V making the error roughly 6%.This makes sense to me since as the voltage at the ADC gets closer to 0, the +- 1 LSB INL will make a larger and larger impact on the measured voltage. How would you then characterize the error of the entire system?To give a bit more context, I'm using this scheme to measure the RMS voltage of the sine wave. I would like to write down equations for the errors to aid in choosing components to meet a spec.

author: michaeliv
author_rank: Frequent Contributor
timestamp: September 15, 2015, 08:21:38 am
content: So, If I'm understanding it correctly, you're sampling the sine wave and trying to calculate the RMS voltage from multiple samples ?The max error then depends on more things, like the sampling rate of the ADC.Ex if your sampling rate is the same or less than the AC frequency, the max error will be 100% since you might be measuring only exactly when the sine wave goes through 0.It also depends on the formula you're using - Bigger % errors at smaller voltages won't contribute too much to the result ... depending on how the formula handles them.Also, you can improve the accuracy by not dividing the voltage by 100, but by 50-60, to maximize the usage of the ADC's range.For your current design the accuracy would be 4.2721519% (if the ADC had infinite precision + bit depth).So your total accuracy would be 4.2721519% + 1/4096 * ADC reference * resistor divider ratio =4.2721519% + 1.22070312mV * 1004.2721519% +- 0.122070312V

author: bitshift
author_rank: Regular Contributor
timestamp: September 15, 2015, 08:35:03 am
content: Thanks michaeliv, I appreciate your help so far.Quote from: michaeliv on September 15, 2015, 08:21:38 amYesQuote from: michaeliv on September 15, 2015, 08:21:38 amFrom my (very) limited understanding of the Nyquist sampling theorem, to faithfully measure the sine wave I need to sample it at a minimum of twice its frequency. In this case it's just a 50Hz sine wave so I will sample it at a frequency of at least 100Hz.Quote from: michaeliv on September 15, 2015, 08:21:38 amAaah this makes sense. The RMS voltage will be calculated using this formula:How do you calculate the total error in the RMS voltage knowing that the error depends on the voltage level?Quote from: michaeliv on September 15, 2015, 08:21:38 amIn this case I am using 100% of the range of the ADC already. The sine wave is DC biased around 2.5V with a max peak of 250V.Quote from: michaeliv on September 15, 2015, 08:21:38 amHow did you get 4.2721519%?

author: michaeliv
author_rank: Frequent Contributor
timestamp: September 15, 2015, 09:18:18 am
content: Quote from: bitshift on September 15, 2015, 08:35:03 amDisclamer: I'm not familiar with advanced maths.But a 100Hz sine wave goes through 0V 100 times a second, so you might be sampling it exactly when it goes through 0 twice.But that does not really matter since it assumes that the sampling of your ADC is instantaneous.Assuming that the ADC takes some time to sample the voltage (which is likely since it's only 100hz ?) - to find the exact /100% correct accuracy of the real-world system you would have to do some very complex mathematics which involves the sine wave + knowledge of the internal architecture of the ADC, beyond what is in it's datasheet. This is because the ADC takes some time to measure the voltage - during which the voltage changes -- this can cause inaccurate measurements due to the architecture of the ADC.Basically, the datasheet of the ADC assumes that the input voltage is constant throughout the sampling period. Since it's not, the actual voltage that the ADC reports might be an average of the voltage during the sample period, or a value at a specific point in time during the conversion.BTW since you know it's a sine wave, why don't you just convert it to DC and measure the voltage and work your way back to the AC voltage ?Quote from: bitshift on September 15, 2015, 08:35:03 amYup, you're right, I missed that.Quote from: bitshift on September 15, 2015, 08:35:03 amIt's from the previous "With the voltage reference at the worst case 5.056V the ADC will see 0.0191455696202532 of the reference voltage..."0.0191455696202532 is 4.2721519% off from the expected 0.02V.

author: Jeroen3
author_rank: Super Contributor
timestamp: September 15, 2015, 09:46:13 am
content: An SAR ADC, the ones likely to be used if only 12 bit, contain a sample and hold. There is only a small moment in time the ADC is open to the input pin. That is when the sample&hold is refreshing. Next, the ADC completes a conversion in several uS.The input pin is not directly connector to the converter.I've just recently played around with 50 Hz signal input into the ADC, do some filtering, and DAC output.It looks like this, with 1Khz samplerate.There is no challenge in rectifying the signal. It moves the measurement to the analog domain, requiring more components and calibration. But it is easier.You can already software rectify to get the pk-pk values and calculate back to rms. Determining the frequency requires more than an fs of 1 kHz. At least if you don't want to average the frequency over a longer period of time.

author: BravoV
author_rank: Super Contributor
timestamp: September 15, 2015, 09:49:56 am
content: Assuming its not for education or fun in building this RMS converter from the scratch, why not using RMS -> DC converter chip ? There are plenty of choices out there.

author: tszaboo
author_rank: Super Contributor
timestamp: September 15, 2015, 09:53:50 am
content: You forgot input protection. Go back to the drawing table, and design it there. It makes a huge difference. Leakage current of a small signal low leakage diode, a TVS diode. It can dominate the error sources.

author: bitshift
author_rank: Regular Contributor
timestamp: September 15, 2015, 10:20:05 am
content: Quote from: BravoV on September 15, 2015, 09:49:56 amThis is for fun. I'm building a digital wattmeter but I would like to keep it as low cost as possibleQuote from: NANDBlog on September 15, 2015, 09:53:50 amSomething like this after the resistor network?

author: Jeroen3
author_rank: Super Contributor
timestamp: September 15, 2015, 11:39:23 am
content: Also, the drawing above lacks an input buffer for the ADC. Go from the resistor divider to diodes, add some c's, and then into the opamp to create a low enough impedance signal for the ADC. Don't forget your anti-aliasing filter at 0.5*fs.

author: f5r5e5d
author_rank: Frequent Contributor
timestamp: September 15, 2015, 12:57:25 pm
content: much higher sample rates are used in practical circuitsoversampling simplifies the anti-alias input filter design, reduces sinc error if your math assumes ZOH, more samples averaged can reduce noise...and the processing power to do smarter algorithms with more data is cheap today

author: bitshift
author_rank: Regular Contributor
timestamp: September 15, 2015, 02:09:18 pm
content: Quote from: Jeroen3 on September 15, 2015, 11:39:23 amForgive me for asking a potentially silly question but why is it important for the ADC to see a low impedance signal. Is it so that enough current can flow to charge the sample and hold capacitor?EDIT:This is answered in thedatasheetof a microchip ADC I'm using:For the A/D converter to meet specification, the chargeholding capacitor (CSAMPLE) must be given enoughtime to acquire a 12-bit accurate voltage level duringthe 1.5 clock cycle sampling period. The analog inputmodel is shown in Figure 4-1.In this diagram, it is shown that the source impedance(RS) adds to the internal sampling switch (RSS) impedance, directly affecting the time that is required tocharge the capacitor, CSAMPLE. Consequently, largersource impedances increase the offset, gain, andintegral linearity errors of the conversion.Ideally, the impedance of the signal source should benear zero. This is achievable with an operationalamplifier such as the MCP601 which has a closed loopoutput impedance of tens of ohms. The adverse affectsof higher source impedances are shown in Figure 4-2.

author: dmills
author_rank: Super Contributor
timestamp: September 15, 2015, 04:54:37 pm
content: There is one other elephant in the room.You say you are measuring the RMS value of a 50Hz sine? Would this be derived from the mains by any chance?The mains has non negligible voltage harmonic distortion (And loads often have major harmonic current content), so you probably want to be measuring out to at least the 10th harmonic, so maybe a 2KHz sample rate or so.If you were just measuring a literal sine wave, why would you bother doing complex RMS measurements, just measure the peak and calculate the RMS as you know the waveform.....The condition of sufficiency in the sampling theorem is 'sample rate strictlygreaterthen twice the bandwidth', 100Hz sampling a 50Hz signal does not suffice for this, 101Hz does, but the maths gets hairy.Regards, Dan.

author: Jeroen3
author_rank: Super Contributor
timestamp: September 15, 2015, 08:14:48 pm
content: The voltage fundamental is easily cherry picked with some filters.With the current you should definitely take a look around the net for some scope images.Although your current transformer already reject a lot of the high frequency noise. There is still a lot more than only 50 Hz in your signal.Also, did you think of power factor measurement yet?This is considered a clean sine: (green is current)

author: bitshift
author_rank: Regular Contributor
timestamp: September 16, 2015, 05:40:59 am
content: Quote from: dmills on September 15, 2015, 04:54:37 pmIt is derived from mains. I'm trying to build a wattmeter for fun/educational purposes.Quote from: dmills on September 15, 2015, 04:54:37 pmThank you for this. I will take this into account and hopefully come up with a better device.Quote from: dmills on September 15, 2015, 04:54:37 pmThis is a fair point. I'm going to change the scope of the device to measure the power factor as Jeroen3 suggested.Thank you everyone for the help so farBack to the drawing board