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

0 Members and 1 Guest are viewing this topic.

Offline davoTopic starter

  • Newbie
  • Posts: 8
ADC on Raspberry Pi
« on: July 11, 2013, 08:12:54 am »
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, 08:15:37 am by davo »
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: ADC on Raspberry Pi
« Reply #1 on: July 11, 2013, 08:26:55 am »
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 davoTopic starter

  • Newbie
  • Posts: 8
Re: ADC on Raspberry Pi
« Reply #2 on: July 11, 2013, 01: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: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: ADC on Raspberry Pi
« Reply #3 on: July 11, 2013, 08:36:47 pm »
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

  • Regular Contributor
  • *
  • Posts: 63
Re: ADC on Raspberry Pi
« Reply #4 on: July 11, 2013, 08:52:05 pm »
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 davoTopic starter

  • Newbie
  • Posts: 8
Re: ADC on Raspberry Pi
« Reply #5 on: July 12, 2013, 01: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, 01:32:40 am by davo »
 

Offline wemme

  • Regular Contributor
  • *
  • Posts: 63
Re: ADC on Raspberry Pi
« Reply #6 on: July 15, 2013, 12: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 davoTopic starter

  • Newbie
  • Posts: 8
Re: ADC on Raspberry Pi
« Reply #7 on: July 19, 2013, 06:07:54 am »
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, 06:12:22 am by davo »
 

Offline davoTopic starter

  • Newbie
  • Posts: 8
Re: ADC on Raspberry Pi
« Reply #8 on: July 20, 2013, 12: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

  • Regular Contributor
  • *
  • Posts: 63
Re: ADC on Raspberry Pi
« Reply #9 on: July 22, 2013, 01: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 davoTopic starter

  • Newbie
  • Posts: 8
Re: ADC on Raspberry Pi
« Reply #10 on: July 23, 2013, 12: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



 

Offline David_AVD

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

Offline wemme

  • Regular Contributor
  • *
  • Posts: 63
Re: ADC on Raspberry Pi
« Reply #12 on: July 23, 2013, 10:56:41 pm »
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 davoTopic starter

  • Newbie
  • Posts: 8
Re: ADC on Raspberry Pi
« Reply #13 on: July 24, 2013, 12: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
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2797
  • Country: au
Re: ADC on Raspberry Pi
« Reply #14 on: July 24, 2013, 12: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.
 

Offline wemme

  • Regular Contributor
  • *
  • Posts: 63
Re: ADC on Raspberry Pi
« Reply #15 on: July 24, 2013, 11:29:14 pm »
A instrumentation amp (differential) would be the next option as David_AVD suggests.
However you will be outside of the common mode range of the amp so you will most likely need to generate a negative rail.
all and all its a pain in the arse to vero board of cludge onto the adc board.
Cheers


 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf