Solitary_Knight
Posts: 4
Joined: Sun May 29, 2016 8:22 pm

Low Accuracy Readings Using MCP3008/MCP3208 [Solved]

Sun May 29, 2016 10:17 pm

I am trying to read AC current using a hall-effect sensor (DRV5035VA) and an ADC (I have both the MCP3008 and the MCP3208). The DRV sensor outputs about 1.02V when there is no current. The setup works for the most part, but the readings have a large amount of error. When the DRV is at 1.02V, I get typical readings of 316-326 on the MCP3008 (1.005V - 1.035V) and 1263-1303 on the MCP3208 (also 1.005V - 1.035V).

Setup:
Image

Data points taken about 0.1ms apart (MCP3208, X axis is milliseconds):
Image

Compared frequencies of values (MCP3208):
Image

I need to be getting accurate values at least 15 times a second, ideally much faster. I've tried brute-forcing it with averages and medians etc., but even that isn't good enough for my needs. I know it is possible to get stable readings like in this video (the temperature sensor stays at 218 with the occasional 219, a range of 1, whereas my MCP3008 has a range of 10).
https://www.youtube.com/watch?v=wIAffBT ... ran-Harper

I have tried:
  • Bit-banging with regular GPIO pins vs. using Spidev (no difference)
    30000Hz-3000000Hz clock speeds (no difference)
    Measuring the hall sensor with a DMM (it seems to stay within 1mV, which is plenty accurate)
    Connecting 5V to VREF and connecting 3.3V to CH0 (similar inaccuracy; rules out the hall sensor even more)
    Connecting an AA battery to VREF to make it more stable (the wire seems to be stable to about 1mV, but again, similarly inaccurate readings)
    Reading the ADC at different frequencies (no difference between 0.1ms or 1s)
    Probably lots of other stuff that I'm forgetting
Am I doing something wrong? Or is there just no way to get the kind of accuracy that I want? Thanks in advance.
Last edited by Solitary_Knight on Thu Jun 02, 2016 5:26 am, edited 2 times in total.

rzusman
Posts: 347
Joined: Fri Jan 01, 2016 10:27 pm

Re: Low Accuracy Readings Using MCP3008/MCP3208

Sun May 29, 2016 11:04 pm

ADCs are extremely sensitive to layout issues.
You will never be able to get the spec’d accuracy using a proto board.

Try a nice PCB with a good ground plane and well-bypassed power traces and see what you get.

User avatar
joan
Posts: 15253
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Low Accuracy Readings Using MCP3008/MCP3208

Sun May 29, 2016 11:17 pm

Have a look at http://abyz.co.uk/rpi/pigpio/examples.h ... wMCP3008_c

You don't need 25 ksps but it will give you accurately timed data. At the moment you will only have a crude idea of sample timing.

Solitary_Knight
Posts: 4
Joined: Sun May 29, 2016 8:22 pm

Re: Low Accuracy Readings Using MCP3008/MCP3208

Mon May 30, 2016 12:05 am

rzusman wrote:ADCs are extremely sensitive to layout issues.
You will never be able to get the spec’d accuracy using a proto board.

Try a nice PCB with a good ground plane and well-bypassed power traces and see what you get.
Thanks for the quick reply. The video I posted was the programming part, but in the video before he explained how to wire it up. He's using a breadboard as well, and even the same cobbler as me. As far as I know our circuits are practically identical.
https://www.youtube.com/watch?v=LW95W7k ... ran-Harper
So I don't understand how our results can be so different, unless my breadboard is really that much cheaper than his.

rzusman
Posts: 347
Joined: Fri Jan 01, 2016 10:27 pm

Re: Low Accuracy Readings Using MCP3008/MCP3208

Mon May 30, 2016 12:29 am

I would try bypassing your supplies with 1µF and .01µF capacitors to ground.

Read sections 6.4 and 6.5 here:
http://ww1.microchip.com/downloads/en/D ... 21295C.pdf

I'm not sure why the breadboard in the video works as well as it does, but Analog circuits are difficult that way.

ghp
Posts: 1668
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Low Accuracy Readings Using MCP3008/MCP3208

Mon May 30, 2016 5:56 pm

Hello,
I tried to find a datasheet for your sensor, but did not succeed. Do you have a link for a datasheet?
Think this sensor is the small three-pin to the right of your setup.

One approach to isolate the noise problem is to use a low impedance voltage source instead of your sensor, for example a few kOhm potentiometer. This should give quite stable readings, as it also eliminates influences from vref to some extend. I use a MCP3202 in similiar setups with potentiometer inputs and get values (+- 2 points), using half a meter of unshielded cable for the potentiometer. Some capacitors on Vcc are very useful, place them close to the chip.
If you get stable readings with a potentiometer, then it is not the breadboard or adc causing trouble.

Another source of noise is Vref, which is usually a noisy Vcc. When I measure constant voltages of sensors e.g. TMP36, there is a quite large noise margin. But when using an adc with internal vref, e.g. ADS1015, results get much better. It is difficult to measure this with DMM, as these are too slow for some spikes. A low pass filter from Vcc to Vref with 100 Ohm, a few uF (and for safety a schottky unloading cap in case of power loss) could help, sensor could be powered from this Vref then (if power consumption is low).

Regards,
Gerhard

Solitary_Knight
Posts: 4
Joined: Sun May 29, 2016 8:22 pm

Re: Low Accuracy Readings Using MCP3008/MCP3208

Tue May 31, 2016 5:02 am

ghp wrote:Hello,
I tried to find a datasheet for your sensor, but did not succeed. Do you have a link for a datasheet?
Think this sensor is the small three-pin to the right of your setup.

One approach to isolate the noise problem is to use a low impedance voltage source instead of your sensor, for example a few kOhm potentiometer. This should give quite stable readings, as it also eliminates influences from vref to some extend. I use a MCP3202 in similiar setups with potentiometer inputs and get values (+- 2 points), using half a meter of unshielded cable for the potentiometer. Some capacitors on Vcc are very useful, place them close to the chip.
If you get stable readings with a potentiometer, then it is not the breadboard or adc causing trouble.

Another source of noise is Vref, which is usually a noisy Vcc. When I measure constant voltages of sensors e.g. TMP36, there is a quite large noise margin. But when using an adc with internal vref, e.g. ADS1015, results get much better. It is difficult to measure this with DMM, as these are too slow for some spikes. A low pass filter from Vcc to Vref with 100 Ohm, a few uF (and for safety a schottky unloading cap in case of power loss) could help, sensor could be powered from this Vref then (if power consumption is low).

Regards,
Gerhard
Here is the sensor datasheet; I should have included it before:
http://www.ti.com/lit/ds/symlink/drv5053.pdf

I don't have an electrical set yet (one is coming in the mail, though) but I managed to find a potentiometer in an old XBox controller chip. I don't know its resistance. I also found some capacitors and resistors on other chips, but they are very old and for all I know they are useless. Here is the data that I got:
Image

So it looks like using the potentiometer significantly improves the readings. You mentioned the ADS1015, which has a bypass capacitor, an internal reference, and a gain amplifier up to 16x. Do you think using the gain amplification feature of the ADS1015 or the ADS1115 would significantly improve the readings from the hall sensor? Is there anything else I can do?

ghp
Posts: 1668
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Low Accuracy Readings Using MCP3008/MCP3208

Tue May 31, 2016 7:42 pm

Hello, good success with the potentiometer. Perhaps you should check the place where the caps are connected: put them as close as possible to the adc.
The datasheet of the hallsensor is showing some interesting details:
- they say it is a must to have a 0.01uF cap close as possible to the pins.
- when you look for the filter section, there is an unfiltered noise margin of 30mV which is close to your measurements. So a low pass filter is recommended, they give details on R and C-Values in the datasheet.
- very interesting is the source/sink capability of the internal amplifier: 300uA source and some 2mA sink. At 1V, this is like 3.3kOhm impedance (worst case), when you add the filter resistor it is 4k. The mcp-adc need 'low source impedance' in order to measure precise. Perhaps you should spend an op amp to adjust impedances. From the adc datasheet "Ideally, the impedance of the signal source should be near zero. This is achievable with an operational amplifier"

Regards,
Gerhard

Solitary_Knight
Posts: 4
Joined: Sun May 29, 2016 8:22 pm

Re: Low Accuracy Readings Using MCP3008/MCP3208

Thu Jun 02, 2016 5:24 am

ghp wrote:Hello, good success with the potentiometer. Perhaps you should check the place where the caps are connected: put them as close as possible to the adc.
The datasheet of the hallsensor is showing some interesting details:
- they say it is a must to have a 0.01uF cap close as possible to the pins.
- when you look for the filter section, there is an unfiltered noise margin of 30mV which is close to your measurements. So a low pass filter is recommended, they give details on R and C-Values in the datasheet.
- very interesting is the source/sink capability of the internal amplifier: 300uA source and some 2mA sink. At 1V, this is like 3.3kOhm impedance (worst case), when you add the filter resistor it is 4k. The mcp-adc need 'low source impedance' in order to measure precise. Perhaps you should spend an op amp to adjust impedances. From the adc datasheet "Ideally, the impedance of the signal source should be near zero. This is achievable with an operational amplifier"

Regards,
Gerhard
I tried making an RC filter with a 0.0015uF cap and a 9.5k (close to 10k) resistor as the datasheet suggests in the "Filtered Typical Application", and it didn't help much. A 0.1uF capacitor, however, helps immensely. Here is a comparison of the AC readings I was getting before to what I'm getting now.
Image
This is so much better, so I can finally move on with my project. Thank you so much for the help.

Return to “Interfacing (DSI, CSI, I2C, etc.)”