Show by Label

Thursday, September 29, 2016

Building a 6 Digit Milli-Volt Meter

There are a large number of updates in the software, scroll down to see them.


As I mentioned in one of my other posts about the Kelvin-Varley Divider, I wanted to have a higher resolution voltmeter than I currently have. I happened to stumble on a nice set of Youtube videos from Louis Scully from Scullcom Electronics. He has described a set of very nice instruments, one of them is a 6.5 digit milli-Volt meter.

One usual caveat! The links I provide may at times no longer work, so my apologies in advance if you land in the 404 land of no returns.

Here are the links to the videos, now up to 4 in total.

Part 1 of the 6.5 digit Voltmeter
Part 2
Part 3
Part 4
Mk2

The design is quite simple and should be able to be built if you have a bit more than average skills.
The good news is that a follower of this design, Greg, has provided a PCB through OSH Park that greatly enhances the input section of the DVM, which is the Achilles heel of such a project.

Here is the website that details the implementation using that PCB:
Barbouri Millivolt-Meter Project

I will use that PCB, but I have a few changes in mind for the version I am going to built and I'll go through these elements here.

The front end of the design is the most critical. I'll implement that by following the PCB design. For the processor part, I originally wanted to use the same Arduino Nano that Louis Scully is using, but since the PCB layout is for an Arduino Pro Mini I'll use that. However, I have no need to drive a multi-color back light LCD, and I also do not foresee any other enhancements that will eat up the Arduino ports, so I see no need to use the Display42 PCB from Greg with the I2C MCP23017-E/SP chip.

To cut down on the amount of wires going from the Arduino the the LCD, there are 6, I am using a module that is available on eBay for a very small price : LCD Interface

The LCD that I'll end up using will be this one :
16 x 2 White on Blue LCD












My design will also power the unit from a battery, to avoid grounding issues and provide a clean supply to begin with. However, rather than using normal batteries, I will use a  rechargeable cell, and I want to provide a way to charge them while using the instrument, and also when not in use. To keep taps on the voltage level or discharge level while not on mains, I need a monitor that will warn me when the voltage is getting too low.

Here is the circuit that I use to implement the button debounce, and the power section.




One word of caution before I dive in. The DC chassis part is not quite like the Eagle symbol I used in this diagram. There is no short between the plus and minus when there is no plug inserted! The minus is however isolated from the chassis when there is no plug inserted, keeping everything isolated from the chassis. If the plug is inserted, there is an indication on the LCD, so you won't forget.

You'll notice that I deviated from the design Louis used for the two buttons. I have quite some experience now interfacing buttons if you have followed my Raspberry Pi posts. The processor of the Pi runs at 900MHz or more (yes, no typo), and interfacing with something as slow as a button has its challenges. Especially for inexpensive buttons. You'll be amazed how noisy they can be.

In any case, the filtering that I use to get rid of most switch bounce noise is by using an R/C filter on both edges (closing and opening). I always prefer to use active high buttons or switches because they avoid all sorts of power-on problems. When the switch/button is open, the capacitor is at ground level. Closing the contact will charge the capacitor through the 10K series resistor, creating a nice and clean rising edge (R/C) towards the input of the Arduino. Releasing the switch will cause the capacitor to discharge through the 10K series resistor plus the 1K to ground, again creating a nice R/C slope that will filter the high speed bounce noise. In software we can use a little delay to get rid of the slower bounce transitions, and together this will create clean signals to the Arduino program without having to resort to Schmidt-trigger gates or Flip-Flops.

One word of caution. Don't make the debounce capacitor much larger than 10nF. If you don't have 10nF, you can go as low as 1nF. The reason for this is that the slower the R/C slope, the more time the signal stays in the undefined area between digital "high's" and "low's" and that can cause glitches for the processor again.  If I peaked your button interest, have a look here : Debouncing buttons There is a lot more to buttons than you may think.

The power design is quite simple, and I've used that before. The two Schottkey (low drop) diodes D2 (this diode can actually be a 1N400X type) and D3 will decide which supply is feeding the Voltmeter. If the mains is connected (providing the 15-30V DC), D2 will have the higher voltage so it will win. If there is no mains connection, the battery supplies the voltage. The resistor (R1) in parallel of D3 determines the (re)charge current of the Ni-CAD cell. The charging current is about 0.1 x C for a 250mAh cell. Depending on the capacity of the cell(s) you're using you may need to change the value of R1 so it is within the (re)charging specification of the cell(s).

In order to keep an eye on the charge level of the cell, I have added a few parts to allow the Arduino to measure the voltage level. You don't want to run into a situation where the voltage is too low, and you will introduce errors in the measurements. Besides, you don't wat to be caught with an empty battery when you're in the middle of something. R2 and R4 create a 3:1 voltage divider with easy to find resistors. You can create 20K with 2 x 10K in series. (don't use less than 10K for R4, or it will negatively influence the ADC conversion) C4 is a small filter to get rid of noise and the output goes to one of the Arduino ADC inputs. The rest is done in software and I have also designed some battery level symbols to make it look nice.

The complete multi-meter draws less than 60 mA. About 26mA of that is used by the LCD display. It is safe to use the L part for the 12V regulator, and even for the 5V regulator on the PCB.

If you are already an Arduino user, you may have the Mini Pro, and you also may have the required programming cable. If not, here is a source that provides both as a bundle :
Arduino Pro Mini with interface

Here is a picture of the small interface board that will turn the LCD module into an i2c capable interface, reducing the number of wires, and to stay compatible with the PCB.



You need to install a new LCD library to get the i2c driver, and I selected the library from here :
i2c / LCD library

This library is tailored for a particular interface board, the FaBo #212 LCD I2C Brick, but the only difference is the i2c address with the board I have.

First of all, you need to know the i2c address of your board.
I used a little sketch to do that:
i2c address scanner

My address turned out to be 0x27, while the FaBo brick uses 0x20.
After you have installed the new i2c-LCD library on your system, you need to edit the  FaBoLCD_PCF8574.h file that is in the library source section, and change this line :

#define PCF8574_SLAVE_ADDRESS 0x27 ///< PCF8574 Default I2C Slave Address = 20


Here is a picture of the finished project. I actually build two units, because one can never have enough voltmeters. My design and the changes I made allows me to position these meters very close to my prototypes, and without and power wires attached. I can also make floating measurements, because nothing is connected to the housing. (the DC socket inputs are isolated from the chassis if no power plug is inserted)



Below is a link to the copy of the Arduino sketch. There are many changes to the original code, so have a good look at what has been changed in case you use different hardware.

I have been playing with the two units, to see what the accuracy is and what I could change in the user interface.

I must say that I am very impressed with the accuracy! I have two calibrated voltage reference units, and also a new/freshly factory calibrated 4.5 digit bench multi-meter. The accuracy and precision of this design is astounding for such a simple and inexpensive tool.


I was a little apprehensive about feeding the LCD display with the same 5V supply as the rest of the logic. These displays are notorious for introducing spikes and noise, so I was on guard for trouble.

When I got my scope attached, I was not surprised by the noise I found, so I started with decoupling the 5V power where it enters the display module. I used a Tantalum 3.3uF together with a 100nF to begin with, because the i2c and the LCD do not have any decoupling.
Here is how that looks:

Unfortunately, this did not reduce the nasty spikes on the reference voltage and the main 5V by much. Looking into it some more, I found that the switching of the LTC_CS line to start/stop the AD conversion cycle turned out to be the culprit. Here is a screenshot:


The top trace (A) is the LTC_CS signal coming from D10 at the Arduino PCB. The bottom trace (B) is the 4.096V reference, AC coupled. The spikes are clearly caused by the switching at the digital port. They are a few nSec in width, so I selected a 4n7F capacitor that slowed the edge down enough to not cause a spike anymore. I mounted that capacitor on the PCB of the Arduino, with one leg soldered to D10 and the other end to the unused GND mounting hole just next to it.:


And this is the result:


I noticed a potential bug in the code, related to the averaging of the results. The Spi_Read function discards a reading of the ADC if it's not ready, but the main loop code counts it as a valid sample, which could result in wrong measurements. I have fixed the code below, but I could not find instances of this error when I looked for it with a Logic Analyzer.

While I had that out, I looked at the timing in more details, to see if there were any potential conflicts.

First of all, this is a picture of the ADC sampling window:

Here you can see that the CS is going down to start the cycle and the MISO is ready 1.25uS later, virtually at the same time. There is 1.5uS between that event and the first clock going high. This is after I already eliminated the little delay in the original Spi_Read code. It is not needed. You can see here the four data bytes getting read, and the actual data presented on the MISO. Note that at the third clock, we are reading the third status bit (SIG), and that indicates a V-in signal > 0. The data towards the end is the "real" 28 bit data, of which the last 4 are the "extra" sub LSB's and they are discarded in the main loop after the averaging. (look at the datasheet for details)

I selected 8 samples to be averaged in my code, and then prepare the result to go to the LCD. As I mentioned earlier, these LCD's are very noisy. In our case, this has no real influence, because the LTC2400 is put to sleep after we have read the data, and made the CS pin high again, as you can see above.

Here is a screen shot that shows the end of the data (channel 5) going through the  I2C bus to the LCD, and the beginning of another acquisition cycle:

You can see that we have a "quiet" period after the LCD got updated, and the start of a new ADC acquisition, which is 0.129 mSec (T1-T2). The total loop time, from LCD update to LCD update is 1.5 Seconds in my case. Sending the results to the LCD only takes about 36 mSec.

Here is a picture of a complete loop:

The "dead" time, averaging the results and sending it to the LCD is only 0.22 Seconds.

After playing with the meter, I got more and more dissatisfied with the flopping around of the last 3 digits, even when I has a stable voltage reference connected to it.

At first I played around with the averaging, but that is really no solution for a system that has 24 bit resolution. The reason is the inherent amount of noise when you are down to the micro-Volt level. Below is a sample of my 2.5V reference, using my non-calibrated voltmeter (the reference is calibrated as having 2.49993V)

Averaging does not have as much influence as you may think. There is still quite abit ofnoise.

So, still not good enough. I then looked at smoothing, but that was not good enough either, so I turned to filtering. I tried a few approaches, and then really investigated an Infinite Input Response (IIR) filter design. And that showed a lot of promise:


This filter is based on the "weighing" of the new samples, based on a division. The divisor is fixed and above I used a factor of 64. This means that a new sample only contributes to 1/64th of the value to the averaged total. This is great when you have a stable signal, but what if the input voltage changes?
You could of course reduce the weighing factor, and here is one example with factor 4.


An order of magnitude better then averaging. But I was not satisfied yet. I then looked at resetting the averaged result if the sample was significantly different enough from the averaged result. I used a 5 sample input filter to avoid spikes resetting the filter, and that worked very well. If a new voltage was applied, it only took 5 cycles of 0.165 Sec. to switch to the new input.



I have just about zero experience with filters, and this extra code I designed myself, but I was convinced that there are better methods available. I eventually found the Kalman filter, which is used a lot, and seemed perfect for my application.

Knowing nothing about it, I searched and found a very nice tutorial on Youtube that explains the Kalman filter very very well, even for total Dummies like myself. (look for Michel van Biezen - Special Topics - The Kalman Filter) I wrote a simplistic version of the filter based on his explanation but was not satisfied with the result. I also worked with another example I found, but that had the same problem. Neither of them worked with relatively quick input changes, as an example when switching from 2.5V to 5.0V. They both took several seconds to show the new value. Bummer!

So Kalman looked great on paper and in simulation (using Excel), but in reality, using my Volt Meter, it was a lot worse than the IIR filter I already used. However, I stole a concept from the Kalman filter, namely the Gain calculation. This is a dynamically calculated weighing factor, so I wrote some code around my IIR filter that accomplished what I wanted. Details are in the code. The result is fantastic, I think!

If I now connect the meter to a really stable voltage, like from a reference, 5 decimal digits are rock solid with only the 6th flopping around due to the noise. When I switch from one reference voltage to another one, within a few cycles, the voltage is updated and within a second or so the 5 digits are rock solid again.

When I tested the ability to set a voltage manually with a power supply (one of those I built in the other Forum posts), I was amazed how well the response to my tuning and the accuracy was, but also I saw how noisy my power supplies turned out to be. That's what you get when you are using a 24bit ADC with micro-voltage resolution. Oops!

In any case, with this filter in place, I also added a separate calibration function, to calibrate the Volt Meter to my Voltage Standard. I already use the (Zero) Null Volt calibration to null the input level, but I now also can tune the meter to my Voltage Reference.

The accuracy is now much better as well.

With all this done, I no longer need to reduce the number of decimal digits, so that code went into the bit-bucket. In the process of going through the filter designs, I also saw a way to get to a more stable and precise acquisition delay for the LTC2400. The delay is now dynamically calculated.

Because I needed to store the calibration factor for the voltage reference, I needed to store a floating point number in the EEPROM. Turns out, the library we already used has that feature, so I could clean-up the code, and send two more functions into the bit-bucket.

My dual-button press now drives the zero calibration and the reference calibration.

With all these changes and loop tuning, the main loop time is now about 165mS, so the display is very responsive.

V3.11 update:
I found a bug in the filter calculation, based on a rounding error. This is caused by diving a long by a float, and the result going into a long again. The solution was to use a float as the result. The compounded rounding error cause the filter result to be a little bit below the raw averaged input level, as you can see in the filter graph above.
Here is a shot of the result after I fixed the code:


The difference between the filter result after 1000 samples, and the calculated median value in Excel is now very, very small.

I also added the filter weight exponent multiplier to the display.

V3.12 update:
Because the linearity of the meter was not as good as I had hoped, I created a way to measure the value of the ADR4540B chip, and updated that factor in the code. To measure that voltage with my still un-tweaked meter, I calibrated the meter with my 5V0 reference, to get as close as possible. In order to do that, I created a special cal functions for all my reference voltages. Now you can select any of them, just update the cal factors.

To do this calibration, I let my 2 meters and the reference warm-up. Then I did a fresh null calibration, and a 5V0 calibration. I then measured the ADR reference voltage for a few minutes to get the best possible filtered voltage. I had already added a pin on my PCB to do that easily. This voltage was then used to update the constant in the code.  I did the same for my other meter. After updating the v-ref constant, I did the measurement again to verify and tweak if required. Finally, I did the ref voltage calibration again. After trying all 4 reference voltages, I had the best linearity result with the 10V reference.

After this calibration the linearity is even better.
Not surprisingly, the 10V is spot on :

Reference Voltage     Measured Voltage     Delta                   %
2.49993 V                  2.49953 V                  -400uV           -0.016%
5.00181 V                  5.001515 V                -295uV          +0.059%
7.50547 V                  7.50534 V                 -130uV           +0.0017%
10.00673 V                10.00672 V                -10uV            +0.00001%

That is good enough for me. If I have e need to really measure in the sub-volt range, I can still do the 2.5V cal.

The LTC chip can actually measure an input range of +/- 12.5% of the reference voltage, so what you can do with this feature is to null the meter with a voltage you want to monitor, say a 2.5V reference, and you can then measure the drift with uV resolution over time. (this includes the drift of the meter itself as well of course, but still)

Here is the latest version of my code: https://github.com/paulvee/6-digit-milli-voltmeter :

I am sure you will enjoy this tool!

Have fun!





21 comments:

  1. Really useful. You are awesome. But I am using different controller (18F microchip series). I would like to use kalman filter. How can I incorporate kalman filter into my program? Any sample code with just using kalman filter? How did you calculate the number 96 for noise level. Please help.

    ReplyDelete
  2. If you want to use the Kalman filter, you really need to figure it out yourself. Earlier in my post, I show a search term for finding a very good explanation on YouTube.

    In my own opinion and experience, using the Kalman filter on a DMM with the hardware we have is too slow to be useful, which is why I ditched it.

    To get to the 96 as a noise level factor, I just did many measurements and pumped the results into Excel files for further analysis. While I was playing with the filter variables to get improved filter results and improved filter and display response times, I simply empirically decided that everything within this 96 range, which is only a mere 234uV level change, is probably noise, and everything outside this level is probably a "real" new value, requiring a filter weight change.

    Depending on your own noise levels, or responsiveness of the filter and display update frequency to new values, you can change the 96 value to whatever you like.

    If, make that a very big IF, I decide to use a rotary encoder as the GUI interface instead of the single button, I can make more variables changeable by the user. So far, I have not really seen the need, but since it is possible, I probably will, sometime.

    Success!

    ReplyDelete
  3. Your analysis of the project is incredible! I have leant much reading your take on the whole design. This is sort of a retrospective and new improvements of the project all in one. Thanks for the long post.

    ReplyDelete
  4. Wow! thank you!
    i have a few questions (and I apologize if they are dumb - I'm learning and looking for a project to work on with my mentor) -
    1. how would this change if measuring A/C signals?
    2. If using a nano, would it be possible to add have the outputs to include LED light, audio, AND bluetooth transmission??? OR would that create too much noise as well?

    Thanks again
    Ben

    ReplyDelete
    Replies
    1. I suggest you solicit your mentor to see if adding AC measurement capabilities is a doable and worthwhile project for you on the basis of this design. To prepare for that discussion, I suggest you use Google to familiarize yourself with that concept before you do.

      Adding an LED to one of the Nano outputs is possible, although I fail to see why you would want to do that. Why can't you use the LCD?

      I also don't think you want to add extra noise by doing anything with audio or bluetooth when the front-end is capable of measuring single digit milli-volts. How do you envision to keep the audio/transmission noise away from the measurements?

      If you are looking for a more software heavy project on the basis of this hardware, I suggest you look into better noise filtering or increasing the measurement frequency by optimizing the filtering/averaging algorithms.

      Delete
  5. Hi, impresive post!
    I also trying to uV meter using 24bit fully diff. ADC. I tried several ADC's but can't get stable 1uV measurement. Now I am trying with Analog Device AD7124. Do you think it's possible to measure uV range with 24bit ADC?

    ReplyDelete
  6. AFAIK, it is generally understood that with "normal" means in terms of layout and used components, you will only get up to 18 bits of resolution with 24-bit ADC's. Make the calculation and see where your limits will be.

    ReplyDelete
  7. Does this project involve analysing the adc or any other component (other than the voltage reference output) in order for the calibration to work correctly? It seems that you manually got the value for the unlinearities in your adc, and put those in the calibration routine..?

    ReplyDelete
  8. No whos, I only use an external voltage reference to calibrate. I have one of those good eBay ones that also lists the actual voltages after calibration/verification, so you know what the output is. As an example, mine has 2.49993 in the 2.5 setting, etc. That is good enough for me and I calibrate the DVM accordingly. Note that you can calibrate towards 2.5V, 5V, 7.5V and 10V, depending on your intended application.

    ReplyDelete
    Replies
    1. Gotcha. Thanks. Did your units two last digits jumping all around the place too? (I'm looking at those youtube videos) That defiates the purpose of having all those digits IMHO..

      Delete
  9. whos, the last 2-3 digits can indeed jump around. This is inherent with the sensitivity level due the number of digits. Apart from the stability of the meter itself, it can also be caused by the instability or noise level of the source you are measuring. Due to the "weighted averaging" algorithm that I implemented, and with a stable and clean source, even the last digit can be rather stable.

    Keep in mind that when you're dealing with this high of a number of digits and the resulting sensitivity levels, you also need to be aware of the minute amount of noise or fluctuation in uV that will cause the last digits to move. (know thy instrument)

    As a last resort, when the source is not that stable or the value is moving (you're adjusting), you can still reduce the digit count.

    ReplyDelete
  10. This comment has been removed by a blog administrator.

    ReplyDelete
  11. This comment has been removed by a blog administrator.

    ReplyDelete
  12. This comment has been removed by a blog administrator.

    ReplyDelete
  13. Hi Paul,

    What's your accuracy on extreme ends - say, 1mV?
    I also get different results depending on calibration (10V or 2.5V), but on 1mV the result is the same - 500uV, i.e. 50% error.

    Many thanks
    Alex

    ReplyDelete
  14. Hi Unknown,

    You bring up a good point. I must admit that I never really tested the DMM at these low levels.

    It seems that below 2mV, the accuracy goes way down (50% as you saw as well) to a point I believe that it's no longer working properly.

    At 2mV and above all seems to be well and accuracy improves a lot.
    Unfortunately, I don't have the means to specify accuracy at these low levels, so it is what it is. Maybe another user that build the DMM and has a way to specify accuracy at sub 1mV levels can chime in?


    ReplyDelete
  15. This comment has been removed by a blog administrator.

    ReplyDelete
  16. I am obsessed with this subject. But I want more. I want to build a complete bench test setup. 4 lead uvolt multimeter/uohmmeter, signal generator, oscilloscope, spectrum analyzer, meter calibrator all in the form factor of a cell phone so it can attach to my cell phone like a phone case, be powered by the usb port and display results on the phone screen. It all has to be usefull ranges as well. Clearly the cell phone can generate up to ghz range frequencies otherwise it couldn't transmit wifi signals. It has plenty of current available from the battery but connecting to it is problematic. All the pieces are there but putting the puzzle together remains elusive.

    ReplyDelete
  17. This comment has been removed by a blog administrator.

    ReplyDelete
  18. This comment has been removed by a blog administrator.

    ReplyDelete
  19. This comment has been removed by a blog administrator.

    ReplyDelete