double vDeltaRef, vPlusRef = 10, vMinusRef = 0, q, n, nExp = 3; vDeltaRef = vPlusRef - vMinusRef; n = Math.pow(2, nExp); q = vDeltaRef / n; System.out.println(q);
the result from the formula is 1.25v this value:
How can I translate the obtained result
Advertisement
Answer
Since you know vPlusRef
, vMinusRef
and nExp
, you can always calculate q
(which is 1.25
in this case).
Then, to convert from digital to analog simply multiply the digital value with q
. For example the 3-bit value 011
, which is 3
in decimal, will be converted to 3.75
which is the lower bound of the required range 3.75
to 5.00
.
Finally, to convert from analog to digital do:
int digitalValue = (int) Math.floor(analogValue / q);
For example an analog value of 8.19
would return 6
, which is the 3-bit value 110
.