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

Subscribe to ARC Pro, and your robot will become a canvas for your imagination, limited only by your creativity.

United Kingdom
#9  

@fredebec, that was my dilemma with the 6v SLA I planned. You can use a voltage divider to basically split the voltage in half, 4.5v in your case, which is under the 5v max threshold. ARC will report back a value, multiply it by the factor 0.019607843 (5/255) and double it.

As for voltage divers circuits, I did knock one up once but it was very primitave, just 2 resistors of equal value from Vcc to Ground, tap the signal off from between the 2 resistors... I don't have it drawn up though, but google voltage divider and a lot of examples come up.

#10  
United Kingdom
#11  

Wow, it looks like it was a combination of a few things but what I didn't realise is that S2 of the LiPo balance plug actually measures both cells voltage so I was feeding over 8V in to ADC1 which must have been giving it problems. Disconnecting one of the two leads (the one with the full voltage) and the other works fine.

I think I will leave it just checking one cell, they are balanced and the charging is at 80mA on a 5000mAh battery so remains very balanced, it's not how I wanted it but it works.

I'll look in to it more when I get chance, I guess that's why I should have at least looked up the balance plug wiring configuration before doing this but no harm no foul I guess, I'm just glad the 8v to the ADC port didn't fry anything.

Edit: I tell you what, no sleep makes me forget the most simple of things. I know how a 2s lipo is wired yet totally forgot that. Ground to 1s is across 1 batter, ground to 2s is across both. 1s to 2s is across the other battery.

but, is it safe to connect the ground from ADC1 to the +v of battery 1 in order to measure the voltage across that battery?

#12  

Awesome thanks to both Rich and Dave I have an idea to monitor my EZ-Board voltage and test out my ADC ports as well. The Zener will reduce the battery pack of 8.5 volts down under 5 and viola! It does feel great to "bag a solution" I know Rich has bagged many and now Dave has just added one to his list. I bagged one the other day and WOW. Once again thanks to Rich for the voltage script which we can all use!

#13  

Rich 2 questions regarding your voltage monitor script...what is the $factor = 0.019607843 varible used for and what are the "chicken feet" symbols? I am going to guess and say multiply?! Thanks a bot

United Kingdom
#14  

The $factor is 5/255, it's actually not required but as I was having problems I didn't know if I had the factor right so used a variable so I could change it easily.

Basically, the ADC signal can receive up to 5v, ADC read reports back a value between 0 and 255 depending on the voltage. 255 being 5v and 0 being 0v. So, to convert that figure to voltage you need to multiply the ADC read value by 5/255. Hopefully that made sense.

Chicken feet symbols? I don't know what symbol you are referring to... * or # ?

United Kingdom
#15  

Updated voltage monitor script for a single battery


# 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
$adc0 = GetADC(ADC0)
# Convert values to voltage
$volts = $adc0 * $factor
# Adjust voltage if using reducer, change 1 to whatever factor needed.
$actualvolts = $volts * 1
# Check if below recommended levels
IF ($actualvolts <3.5)
  # Do sometihing if voltage low
  Print("Battery Low")
ELSE 
  # Wait 5 seconds
  Sleep(5000)
  # Go back to the start
  Goto(ReadCells)
ENDIF 
  # Go back to the start
Goto(ReadCells)

$factor is 5/255 which converts the ADC value to volts. In the IF ($volts <3.5) you can change the 3.5 to whatever voltage you want it to tell you that it's low. This is based on a battery of less than 5v, if you use a voltage reducer you would need to multiply $volts again, if halved the voltage multiply by 2, if quartered multiply by 4 etc.

I don't know how "clean" my code is, I generally end up with a lot of nests of IFs and ELSEs and a lot of variables that I suspect could probably be avoided. Feel free to alter it however you wish.

Edit: Replace the;) with a ) the code function must do something to confuse it with me wanting to put a;) there

#16  

Totally! Thanks for explanation! chicken feet=* LOL the way they were pasted makes the * look like a chicken foot.:)