Author Topic: ADC on Raspberry Pi  (Read 2684 times)

0 Members and 1 Guest are viewing this topic.

Offline davo

  • Contributor
  • Posts: 8
ADC on Raspberry Pi
« on: July 11, 2013, 06:12:54 PM »
Hi,

Sorry for the long post but I'm hoping someone can give me some advice about using an ADC on my RasPi.

I'm building a monitoring server for systems on my boat and looking to monitor the voltage on two battery banks (house and starter), current in/out of the house bank, and current out from three solar panels and a wind generator (using the BB-ACS756 hall effect current sensors from Cytron).

I bought a couple of Delta Sigma Pi ADC converters (http://www.abelectronics.co.uk/products/3/Raspberry-Pi/14/Delta-Sigma-Pi-18-bit-Analogue-to-Digital-converter) from AB Electronics and set up the house bank current in/out with no problems using an existing shunt. 

However, monitoring voltages caused me major headaches.  I used a voltage divider on the inputs with 10k and 1k resistors giving me a voltage of about 1.2 volts on the differential inputs of the original boards (which should have been good up to something like 20 volts) but that didn't work.  I tried putting a capacitor across the inputs thinking it might suppress any spikes but that didn't seem to make much difference.  I ended up letting the smoke out of one chip on each board and blowing some individual inputs on the other chips.  Expensive mistake!

I think my problem is with spikes on the voltage of the battery banks maybe by loads from pumps etc as they seemed to work for a while then failed badly but I'm not at all sure.

Anyway, I've just bought a couple of slightly different ADC boards (http://www.abelectronics.co.uk/products/3/Raspberry-Pi/17/ADC-Pi-V2---Raspberry-Pi-Analogue-to-Digital-converter) from the same source.  I chose these boards instead as they already have a voltage divider which I think (well hope actually) makes them slightly less fragile and allows for up to 5 volt inputs instead of the 2 volts on the original board.

So I'm hoping someone can help me with designing a method of safely measuring voltages between (say) 10 and 16 volts using the new boards.  I'm sure I'll need another voltage divider but I'm not sure of the values to use and how can I protect the ADC inputs from unknown spikes or surges?

Thanks in advance.
Dave

« Last Edit: July 11, 2013, 06:15:37 PM by davo »

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 1818
  • Country: au
  • Question Everything... Except This Statement
Re: ADC on Raspberry Pi
« Reply #1 on: July 11, 2013, 06:26:55 PM »
as battery voltage is very slow to change add a bigger buffer resistance into the adc to bring your time constant something close to 10 seconds, also have a zener or TVS diode to clamp both positive and negative on your input,

Offline davo

  • Contributor
  • Posts: 8
Re: ADC on Raspberry Pi
« Reply #2 on: July 11, 2013, 11:41:34 PM »
Thanks!

Would 100k and 20k divider resistors be big enough do you think or 1M and 200k?  Either should give me a range of between 2 and 4 volts at the inputs I think.

I can use a 5 volt zener to ensure the voltage doesn't spike above v max at the input. 

Would I need to think about power dissipation through the zener because if it fails open circuit due to a spike, I'm risking the inputs again?

Thanks for your help!

ciao
dave

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 1818
  • Country: au
  • Question Everything... Except This Statement
Re: ADC on Raspberry Pi
« Reply #3 on: July 12, 2013, 06:36:47 AM »
you can either up your resistance or your capacitance, the key point is slow down the rate of change and clamp it. when zeners are running dramatically under there wattage they don't fail often. if concerned put 2 in parallel, then your only concern will be if one shorts, but that's going to show up as 0V which should make clear you have a problem, and still protect the input

Offline wemme

  • Contributor
  • Posts: 22
Re: ADC on Raspberry Pi
« Reply #4 on: July 12, 2013, 06:52:05 AM »
Keep in mind the input impedance to the ADC effecting your resister divider.
mcp3424 has a  2.25/PGA Mohm so worst case is ~280K at a gain of 8 this will mean you will need take this into account at the high impedance you are talking about.
with a resister divider a zener will be fine for protection. however a TVS diode has a larger junction area than a zener and therefore can take a large hit.

Offline davo

  • Contributor
  • Posts: 8
Re: ADC on Raspberry Pi
« Reply #5 on: July 12, 2013, 11:29:47 AM »
Thanks again!

I read the 2.25/PGA impedance value from the data sheet but wasn't sure what it meant exactly.  Would that be 2.25Mohm when the programmable gain is 1 and 0.28Mohm when the gain is set to 8?

Again from the data sheet, the sampling capacitor is 3.2pF so with PGA set to 1, would that mean I can use 10Mohm and 2Mohm in my divider?  I think that would give a time constant of around 38 micro seconds or (say) 120 micro seconds to charge to about 90%?  I could put another capacitor from the input to ground to slow things down even more I guess.

I think my divider resistors have been orders of magnitude off which might explain why I'm blowing the inputs.

Thanks heaps.
« Last Edit: July 12, 2013, 11:32:40 AM by davo »

Offline wemme

  • Contributor
  • Posts: 22
Re: ADC on Raspberry Pi
« Reply #6 on: July 15, 2013, 10:11:55 AM »
Hi Davo,
The reason your inputs have been blowing up are because of transients on the supply rail.
This is common on any automotive or marine setup. You will need to protect the input by placing a Zener or TVS across the input as already suggested.

also you will need to be carefully about your ground point and ensure you don't have any ground loops.
I assume the ground from your unit goes back directly to the -battery terminal and not linked to a ground on other items?

Any Resister Divider with a few 10s of Kohm should be enough with a zener /TVS to provide protection.
as long as the impedance is 1/10 of the impedance of your load you shouldn't really have any loading issues.

Regards




Offline davo

  • Contributor
  • Posts: 8
Re: ADC on Raspberry Pi
« Reply #7 on: July 19, 2013, 04:07:54 PM »
Thanks wemme!

I've got the new ADC's (ADC Pi V2.1) today and I'll be installing and testing them over the weekend.  This ADC only has single inputs (cannot do differential measurements) and has an on-board voltage divider allowing an input range of + - 5volts.

The house battery bank has a shunt already installed (used by a Xantrex "link 10" battery monitor) and I've been grounding the pi to the load side of that shunt in the same way as all the other loads on the boat.  After your comments, I'm having second thoughts especially as I'll need to measure the voltage on the starter battery which shares the same battery ground as the house bank! 

Would you suggest I ground the pi on the battery side or the load side of the shunt? 

If on the battery side, the Link 10 battery monitor would not see the load that the pi has on the battery bank of course.  However, the bank is 420AH so the extra load from the pi would be less than negligible. 

If I put it on the load side, would I get a ground loop when I try to measure the starter battery?

And would I be able to measure the size and direction of the current (charge/discharge) through the shunt with the new ADC without a differential input ?

It looks like I'm well out my depth here.  Maybe I need to go back to school :-)

Thanks heaps for your help folks.
dave



« Last Edit: July 19, 2013, 04:12:22 PM by davo »

Offline davo

  • Contributor
  • Posts: 8
Re: ADC on Raspberry Pi
« Reply #8 on: July 20, 2013, 10:02:41 AM »
Hmmm, I just checked and the shunt is from the house bank negative terminal to an earth bus and the starter battery negative terminal is connected to the earth bus (i.e. on the load side of the shunt).

So I'm sure now that I need to connect the Pi earth to that same bus (i.e. the load side of the shunt).

I'll start with measuring the voltage across the shunt I think as it's highly unlikely to give me problems with spikes as the voltage looks like 1mV per amp of current through the shunt.

Thanks
Dave

Offline wemme

  • Contributor
  • Posts: 22
Re: ADC on Raspberry Pi
« Reply #9 on: July 22, 2013, 11:13:18 AM »
Hi Davo,
You should be ok if you go on the load side just make sure your sense ground and voltage ground for your supply come from the same point.
so you don't get any voltage spikes between your ground of the pi and -ref on your adc.
provided you have some reasonable impedance between the voltage points your measuring a zener will clamp it in both positive and negative directions.


Offline davo

  • Contributor
  • Posts: 8
Re: ADC on Raspberry Pi
« Reply #10 on: July 23, 2013, 10:13:01 PM »
Thanks again wemme.

I struck another issue during testing though :-)

I'm powering the pi from a buck 12VDC -> 5VDC converter. 

With the ground side connected to the pi but the +ve disconnected (via a switch), there is zero resistance from pi ground to the battery ground (actually the load side of the shunt). 

But when I switch the power through to the pi, I can measure some voltage (varies a lot but averages around 0.3V) from the pi ground to the battery ground.  I don't have a circuit showing the internals of the buck converter but I'm thinking it has a cap or something from it's -ve output to it's -ve input (isolation maybe?).

Anyway, it seems to be screwing up small measurements like the voltage across the shunt.  They say nothing in life is easy but a break now and then would be nice :-).  I might have to go with a different and probably more inefficient power supply.

I also think I'm going to have to go back to a differential input for the shunt voltage measurement.

I'll give measuring the battery voltage a go tomorrow night when I get back to the boat.  I'm hoping that will be nice and stable and with the zeners for protection this time, I might just be able to keep the smoke inside the chips where it belongs!

ciao
dave




Online David_AVD

  • Super Contributor
  • ***
  • Posts: 2175
  • Country: au
Re: ADC on Raspberry Pi
« Reply #11 on: July 24, 2013, 08:23:13 AM »
Not surprising.  You'll need to do proper differential measurements to get any sort of accuracy.

Offline wemme

  • Contributor
  • Posts: 22
Re: ADC on Raspberry Pi
« Reply #12 on: July 24, 2013, 08:56:41 AM »
Differential would be nice but can have common mode issues also.

if I understand what you are saying is that the reference ground is bouncing around.
The problem is mostly likely just inductance and resistance between the supply ground (battery) and measuring point (adc) and current is being consumed along the path (pi) which induces a voltage that also shows up at the end. a star earth gets around this issue but can have other issues.
is the voltage being induced in the psu or the PI? if its in the psu you may be able to connect both grounds together to ensure a low impedance.

Regards








Offline davo

  • Contributor
  • Posts: 8
Re: ADC on Raspberry Pi
« Reply #13 on: July 24, 2013, 10:34:20 AM »
Thanks.

I think that's exactly right, the reference ground is bouncing around. 

I'll try binding them together tonight with a multimeter to measure the resulting current flow and monitor the buck output voltage at the same time to see if I can successfully bind the input and output earths.  I'll put a dummy resistive load on the output first I think rather than risk the pi.

I'm not sure how to tell where the voltage is being induced but I suspect the buck converter output earth is not bound tightly to the input earth .  It's earthed back to the battery over a short cable to the load side of the shunt so it's sort of a star topology already.

ciao
dave

Online David_AVD

  • Super Contributor
  • ***
  • Posts: 2175
  • Country: au
Re: ADC on Raspberry Pi
« Reply #14 on: July 24, 2013, 10:43:02 AM »
Using a differential measurement (two sense leads per channel) will avoid the issues of offsets in the cabling.  The inputs will need to be able to go slightly negative with respect to the ADC ground.

Trying to shunt out the various 0V points is not the solution imo.  Better to just measure the difference right at the desired point.


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf