By using some simple mathematical tricks it's possible to make simple voltmeter with nanovolt resolution using a Nano, a dual op-amp and some passive components.
The first axiom is that the average value of a sinewave over one period is zero.
The second axiom is that the average value of all a sinewave's harmonics over the fundamental period is also zero.
The third axiom is that the average value of noise is zero.
This is very important and often forgotten. Noise cannot generate a DC value as long as it is not strong enough to cause non-linearities.
The only way noise can generate a DC value is if it interacts with a power source in a non-linear fashion.
Noise can be reduced by low pass filtering. This filtering can be implemented by simple averaging or other methods to reduce bandwidth.
Another important fact is that a modern CMOS op-amp input offset is quite stable with a relatively low temperature coefficient.
For example, the MCP601 has offset drift of 2.5uV/degree C. The op-amp itself uses very little power so if ambient temperature can
be held relatively constant, it's easy to make precise voltage measurements.
The simplest high precision voltage divider is a PWM provided that the correct components are used and the operating frequency is properly selected.
The most critical part of the PWM is the filter capacitor which has an optimal value of 330nF.
This number is not mathematically derived, instead it comes directly from the capacitor specification.
https://yageogroup.com/content/datasheet/asset/file/KEM_F3106_R75Capacitance values of 330nF or less are rated at >= 100,000 MOhms with a typical value of >= 500,000 MOhms.
Going to a larger capacitance value will proportionately reduce the insulation resistance because of the increased insulation area.
This will cause a greater loading error without giving any real benefits.
To keep PWM precision as high as possible, the filter resistor should be relatively small compared to the capacitor insulation resistance.
If a 1MOhm resistor is used, the output error will be 1M /(100,000M + 1M) which is roughly 10 parts per million at worst.
If the PWM reference voltage is 5V, the maximum error is 50uV with a typical error of 5uV.
This gives a filter time constant of 1M * 330nF = 330ms which is suitable for over 16 bits of resolution with the correct PWM fundamental frequency.
There is an advantage to reducing the filter resistance provided that the switch driving the PWM has equally matched on resistance for the switch
going to the reference voltage and the switch going to ground. The actual switch on resistance value is not important, only the match.
If the reference voltage switch resistance is higher than the ground switch resistance, there will be a conversion error.
For example, assume the high switch resistance is 100 Ohms, the low switch resistance is 120 Ohms and the filter resistance is 1 MOhm.
The PWM output voltage at 50% duty cycle will have an error of 1 - (1M + 100R)/(1M + 120R) = 20 ppm. This is a conversion error and doesn't introduce
offset. When the duty cycle is set to 0, the PWM output will be zero. When the duty cycle is 100%, the PWM output will be 100%. It's only when the
duty cyle is at an interim value that the conversion error will be significant.
The second axiom above is used in determining the PWM fundamental frequency. If the measurement averaging period is an integer multiple of the PWM
fundamental frequency, the PWM ripple will effectively be nulled out.
If the measurement averaging period is an integer multiple of the power line frequency, power line interference will be nulled out.
The PWM operates in a simple feedback loop and needs to be synchronously controlled by the microprocessor. This limits both the minimum PWM bit width
and the maximum PWM duty cycle.
Based on the above, the PWM period is set to 1,000 clock cycles giving a fundamental frequency of 16kHz. The maximum duty cycle is limited to 90% giving 100 clock cycles
at the end of the PWM period for null detection and setting the next PWM duty cycle value.
If 4,000 PWM cycles are averaged, the averaging period will be 250ms which is 15, 60Hz power line cycles and 25, 50Hz power line cycles.
Interference from these sources will average to zero.
Although the PWM resolution is only 5mV per step, the PWM is extremely linear and interpolation between steps can be used to increase resolution.
Because the PWM filter is low pass, it is ideal for interpolation. The PWM output is restricted to one of the 1,000 available steps so there will be ripple on the
output reading, but because sampling is done at the PWM fundamental frequency, sufficient averaging of the output will reduce the ripple to an arbitrarily low value.
The third axiom applies here also. Prior to averaging, the PWM duty cycle setting value is very noisy because of PWM ripple and also thermal and other noise.
The PWM has no intrinsic offset so output nulling can be achieved down to nanovolt levels. But, extracting the average value to that kind of resolution requires averaging
over a substantial number of samples which takes a long time.
There is offset error from the op-amp and there are simple techniques to compensate for it such as switching the op-amp input between the PWM output and the input.
The input offset is then common to both voltages and is effectively cancelled out. Another trick is to use a PWM to generate an offset correction voltage, but this requires
a two bit null detector to both null out the offset and the input voltage.
The nulling algorithm is very simple. Wait until the PWM count is close to the end and then sample the null detector output and then set the PWM duty cycle one step higher
or one step lower depending on the output of the null detector.
Then, wait until the counter rolls over and then go back to the first step.
While waiting for the counter to finish, send out the accumulated duty cycle readings over the RS232 port.
Although single bit detection seems simple, it's very powerful because the rate of information flow is constrained to one bit per sample with the PWM output only able to
change by one step or less every period.
If the PWM quantization is 5mV and the fundamental frequency is 16kHz, the slew rate will be 5mV * 16kHz = 80 V/s.
Referring to
https://www.electrical4u.com/slew-rate/, the bandwidth is calculated to be 80 / (2 * pi * 5) = 2.646Hz.
The bandwidth is programmable by simply increasing or decreasing the amount the PWM duty cycle changes each cycle. In practice, I've found that changing by only one bit
gives the best stability and responsiveness. A more advanced algorithm may be able to increase responsiveness.
Another advantage of single bit detection is that it acts as a noise limiter. Regardless of the noise at the detector input, it can only move the PWM output up or down
by one step. A noise peak of 1V has the same effect as a noise peak of 1uV, the PWM can only change by one step. This places a hard limit on the amount of noise fed back into
the null detector.
By cascading multiple op-amps the single bit detector, very fine quantization is possible without averaging. If the op-amp gain bandwidth is 1Mhz with two op-amps in cascade,
a 16kHz sampling frequency, and 1V digital input hysteresis, the quantization is 1 /(1MHz / 16kHz)^2 = 256uV. Because interpolation is used, actual quantization is much finer.
A third op-amp stage can be added which will increase resolution to 1 /(1MHz / 16kHz)^3 = 4.1uV.
A PWM is also use to bias the input of the null detector. This is done for two reasons. The first is that the PWM will very precisely set the input bias to half the reference
voltage. This is convenient, but more important is that the PWM runs at a high harmonic of the measuring PWM so that it's ripple will be nulled out. Also, because the PWM is
sampling the reference voltage, noise on the reference is mixed to a much higher frequency and will have less effect on the op-amp input.
The circuit as shown is intended only to demonstrate the use of a PWM in measurement as well as the principles of single bit detection. In many use cases, single bit detection
is much easier to implement than PID control and equally effective. The use of a PWM as a digital to analog controller is also well established. By combining the two techniques,
very high precision measurements are possible although the averaging times may be too long to be practical in some cases.
An alternative is to use the PWM as a calibration standard with a fixed duty cycle. It can the be used to calibrate a voltage divider following a conventional DAC. Because the null
detector can have quantization down to the nanovolt range, the output of the DAC voltage divider can be comparable to a low voltage input such as from a thermocouple.
By switching the null detector input between the thermocouple output and the DAC voltage divider output, the op-amp input offset is common to both measurements and cancels out.
The op-amp input offset will be essentially unchanged even down to the nanovolt level at modest switching rates allowing for high precision repeatable measurements.
The DAC voltage divider is calibrated by setting the PWM output at a value less than the DAC full range and then switch the null detector input between the PWM and DAC voltage
divider to precisely determine the voltage divider ratio. For example, if the DAC is divided down by 500, the DAC duty cycle would be set to 1/1000. The switching frequency
must be a subharmonic of the PWM fundamental such as 1kHz to null out the PWM ripple.
Ideally, the DAC readings would average to 0.5. Any deviation would primarily be caused by the divider resistors. This allows the use of moderate precision resistors and
commodity op-amps to make high precision measurements, although limited by the sampling frequency.
Charge injection by the analog switch will cause transient voltage spikes. High quality analog switches with extremely low charge injection are readily available which can
minimize this. Also, charge injection is mainly capacitively coupled, and depending on input source resistance and capacitance, will discharge quickly. By sampling the null
detector output as late as possible after the switch transition, the effect of charge injection can be greatly reduced.