NordicSemiconductor / Nordic-Thingy52-FW

Nordic Thingy:52 software development kit. This kit is designed to assist users in developing their own custom firmware for Thingy. Please see http://www.nordicsemi.com/thingy for the latest news and software releases.
Other
210 stars 133 forks source link

m_batt_meas: correct interpretation of XC6804 CSO signal #26

Closed pabigot closed 6 years ago

pabigot commented 6 years ago

The XC6804 charging status output pin is on during trickle and main charging, and off when charging is complete. The sense of the signal was inverted in the code, resulting in a CHARGING_FINISHED event when the USB is connected and the battery is partially discharged. Swap the interpretation so a CHARGING event is generated instead.

Signed-off-by: Peter A. Bigot pab@pabigot.com

pabigot commented 6 years ago

After more experimentation I'm about 80% convinced the original code is correct: putting a low-resolution USB ammeter on the input shows that it starts (trickle?) charging at ~0.04 A when the GPIO is low, and when the GPIO goes high it drops to 0 A. Some of the confusion is because the pin value appears to have some jitter around the time of the cable being inserted; I determined the above behavior by modifying m_batt_meas_handler in main to display and detect changes to the BATT_CHG_STAT. Changes to BATT_CHG_STAT don't seem to reliably produce events unless they're paired with a change in USB_DETECT. Maybe a GPIO_PIN_CNF_SENSE needs to be added.

Also on my device it seems that the device doesn't charge continuously at 4.11 V even though the "full" threshold is 4.19 V, which may explain the behavior in this devzone question.

koffes commented 6 years ago

Thank you. I see that the pull request was submitted 9 hours ago, and 7 hours ago you stated that you are fairly convinced that the original code is correct. Am I right in assuming that we should just close the PR?

pabigot commented 6 years ago

Sure. I don't know how the behavior is reconciled with the datasheet's description of the CSO signal and the PCA20020 schematics, but reality wins over theory: the signal is low when charging is active.

pabigot commented 6 years ago

Now I do see it: in the XC6804 datasheet Electrical Characteristics CSO Pin ON Voltage is documented as 0.5 V, while CSO Pin OFF maximum Current is given for V_CISO at 6 V. So ON is off, and OFF is on. This is the world we live in....