United Kingdom
Asked — Edited

Getadc

I'm playing with the voltage monitor for my bot and using the GetADC(ADC Port) script command but having some slight issues with the values returned.

At first I thought it could be my code so I wrote a script to get the adc values from each of the ADC ports and add them as variables.


$vc1 = GetADC(ADC0)
$vc2 = GetADC(ADC1)
$vc3 = GetADC(ADC2)
$vc4 = GetADC(ADC3)
$vc5 = GetADC(ADC4)
$vc6 = GetADC(ADC5)
$vc7 = GetADC(ADC6)
$vc8 = GetADC(ADC7)

In the variable watcher I have the following results - this is without anything connected to the ports.

Port Value ADC0 32 ADC1 241 ADC2 136 ADC3 45 ADC4 14 ADC5 4 ADC6 1 ADC7 255

And when I attach the live of my cells (currently reading 4.09v & 4.06v) to the ADC signal on ADC0 and ADC1 I get

Port Value Description ADC0 255 (4.09v cell) ADC1 154 (4.06v cell)

Something isn't right surely? As far as I can see the GetADC command should report back a value between 0 and 255 for the voltage on the signal pin (0 being 0v and 255 being 5v), is that right? Do I have a problem with my board or software? Or have I not wired it correctly (I have nothing on the VCC and Gnd pins and the +v from each of the cells to ADC0 and ADC1)


ARC Pro

Upgrade to ARC Pro

ARC Pro is more than a tool; it's a creative playground for robot enthusiasts, where you can turn your wildest ideas into reality.

United Kingdom
#1  

My full code for the reading of the battery cells is


# Read voltage level of each cell on LiPo battery balance port and report to software.
# Set ADC factor
$factor = 0.019607843
:ReadCells
# Get ADC values
$vc1 = GetADC(ADC0)
$vc2 = GetADC(ADC1)
# Convert values to voltage
$cell1 = $vc1 * $factor
$cell2 = $vc2 * $factor
# Check if below recommended levels
IF ($vc1 <3.5)
  # Do sometihing if voltage low
  Print("Cell 1 Low")
ELSEIF ($vc2 <3.5)
  # Do sometihing if voltage low
  Print("Cell 2 Low")
ELSE 
  # Wait 5 seconds
  Sleep(5000)
  # Go back to the start
  Goto(ReadCells)
ENDIF 
  # Go back to the start
Goto(ReadCells)

It's far from complete, the if's will eventually tell it to go charge up but for now just print a warning. The main thing is the values returned from the ADC ports.

Any help would be very much appreciated as I can't see what I'm doing wrong.

United Kingdom
#2  

And the schematic of how it is wired.

User-inserted image

Edit: I just had a thought though, do I need to bring the ground from the battery to the ADC port too?

As I'm using a LiPo which are notorious for being dangerous if misused I'm hesitant to just go connecting things up "willy nilly"

#3  

Hi Rich,

I'm using all my ADC ports on one of the EZ-B boards in my B9. However I'm using DC power from a plug in power converter but there should not be much difference between that and a battery (cell as you all call them on the other side of the pond;) ). Anyway, what I have attached to the ports are both pots and momentary switches. I have no grounds going to the switches, just the 5v and signal from each ADC port to the switchs I want to monitor. That way EZ-B will see the 5v when the switch is closed. The pot is different; from an ACD port I have 5v and a ground going to the outside lugs and the signal going to the center lug. That way EZ-B will see the change in voltage when I turn the knob on the pot.

I would think you would have to have a return path for the voltage so I would expect you would need to bring the ground from your battery to the EZ-B. Now I'm not sure if you should attach it the the ground of the ADC port or the negative side of the main power input of the EZ-B board. Check continuity between the ground pin of the ADC and the negative side of the power input to see if they are tied. If so then its not an issue. If not I'd start by attaching to the negative side of the main power input. I know that's the way to hook up a H-bridge to EZ-B.

One last thing. The ADC ports will only handle voltage up to 5vdc. However this should not be an issue for you.

Wear a pair of safety glasses or cover up the battery.

Let me know what happens. eek

Have fun, Dave

United Kingdom
#4  

I think ill try with a ground to the ezb adc ports too when I get home.

I was a little puzzled by the adc values with nothing attached but maybe its nothing?

#5  

Any kind of electricity naturally flows to ground (hopefully not through you). You need a path for it to move or it just stays where it is or dissipates back into nature. ;)

PRO
Synthiam
#6  

Dave saves the day:)

The lipo (long as it is below 5v) does not need to have the positive (+) connected. Only the GND (-) and Signal (+) should be connected. So connect the GND from the lipo to the GND on the ADC port. And connect the Positive from the lipo to the Signal on the ADC port.

:)

#7  

I am also really interrested in monitoring battery voltage for my bot. However, I am currently using a 9v battery (obviously more than the 5v handled by ADC ports)... Is there a trick with ADC? or another way?

United Kingdom
#8  

Only doing the LiPo cells which are 4.2v each when fully charged so within the 5v.

Such a simple problem and I could not solve it earlier for love nor money, yet now I look at it with a clear head (and the replies - thanks!) it's so obvious I have no idea how I missed it.

Thanks Dave & DJ. Now to make up a small lead and see what happens:)