User guide for Mark's charger code

Forum for announcements and discussion of beta firmware.
Mark
Site Admin
Posts: 415
Joined: Sun Jul 28, 2013 6:47 am
Location: Brisbane, Australia

User guide for Mark's charger code

Postby Mark » Tue Aug 13, 2013 4:28 am

OK, some brief notes on using the charger with my code - these notes currently apply to version 0.516 - I'll try to keep this post updated when I release new versions:

How to use the charger

  1. Set Mode and Current switches to desired positions.
  2. Insert Battery/Batteries.
  3. LED(s) will light up white to indicate that batteries are detected and waiting for a button press.
  4. As soon as the button is pressed, the LED will go out.
  5. Depending on the duration of the button press, the charger will work in different sub modes:

Mode switch position:

  • Charge:
    • Short: Normal Charge.
    • Medium: Attempt to revive a dead battery then normal charge.
    • Long: Charge a battery even if it fails the internal resistance check - at a slower rate (400 mA)
  • Discharge:
    • Short: Discharge Only.
    • Medium: Discharge, then Charge.
    • Long: Discharge, Charge, Discharge, Charge.
  • Analyze:
    • Short: Charge, Discharge, Charge.
    • Medium: Charge, Discharge, Charge, Discharge, Charge.
    • Long: Charge, Discharge, Charge, Discharge, Charge, Discharge, Charge. (Charge, then 3 full cycles)

A short press is one that is less than 1/4 of a second.
A medium press is one that is for about 1 second.
A long press is one that is for 3 seconds or longer.

If after inserting a battery, the button isn't pressed within 10 seconds, the charge will default to the same mode as if there was a short button press. After the button is released, the LED will flash white a number of times to indicate which duration button press it detected: 1 = Short, 2 = Medium, 3 = Long.

You can set separate modes for each cell - e.g. you can set 1 battery charging, change the mode switch and set another one discharging or analyzing at the same time.

Meanings of the LED colors:

White (Solid): Shown at startup for about 1 second - turns off if no batteries are currently inserted. If you come back to the charge and the LEDs are white, it's most likely an indication that the charger has reset for some reason. LEDs will also show white for 10 seconds after batteries are inserted whilst waiting for a button press.
White (Blinking): Indicates detected duration of button press (see above)
White (Flashing): Shown at startup whilst reading program from SD card into EEPROM.
Red (Solid): Charging.
Red (Flashing SOS): Indicates that an error has occurred - probably a bug in the code!
Red/Blue Alternating: Waiting to charge. (Previously flashing Red, then alternating Red/White)
Red/Purple Alternating: Charging a cell with very high internal resistance at reduced current.
Red/Green Alternating: Doing top off charge.
Yellow: Discharging.
Green (Solid): Finished Charging.
Green (Blinking off): Already Full.
Purple: Aborted Charging - probably because internal resistance is too high.
Aqua: Finished Discharging.
Blue (Solid): Resting (between charges and discharges)
Blue (Fast Flash): If there was a problem with initializing the logging code, both LEDs will fast flash blue for 5 seconds before the charger continues starting up as normal. If you get this, check to make sure that the SD card is properly inserted and not corrupted. (If the card is corrupted, you may not see this flash though, so it's a good idea to check the card regularly)

Data file format columns:

  1. Milliseconds since startup.
  2. Channel Number
  3. Comment, or time in seconds with decimal to milliseconds for duration of current task.
  4. Requested current - in milliamps.
  5. Measured Voltage
  6. Actual current in milliamps.
  7. Calculated power in milliwatts - calculated from measured voltage and calculated current.
  8. Accumulated capacity in milliamp hours.
  9. Accumulated energy in milliwatt hours.
  10. Measured Temperature.
  11. PWM Value
  12. Internal Resistance


Effective Charging Rates:

High: 950 mA
Medium: 475 mA
Low: 190 mA

High mode will only charge one cell at a time. If 2 cells are inserted, the first cell will be fully charged while the other waits. Once the first one is fully charged, it will automatically start charging the second cell. With the Medium and Low rates, the actual charge rate will be double the effective rate with an off period half the time. If 2 cells are inserted at the same time, the charger will alternate between them so that they're both effectively charged at the same time.

Before each charge, the code will test the internal resistance of the cell to try to prevent charging of non rechargeable cells. This is done by doing a brief charge and then a brief discharge - this will be observed as a red, off, yellow, off sequence on the LED. If the internal resistance is too high, the cell will be rejected and the LED will light up purple. If the cell voltage is above 1.40V, the cell will be rejected as already fully charged and the LED will flash green.

Let me know if anyone has any questions!

dino
Posts: 24
Joined: Tue Nov 04, 2014 12:54 pm

Re: User guide for Mark's charger code

Postby dino » Tue Nov 04, 2014 4:08 pm

Mark wrote:
  1. Requested current - in milliamps.
  2. Measured Voltage
  3. Actual calculated current in milliamps - calculated on measured voltage across 3.9 ohm resistor.

Isn't a 3.9 ohm shunt resistor too high for accuracy within the circuit? As i understood Martin's video correctly, the burden voltage is lower when the resistance is lower, for example thru a precision 0.1 ohm resistor. And "Actual calculated" sounds almost like an oxymoron lol. The reader needs to understand that actual current "cannot" be directly measured with full precision but only indirectly measured by way of applying Ohm's law on a shunt resistor in series. And since the Ohm's law is valid, what comes out of the calculation is the actual current.

Mark
Site Admin
Posts: 415
Joined: Sun Jul 28, 2013 6:47 am
Location: Brisbane, Australia

Re: User guide for Mark's charger code

Postby Mark » Tue Nov 04, 2014 10:47 pm

dino wrote:
Mark wrote:
  1. Requested current - in milliamps.
  2. Measured Voltage
  3. Actual calculated current in milliamps - calculated on measured voltage across 3.9 ohm resistor.

Isn't a 3.9 ohm shunt resistor too high for accuracy within the circuit? As i understood Martin's video correctly, the burden voltage is lower when the resistance is lower, for example thru a precision 0.1 ohm resistor. And "Actual calculated" sounds almost like an oxymoron lol. The reader needs to understand that actual current "cannot" be directly measured with full precision but only indirectly measured by way of applying Ohm's law on a shunt resistor in series. And since the Ohm's law is valid, what comes out of the calculation is the actual current.


The information that you've quoted is actually out of date and is only relevant to the first few revisions of the charger (which didn't make it beyond the beta testers) I've updated that part of the post to make it relevant to the charger as it is now.

All recent versions of the charger use a 0.1 current sense resistor to measure current.

My wording probably wasn't as clear as it could have been: In the versions that didn't have the 0.1 current sense resistor, the voltage was measured across the cell only and not the 3.9 ohm load resistor. What I was trying to convey with the original text was that the actual current could have been a little different from that shown due to tolerances of the resistor and also the fact that it wasn't taking into account the resistance of the FET.

dino
Posts: 24
Joined: Tue Nov 04, 2014 12:54 pm

Re: User guide for Mark's charger code

Postby dino » Wed Nov 05, 2014 12:49 am

With "0.1" current sense resistor you mean a current sense SMD resistor with 0.1 Ohms? :)
Okay cool. And what are the remaining specs of it like tolerance, etc, or do you have a Mouser link? ;)
Resistance of the FET, hmm. At this point i wouldn't know how the electronic schematic looks like in detail on your product responsible for measuring the current with high accuracy, maybe it is an engineering secret :twisted:. Measuring current with high accuracy without affecting the original circuit has always been a technical challenge and i applaud that the USC distinguishes between requested current and actual current. The latter is being measured indirectly thru Ohm's Law, as we know. Anything higher than that challenges my technical understanding :mrgreen:

Mark
Site Admin
Posts: 415
Joined: Sun Jul 28, 2013 6:47 am
Location: Brisbane, Australia

Re: User guide for Mark's charger code

Postby Mark » Wed Nov 05, 2014 12:57 am

dino wrote:With "0.1" current sense resistor you mean a current sense SMD resistor with 0.1 Ohms? :)


Yes, that's correct - sorry - I left out the "Ohms"

Okay cool. And what are the remaining specs of it like tolerance, etc, or do you have a Mouser link? ;)


Sorry - I don't know those finer details - Paul should be able to answer that question though.

Resistance of the FET, hmm. At this point i wouldn't know how the electronic schematic looks like in detail on your product responsible for measuring the current with high accuracy, maybe it is an engineering secret :twisted:.


You can actually find the schematics for the chargers on Paul's site:
http://www.paulallenengineering.com/related-files.html

Measuring current with high accuracy without affecting the original circuit has always been a technical challenge and i applaud that the USC distinguishes between requested current and actual current. The latter is being measured indirectly thru Ohm's Law, as we know. Anything higher than that challenges my technical understanding :mrgreen:


Actually, in this situation, the extra resistance doesn't matter too much from the point of view of affecting the circuit since it effectively just becomes part of the load resistance. Adding a current sense resistor into a pre-existing circuit certainly does have the problem of affecting the operation of the circuit though.

dino
Posts: 24
Joined: Tue Nov 04, 2014 12:54 pm

Re: User guide for Mark's charger code

Postby dino » Wed Nov 05, 2014 7:25 pm

Thanks, i didn't know about the files. I looked at the schematics but can't make out the spot where the current is being measured. Either the schematics lacks some crucial detail or it is just me who can't find the glasses :lol:
Measuring the actual current is an important topic or aspect of a serious battery analyzer, maybe we can shed some full clarity on the details of the realization in the most recent USC iteration.. Just maybe ;)

Mark
Site Admin
Posts: 415
Joined: Sun Jul 28, 2013 6:47 am
Location: Brisbane, Australia

Re: User guide for Mark's charger code

Postby Mark » Thu Nov 06, 2014 12:31 am

dino wrote:Thanks, i didn't know about the files. I looked at the schematics but can't make out the spot where the current is being measured. Either the schematics lacks some crucial detail or it is just me who can't find the glasses :lol:
Measuring the actual current is an important topic or aspect of a serious battery analyzer, maybe we can shed some full clarity on the details of the realization in the most recent USC iteration.. Just maybe ;)


It's not complicated at all - if you look at the non LCD charger schematic, above each battery is a 0.1 ohm resistor - labelled R28 and R30. On either side of them are connections to the differential inputs on the ADC - labelled BAT1_I_SENS+ and BAT1_I_SENS- for the first slot and similar labelling for the second slot. The LCD charger is the same in respect to measuring the current - I've just pointed you to the non LCD charger since it's a bit simpler and so easier to find things.

dino
Posts: 24
Joined: Tue Nov 04, 2014 12:54 pm

Re: User guide for Mark's charger code

Postby dino » Fri Mar 13, 2015 7:21 pm

Thanks. I am still wondering why BAT1_I_SENS+ and BAT1_I_SENS- are not connected to the 2 input pins of an op-amp/in-amp/cs-amp/diff-amp or similar OP circuitry before going to the external ADC chip 8-)
Maybe the OP magic is all inside the ADC chip (got a link to the manufacturer's datasheet?).

Mark
Site Admin
Posts: 415
Joined: Sun Jul 28, 2013 6:47 am
Location: Brisbane, Australia

Re: User guide for Mark's charger code

Postby Mark » Sat Mar 14, 2015 3:25 am

We don't need an op amp, etc because the ADC has integrated gain circuitry - it's software selectable as any of 1x, 2x, 4x or 8x.

It's a Microchip MCP3424 - the datasheet is linked to from the following page:
http://www.microchip.com/wwwproducts/De ... ct=MCP3424

dino
Posts: 24
Joined: Tue Nov 04, 2014 12:54 pm

Re: User guide for Mark's charger code

Postby dino » Sat Mar 14, 2015 2:53 pm

Thank you for the link, i am studying now the PDF datasheet and comparing it to the USC schematics. p33 of the PDF states that "The voltage drop across the sensor is waste.", which we all understand.
Example: If the charger's full range of dis-/charging rates were ±{0.05|0.06|…|2.99|3.00}A ;) , then the current sense resistor's value should imo be, similar to Dave Jones' uCurrent Gold, chosen 0.01Ω (instead of 0.1Ω) with ±0.5% (or 0.1%) tolerance in order to keep the waste minimal, only 0.03V drop (=0.01Ω*3.00A) at max current. After multiplication with gain ×8 (PGA=8), we'd reach 0.240000V internally. This number is still far away —namely at 11.7% (=0.24÷2.048)— from the full scale differential input voltage range (FSR). At the other end, a 0.05A sense current would produce a differential input voltage of internally only 0.004000V (=0.01*0.05*8), or 0.195% (=0.004÷2.048) in relation to full scale, |±VREF|.

In other words, the internal ADC Converter would receive only a fraction (0.195…11.7%) of what it could maximally accept. So would this situation worsen the accuracy and resolution of the current measurement, or could the USC device also have been built on a 0.01Ω resistor without major setbacks?

In my example, would it be necessary or recommendable to choose PGA=8, or would PGA=1 be adequate as well? I can't tell yet which PGA setting the USC has..


Return to “Beta Testers”

Who is online

Users browsing this forum: No registered users and 1 guest