SoI've made a primitive voltmeter using various bits of code
It works..
I have a dc voltage between a0 and gnd
this voltage is under 5v (under 2v actually
It sends it over serial 100 times a second
but because of the 10 bit ADC the resolution is only 5mv
I would like 1mv
I have read that I can do this by averaging the values
This is my first arduino project, I'm so pleased I got this bit to work on my own!
And can i somehow add say 10 values together and divide to give me more than 1024 possible values?
I think I would need 4096 or 8192 possible values (12 or 13 bits) to give me 1mv resolution at 0-5v possible less if we can reduce the reference voltage (0-2v I think would be 2048 values equivalent to 11 bits)
If you are only doing around 2 volts measurements then why not use an A:D internal reference?
do an internet search on words like "arduino uno internal reference." Gives links like: arduino uno - what is aref(analog reference) - Arduino Stack Exchange, words that can be read and contain info that is relevant to your posted desires. But getting 12 bits from a 10bit A:D, good luck.
On the Arduino, add up 64 measurements (as unsigned int), add 8 to round up, then divide by 16 to convert the range 0-1023 to 0-4095. This gives you 1.2 mV resolution per bit. It works as described in the note below on the ATmega328 (Arduino Uno and similar), but of course this severely limits the frequency response.
Thanks so much
This has helped a lot! I have set my bench psu to 2v and used that as the reference on the aref pin
and set analogReference(EXTERNAL)
results much more stable and at least double the resolution
A very good start to improving things Thankyou
Thankyou have corrected these mistakes! Cannot pretend to understand the article but will look into it.. I understand how averaging results can give a higher resolution (at least 1 bit extra is relatively easy) but still don't understand how to implement
So I have used this code in a new file with some of my code
Its seems to work however the first reading is correct 1.46volts
Subsequent readings are high by about 0.1 volts
see my code..
I'm now using a regulated bench supply for the reference voltage at 2.5 volts (set on the psu and tested with a DMM)
I have set reference to external and added a delay
If you want to try something else you can look towards the ADS1115 A/D used along with your Arduino. Simple, inexpensive and affords easily programmable gain. Just make sure you look to a reputable source as there are plenty of counterfeit modules floating around. Again, just something different to consider depending on exactly what you want or need.
Ron_Blain:
If you want to try something else you can look towards the ADS1115 A/D used along with your Arduino. Simple, inexpensive and affords easily programmable gain. Just make sure you look to a reputable source as there are plenty of counterfeit modules floating around. Again, just something different to consider depending on exactly what you want or need.
There is a lot of noise! none of the cables are shielded.. but the bench psu is very stable especially with no load!
The results are much better
I realise they may not be 'truly' 12 bits but its good enough
And I agree they do not need to be completely accurate - relative voltages
relatively trying to visualize the delta peak drop (or lack of) when battery is fully charged (a voltage drop of anywhere between 0mv and 20mv)
I have already discovered a charger that massively overcharges, and 2 that are ok
next stage will be to fit a very low resistance shunt to measure the current simultaneously
Not sure how that will affect the charging of the batteries but I'm guessing lower resistance shunt will mean less impact on the charge but more difficult to measure
I will do that when I have the 16 bit ADC board which should make it easier
and maybe use a lower reference voltage and split the battery voltage with a divider so the current and battery voltage are similar ? may create too much noise on the battery voltage though
May just stick to 10 bits for current as it isn't as critical and just use the 16 bit board for voltage
I will also add thermistor to measure battery temperature during charge
Thanks for all the help everyone - much appreciated please see current code that is working it's not perfect but it matches the scope and dmm
Also added RTC
The following example uses the GetBits method to convert several Decimal values to their equivalent binary representations. It then displays the decimal values and the hexadecimal value of the elements in the array returned by the GetBits method.
The following example uses the GetBits method to retrieve the component parts of an array. It then uses this array in the call to the Decimal(Int32, Int32, Int32, Boolean, Byte) constructor to instantiate a new Decimal value.
The binary representation of a Decimal number consists of a 1-bit sign, a 96-bit integer number, and a scaling factor used to divide the integer number and specify what portion of it is a decimal fraction. The scaling factor is implicitly the number 10, raised to an exponent ranging from 0 to 28.
Binary-coded decimal is a system of writing numerals that assigns a four-digit binary code to each digit 0 through 9 in a decimal (base 10) number. Simply put, binary-coded decimal is a way to convert decimal numbers into their binary equivalents. However, binary-coded decimal is not the same as simple binary representation.
In binary-coded decimal, each digit in a decimal base 10 number is represented as a group of four binary digits, or bits. Any base 10 number or digit can be represented in binary notation using binary-coded decimal.
Each digit is encoded separately. The full number is first segregated into its individual digits. These digits are then represented by their equivalent 4-bit binary-coded decimal codes as shown in this truth table.
In general, decimal-to-binary encoding using binary-coded decimal can be done using either 4-bit or 8-bit equivalents. However, the 4-bit equivalent is usually preferred, which effectively represents the decimal values from 0 to 9.
Arithmetic operations, like multiplication and addition, are required to convert real binary numbers to decimal. However, in binary-coded decimal, only 10 different combinations are possible (see above table) in each 4-bit binary sequence. This makes binary-coded decimal an easier way to represent decimal numbers.
The binary-coded decimal representation of a number is not the same as its simple binary representation. For example, in binary form, the decimal quantity 1895 appears as 11101100111. In binary-coded decimal, it appears as 0001100010010101.
The binary equivalents for each of the above examples always go from left to right. Other bit patterns are sometimes used in binary-coded decimal format to represent special characters relevant to a particular system, such as sign (positive or negative), error condition or overflow condition.
The binary-coded decimal system provides a way to get around the size limitations imposed on integer arithmetic. It also enables easy conversion between machine-readable and human-readable numerals. Compared to the binary system, it is easy to code and decode binary-coded decimal numbers. Thus, binary-coded decimal offers a fast and efficient system to convert decimal numbers into binary numbers.
Binary-coded decimal is useful in digital displays, where it can be difficult to manipulate or display large numbers. Since binary-coded decimal treats each digit as a separate subcircuit, data manipulation in such devices becomes easier. Integrated circuits that are configured to give a binary-coded decimal output on such displays are available.
Despite its advantages, binary-coded decimal comes with certain limitations. For example, representing a decimal number as binary-coded decimal requires extra bits of storage in a computer's memory, making it an inefficient way to store numbers. It also takes increased circuit complexity when compared to the standard binary system. Binary-coded decimal code can also be wasteful since many 4-bit states (10 to 16) are not used.
Another limitation of binary-coded decimal is that performing arithmetic tasks using binary-coded decimal numbers can be cumbersome since no digit can exceed 9. Consequently, adding of two decimal digits in binary-coded decimal could create a carry bit of 1, which must be added to the next group of 4 bits to arrive at the correct binary-coded decimal representation.
In unpacked binary-coded decimal numbers, each 4-bit binary-coded decimal group is stored in a separate register inside a computer. The drawback here is that, if the registers are 8 bits or wider, space is wasted storing the binary-coded decimal numbers.
In packed binary-coded decimal numbers, a single 8-bit register stores two binary-coded decimal digits. By shifting the number in the upper register to the left four times and then adding the numbers in the upper and lower registers, the process combines two binary-coded decimal digits, which enables storage in a single register.
In simple binary representation, the whole number is converted into its binary form by dividing the number by 2 repeatedly. In binary-coded decimal, each individual digit is converted to binary. The 4-bit binary equivalent of each digit is then written together.
3a8082e126