Wizpic
Global Moderator
Hero Member
Offline
Posts: 1203
Thank You
-Given: 554
-Receive: 409
|
|
« on: January 19, 2014, 06:41:33 18:41 » |
|
I've been looking at to make an ampere hour meter to monitor a SLA battery to see what's going in/out of the battery and I've been trying to convert some arduino code to PDS but it's not displaying the correct results as I don't quite understand the Arduino code, to start off with I've just put the values in there to match the values displayed in the photo to get an understanding of it and make sure it matches then I can add the rest of the code like the A/D conversion. Arduino code #include <LiquidCrystal.h>
/* This sketch describes how to connect a ACS715 Current Sense Carrier (http://www.pololu.com/catalog/product/1186) to the Arduino, and read current flowing through the sensor.
*/
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
/*
Vcc on carrier board to Arduino +5v GND on carrier board to Arduino GND OUT on carrier board to Arduino A0
Insert the power lugs into the loads positive lead circuit, arrow on carrier board points to load, other lug connects to power supply positive
*/ int batMonPin = A4; // input pin for the voltage divider int batVal = 0; // variable for the A/D value float pinVoltage = 0; // variable to hold the calculated voltage float batteryVoltage = 0; float ratio = 2.4; // Change this to match the MEASURED ration of the circuit, 12k R1 and 5k R2 int analogInPin = A0; // Analog input pin that the carrier board OUT is connected to int sensorValue = 0; // value read from the carrier board int outputValue = 0; // output in milliamps unsigned long msec = 0; float time = 0.0; int sample = 0; float totalCharge = 0.0; float averageAmps = 0.0; float ampSeconds = 0.0; float ampHours = 0.0; float wattHours = 0.0; float amps = 0.0;
void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600); lcd.begin(20, 4); }
void loop() {
// read the analog in value: sensorValue = analogRead(analogInPin); // convert to milli amps outputValue = (((long)sensorValue * 5000 / 1024) - 500 ) * 1000 / 133; /* sensor outputs about 100 at rest. Analog read produces a value of 0-1023, equating to 0v to 5v. "((long)sensorValue * 5000 / 1024)" is the voltage on the sensor's output in millivolts. There's a 500mv offset to subtract. The unit produces 133mv per amp of current, so divide by 0.133 to convert mv to ma */ batVal = analogRead(batMonPin); // read the voltage on the divider pinVoltage = batVal * 0.00488; // Calculate the voltage on the A/D pin // A reading of 1 for the A/D = 0.0048mV // if we multiply the A/D reading by 0.00488 then // we get the voltage on the pin.
batteryVoltage = pinVoltage * ratio; // Use the ratio calculated for the voltage divider // to calculate the battery voltage amps = (float) outputValue / 1000; float watts = amps * batteryVoltage; Serial.print("Volts = " ); Serial.print(batteryVoltage); Serial.print("\t Current (amps) = "); Serial.print(amps); Serial.print("\t Power (Watts) = "); Serial.print(watts); sample = sample + 1; msec = millis(); time = (float) msec / 1000.0; totalCharge = totalCharge + amps; averageAmps = totalCharge / sample; ampSeconds = averageAmps*time;
ampHours = ampSeconds/3600; wattHours = batteryVoltage * ampHours;
Serial.print("\t Time (hours) = "); Serial.print(time/3600); Serial.print("\t Amp Hours (ah) = "); Serial.print(ampHours); Serial.print("\t Watt Hours (wh) = "); Serial.println(wattHours);
lcd.setCursor(0,0); lcd.print(batteryVoltage); lcd.print(" V "); lcd.print(amps); lcd.print(" A "); lcd.setCursor(0,1); lcd.print(watts); lcd.print(" W "); lcd.print(time/3600); lcd.print(" H "); lcd.setCursor(0,2); lcd.print(ampHours); lcd.print(" Ah "); lcd.print(wattHours); lcd.print(" Wh "); // wait 10 milliseconds before the next loop // for the analog-to-digital converter to settle // after the last reading: delay(10); }
PDS conversion Include "proton_4.inc"
Dim batteryvoltage As Float Dim amps As Float Dim msecas Float Dim time As Float Dim sample As Float Dim averageAmps Float Dim ampSeconds As Float Dim ampHours As Float Dim wattHours As Float Dim totalcharge As Float Dim watts As Float sample = 600 time = 600 batteryvoltage = 14.71 amps = 0.28 main: watts = amps * batteryvoltage ' sample = sample + 1; ' msec = millis(); ' time = msec / 1000.0; totalcharge = totalcharge + amps; averageAmps = totalcharge / sample; ampSeconds = averageAmps*time; ampHours = ampSeconds/3600; wattHours = batteryvoltage * ampHours; Print At 1,1,Dec2 ampHours," :",Dec2 wattHours Print At 2,1,Dec2 watts," :",Dec2 time/3600 GoTo main
Any help would be great or a better way of doing it here is the photo
|
|
|
Logged
|
When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
|
|
|
towlerg
Senior Member
Offline
Posts: 263
Thank You
-Given: 474
-Receive: 104
What is this for?
|
|
« Reply #1 on: January 19, 2014, 10:07:42 22:07 » |
|
As has been stated several times, the Proton forum is a much cooler place. The serial number police have given up and even Les is is chilled. Its not a particularly busy board but there is some good stuff and some Proton savy guys. Do yourself a favor and give it a spin.
George
|
|
|
Logged
|
Win 7 Ult x64 SP1 on HP2570p
|
|
|
Wizpic
Global Moderator
Hero Member
Offline
Posts: 1203
Thank You
-Given: 554
-Receive: 409
|
|
« Reply #2 on: January 20, 2014, 06:16:55 18:16 » |
|
As has been stated several times, the Proton forum is a much cooler place. The serial number police have given up and even Les is is chilled. Its not a particularly busy board but there is some good stuff and some Proton savy guys. Do yourself a favor and give it a spin.
George
You hit the nail on the head there Its not a particularly busy board . I did think of posting there but some smart guy (like yourself) would of replied this is basic and not Arduino code and sometimes you get some smart guy's stating the obvious which you already stated you have tried , Just was hoping I made a simple mistake and another set of eyes would of spotted it as sometimes you cant see the wood through the trees
|
|
|
Logged
|
When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
|
|
|
Wizpic
Global Moderator
Hero Member
Offline
Posts: 1203
Thank You
-Given: 554
-Receive: 409
|
|
« Reply #3 on: January 24, 2014, 11:13:43 23:13 » |
|
I have got it all working great after some intensive investigation, mathematically it works well in ISIS and excel Just got to run some real time testing, I will be using a 12V 7 AH battery for the test's
|
|
|
Logged
|
When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
|
|
|
PaulC
Active Member
Offline
Posts: 170
Thank You
-Given: 3935
-Receive: 133
information is free and should be shared for free
|
|
« Reply #4 on: January 25, 2014, 11:53:26 11:53 » |
|
Hi Wizpic this sounds like an interesting project for my solar turbine system at home, could monitor incoming & outgoing on both, and then look it up on excel, i would be following this with great interest.. that is if you don't mind sharing your findings.. PaulC
|
|
|
Logged
|
find it , read it , share it .
|
|
|
Wizpic
Global Moderator
Hero Member
Offline
Posts: 1203
Thank You
-Given: 554
-Receive: 409
|
|
« Reply #5 on: January 25, 2014, 08:49:58 20:49 » |
|
The idea of my unit it is designed to measure both ways in and out without changing the wire's around as it as a circuit that changes the unit automatically(not sure if the others do it that way), It will also have a data logger in built to send it to an SD card then a PC program imports it plot's it and you can export the graph and data automatically. see attached for a pre-view of the graph to see how it looks this is for the charge. Hopefully I will be able to add the data that the ampere meter records so you can see if the battery is been fully charged. I had an issue the once where the charger was not fully charging the battery and the C.F factor was only .82 instead of .98-1.08. This is why I wanted to make my own and add all the stuff that I need/want. I ran a long test in ISIS and have a little bug as after 5hours the average-amps moves from 380milli-amps as this should remain .38 divided by the samples taken to give the AH and this makes the ampere hour reads 11.95 but this is wrong as it should run for 20hours and only show 7AH, Which I'm looking into. My version will be a 12bit A/D unit, The logging part is spot on with voltage and current compared to my fluke meter I watched some reviews on them and it looks like the Turnigy and Watts Up Power Meter come out worse. compared to the GT meter. You can have a look here http://www.youtube.com/watch?v=Lxv9Rozs774
|
|
|
Logged
|
When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
|
|
|
Wizpic
Global Moderator
Hero Member
Offline
Posts: 1203
Thank You
-Given: 554
-Receive: 409
|
|
« Reply #6 on: January 28, 2014, 09:45:07 21:45 » |
|
I have sorted the little bug out with the ampere hour reading I forgot to change sample from a word to a float after it counted 6535 after a few hours this messed things up. Ran a test in ISIS for 20hours with a 38ah as the battery and with the current of 1.9amps. This as got me thinking a little rather than just an ampere hour meter just to say what is going in and out of the battery like the others why not try and make it so it predicts how long it will supply that current and how much life is left in the battery so if the current varies so will the readings this will reflect that . But I suppose it all depends on your application you need it in and what's the real use you need if any. so I've been doing a bit more playing The maths AH/R=amps draw(AH amp-hour, R hour rate) 38/20=1.9 it should supply that current for 20 hours as it does in ISIS(ideal world that is and if the battery was dam good) but with the amps set higher 38/15=2.53(152 minutes) hours which is actually wrong the battery would be fully discharged before that point is reached as you have to take the Peukurt's factor into consideration. which works out the battery will only supply 15amps for .73hours(43 minutes) I know this would not be good for the to draw 15amps continuous and to fully discharge them. I might be looking at this the wrong way So let's say based on the Turnigy ampere hour meter for the RC hobbyist you have got a 7.2v battery rated at 5000mah it will only tell you what your actually using in amp hours you are using which all depends on how fast you run the motors or how long but if you take more than the 1 ampere you are allowed the run time will be a lot less as I stated above due to the Peukurt's factor and it relies on the user to stop it before the batteries are fully depleted so what good is that ?. So I plan to design a universal ampere hour meter and here is some of the features I think that would make it unique. 1. The user can set the AH of battery. (So you can use it to predict the run time and limit the max ampere hour allowed out to pro-long the batter life. 2. Add a safe cut of voltage so if the battery is dis-charged before the actual ampere as been reached either pre-set or user can set threshold 3. cut off supply to the load if either methods are reached and sound a warning tone before hand to alert the user and allow the charger to charge the battery before it connects the load again 4. either make it wireless/blue-tooth so you can monitor it remotely with in 250 meters(RF) 5. make it unidirectional so it tells you when you are charging it or taking current out so need to turn it around 6. Data logging direct to computer or through the wireless or SD card to view data with the log viewer. 7. Can be sued for actual battery capacity testing to make sure the battery as reached the end of it's useful life before you throw it away, this part would be an add on to apply a constant load. I know Silicon chip did a similar thing but some of the parts where hard to get or obsolete, These are just ideas any input or ideas are welcome if there is enough interest I will start another topic in the project section to get it going and post the stuff I have so far and the progress made along the way (like open source project) What would you think would be a nice feature to have or do you think it would be over complicated and be of no real use ?
|
|
|
Logged
|
When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
|
|
|
solutions
Hero Member
Offline
Posts: 1826
Thank You
-Given: 656
-Receive: 905
|
|
« Reply #7 on: January 29, 2014, 04:23:31 16:23 » |
|
I think you need to add the dimension of temperature to your measurement/predictor widget. Ideally cell temperature, but that one's not at all easy to get to.
Curve fitting to a battery equiv ckt model would be interesting as you can store the lumped element parametrics 0and cell temperature) during each charge/discharge cycle and maybe predict death.
|
|
|
Logged
|
|
|
|
Wizpic
Global Moderator
Hero Member
Offline
Posts: 1203
Thank You
-Given: 554
-Receive: 409
|
|
« Reply #8 on: February 03, 2014, 09:53:16 21:53 » |
|
I have been using a GLCD to display all the data now I want to change it to 2 x 16LCD display the voltage/amps on line 1 and need to create some sort of a data queue to display the following on line 2 EG- 2,1,(data queue)," ",dec3 watts AH=amphour WH= watthour AP=amps peak VM= volts min WP = watts peak say every .5 to 1 second intervals but still display the battery voltage/amps continuous without causing a delay to the first line. tried a couple of ways but this cause's the delay on line 1 How would be the best way to approach this in PDS knowing me it's really simple and can't see the wood through the tree say so to speak
|
|
|
Logged
|
When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
|
|
|
Wizpic
Global Moderator
Hero Member
Offline
Posts: 1203
Thank You
-Given: 554
-Receive: 409
|
|
« Reply #9 on: February 15, 2014, 07:52:22 19:52 » |
|
it's been a little busy fro me and managed to find some time and still No help or pointers then. Methods I have tried seem to cause a delay in the other readings, I may be wrong but I've looked at STR$/Strings, Strn, Arrays as Strings but this is ok if you already have text/data stored but these are changing variables. Everything else is working with precision. It has 3 buttons to enter calibration mode for volts/amps rather than trim pots then it's all done, I just can use a 4X16 or 20 but I would rather use a 2X16 to make it easier for others to build
|
|
|
Logged
|
When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
|
|
|
|