5

I have question about the common formula used to turn analog input voltage of ADC into an integer binary number that is as bellow :

enter image description here

I think that in the equation above N is not integer but floating-point value. And also we can not consider [] as integral part function in this formula.

How is it turned into Integer number? do we have to use ceiling or floor function?

According to the graph bellow, I guess that we have to round it to the nearest integer number. For example if the N is 243.8 we should round it to 244 and if it was 243.2 we should round it to 243, So we should not use ceiling or floor function, right?

enter image description here

Edit: To better explain my mean i added this better demonstrating plot with its correspondent quantization error graph. Based on the quantization error plot, i guess the rounding function should be used instead of floor or ceiling. I mean that if every voltage value in range of [0, 1/8) was converted to 000, And every value in [1/8, 1/4) was converted to 001 and so on, Then using floor function was correct. But obviously some rounding is done, right?

enter image description here

Thanks in advance!

A.R.S.D.
  • 53
  • 4
  • 1
    N is an integer here – Scott Seidman Jun 15 '20 at 12:26
  • 1
    So do you mean that [] is integral part function? But i don't think so, because the fraction is normally something between 0 and 1. so the floor or integral part function of that is zero and ceiling is one. then the N is either 0 or pow(2, n) - 1. right? – A.R.S.D. Jun 15 '20 at 12:31
  • 3
    you're overthinking it. [] are brackets, drawn as square for the height. Given the division, they are in fact redundant, so they're only there, ironically, for clarity. In practice, given the other errors in a practical ADC, it doesn't matter whether you round, or take the ceiling or floor, the difference between those is smaller than the inherent errors in the ADC. – Neil_UK Jun 15 '20 at 12:44
  • 1
    Yes you are right but basically i just want to know which one is correct in theory, and as you said practically there is more error type with greater impact on ADC result, but i have to know which of rounding or ceiling or floor is correct in theory. – A.R.S.D. Jun 15 '20 at 12:49
  • The label 'LSB' in this plot is wrong - It's at 0.5 LSB. For an 3 bit ADC as shown, 1 LSB = 0.125 – asdfex Jun 15 '20 at 14:36
  • Does this answer your question? [Conversion formula for adc](https://electronics.stackexchange.com/questions/461847/conversion-formula-for-adc) –  Jun 15 '20 at 14:54
  • I reviewed that question but i think it is not the same as this one. Thanks! – A.R.S.D. Jun 15 '20 at 15:35
  • 2
    @A.R.S.D. : In the past, I had a long discussion regarding the subject, with TI engineers, including also Bonnie Baker and John Davies. To be short: Please, take a time to read my response here: electronics.stackexchange.com/a/387507/22676 – Dirceu Rodrigues Jr Jun 15 '20 at 19:43
  • I checked your answer and in my understandings you have used int() function, which is floor function right? To explain my mean better i have edited post and added new plot with corresponding quantization error graph, that as far as i can understand using floor function is not compatible with the quatization error graph. because based on the error graph the N is rounded to nearest quatization level. – A.R.S.D. Jun 16 '20 at 05:05
  • 1
    For a *theoretically perfect* ADC (which does not exist), then rounding the value is precise. Given, however, the errors in a practical ADC it makes little difference which function is used. – Peter Smith Jun 16 '20 at 14:50

3 Answers3

1

As comments have pointed out, ceiling or floor is irrelevant in practical applications. The error of the ADC will eclipse any accuracy gained in bit rounding. Offset error, gain error and integral non-linearity make such considerations theoretical at best. Observe the following graphic, courtesy of Microchip:

ADC Analog to Digital Conversion Error

For theoretical purposes, however, precision is everything. The equation writer assumes you will apply the rules of binary and significant figures correctly. They were probably an engineer. The result of the multiplication, following the rules of significant figures and decimal places, will give you an integer value. Continuing on the sig fig track, if you get a result of 0x56 for example, you might as well add +/- 0.5 on the end. Where does this precision limitation come from? The theoretical ADC itself! Forget rounding entirely. 4.6 and 5.1 are contained within 5 with a +/- 0.5 uncertainty.

Someone might raise the point that a theoretical computer value like 0x33 has infinite precision in a theoretical system, and they would be correct. However, analog-to digital converters suggest lossy conversion, just like going from 3D to 2D loses information. The equation you provided is not a conversion from analog to “digital”, it is a scaled projection onto a range. There are a lot of other things about the equation that have to be assumed as well, such as that negative binary values are not allowed and will clamp at zero or that values greater than 2^N-1 will clamp.

As written, yes I could end up with a decimal value of -34754863894389439842854843868385382809211111.8493629295749383 if I select the write parameters. To represent semiconductor shenanigans correctly in pure theoretical mathematics, a lot more notation would need to be added to the provided equation, but we don’t even like Maxwell’s equations as engineers, preferring abstractions wherever possible. That kind of persnickety math is exactly what the engineers who wrote that equation were trying to avoid, and to be honest, if they didn’t do so, I don’t think ADCs would be around for us to have this discussion. Mathematics is all made up; we might as well make it up useful.

So your result is neither floor nor ceiling. It’s the same as any digital result: a less precise (abstracted to use a computer term) version of a real-world quantity, just like a pixely picture of a person.

Hackstaar
  • 886
  • 6
  • 22
1

The "[]" is indeed integer part function. Although, the formula, as you also pointed out, seems incorrect. The output of ADC is an integer, which when multiplied by least-significant-bit (LSB) gives closest approximation of the analog input. Thus,
$$N = [\frac{V_{in} - V_{ref-}}{V_{LSB}}]$$ Putting the value of \$V_{LSB}\$, $$N = [\frac{(V_{in} - V_{ref-})(2^{n-bit} - 1)}{V_{ref+} - V_{ref-}}]$$ Thus, if you also move your first term inside the integer-part function. You will get the right result.

sarthak
  • 3,646
  • 4
  • 19
  • 31
  • But this way your using floor function which i think is incorrect with respect to provided plots, I suggest the right function that should be used is rounding function as we can see that the voltage is converted to the nearest voltage level and this is not always lower voltage level, right? – A.R.S.D. Jun 16 '20 at 14:24
0

I viewed and checked the answers, But unfortunately they didn't thoroughly satisfy my questions and doubts. So i decided to post what i reached to and conclusion.

In theory where the only error that could be faced is quantization error so the more precise way is to use rounding.

But in practise this considerations are not taken into account not because the effect of quantization error is negligible with respect to other errors (as some mentioned) but because this does not help to reach more precision model, in my understanding, To better explain it, I posted ADC error types listed in the figure:

enter image description here

As it is clear rounding when there is practical ADC which afflicted by either Linearity or Missing code error, does not help to make more precise model of ADC behaviour as ADC does not convert input voltages to digital levels which are closest to. Thus these kinds of errors affect the theoretical model which lead to inaccurate calculations. So none of rounding, flooring or ceiling functions could lead to best precise model of ADC in practise, As it was possible in theory by using rounding.

That's what was absent in comments and answers.

A.R.S.D.
  • 53
  • 4