Coder Social home page Coder Social logo

alexklimaj / lipow-firmware Goto Github PK

View Code? Open in Web Editor NEW
312.0 312.0 96.0 3.45 MB

Lipo Battery Charger with USB C Power Delivery Based on the STM32G0

Home Page: https://arkelectron.com/product/lipow-the-usb-c-lipo-battery-charger/

License: GNU General Public License v3.0

C 98.88% C++ 0.82% Assembly 0.16% Makefile 0.14%

lipow-firmware's People

Contributors

alexklimaj avatar dakejahl avatar yohmartst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lipow-firmware's Issues

Trouble issuing commands via UART.

I'm connecting the LiPow charger via UART to a Raspberry Pi 3. When opening a serial console with cu -l /dev/ttyS0 -s 921600, I can run commands without any problem.

pi@dronebox:~ $ cu -l /dev/ttyS0 -s 921600
Connected.
>help

help:
 Lists all the registered commands


stats:
 Displays a table showing the system stats

cal:
 Calibrates the ADC based on a known input voltage. Expects one argument as a float in milivolts. Connect input voltage to cells 1-4 and the XT60 battery output.

write_otp:
 Writes the calibration scalars to OTP flash. Will fail if scalars not set or out of range. Must run cal first with known accurate voltage. Can run up to ~32 times.

task-stats:
 Displays a table showing the state of each FreeRTOS task

run-time-stats:
 Displays a table showing how much processing time each FreeRTOS task has used

[Press ENTER to execute the previous command again]
>stats
Variable                    Value
************************************************
Battery Voltage MCU(V)       0.000
Battery Voltage Reg (V)      2.880
Charging Current (A)         0.000
Charging Power (W)           0.000
Cell One Voltage (V)         0.000
Cell Two Voltage (V)         0.000
Cell Three Voltage (V)       0.000
Cell Four Voltage (V)        0.000
2 Series Voltage (V)         0.000
3 Series Voltage (V)         0.000
4 Series Voltage (V)         0.000
MCU Temperature (C)          29
VDDa (V)                     3.291
XT60 Connected               0
Balance Connection State     0
Number of Cells              0
Battery Requires Charging    0
Balancing State/Bitmask      0
Regulator Connection State   1
Charging State               0
Max Charge Current           0.000
Vbus Voltage (V)             5.056
Input Current (A)            0.000
Input Power (W)              0.000
Efficiency (OutputW/InputW)  nan
Battery Error State          0

[Press ENTER to execute the previous command again]
>

However, the following Python script, using the pySerial package

import serial
from time import sleep

ser = serial.Serial("/dev/ttyS0", baudrate=921600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=8, timeout=1)
print("sending...")
ser.write('help\n'.encode())
print('receiving...')
received_data = ser.read()
sleep(0.03)
data_left = ser.inWaiting() 
received_data += ser.read(data_left)
print (received_data.decode()) 

, yields the following output:

sending...
receiving...
e
Command not recognized.  Enter 'help' to view a list of available commands.


[Press ENTER to execute the previous command again]
>

Command not recognized.  Enter 'help' to view a list of available commands.


[Press ENTER to execute the previous command again]
>

Command not recognized.  Enter 'help' to view a list of available commands.


[Press ENTER to execute the previous command again]
>

Note the e right after receiving. It seems that the charger echoes part of the command back, as if only an arbitrary substring of the issued command was transmitted.

I've also tried

  • sending \r and \r\n at the end of my command with the same result.
  • using .encode('utf-8') instead of .encode().
  • using b'stats' instead of .encode().

I2C Library for Controlling BQ25703A

Need to write I2C library to communicate and control the programmable regulator. Need to be able to set the number of cells/voltage and current limit.

The following signals are connected from the BQ25703A to the STM32G0.

ILIM_HIZ - Default low on bootup, drive high before beginning charge. Drive low on fault, or end of charge.

Input current limit input. Program ILIM_HIZ voltage by connecting a resistor divider from supply rail to ILIM_HIZ pin to ground. The pin voltage is calculated as: V(ILIM_HIZ) = 1 V + 40 × IDPM × RAC, in which IDPM is the target input current. The input current limit used by the charger is the lower setting of ILIM_HIZ pin and REG0x0F() and REG0x0E(). When the pin voltage is below 0.4 V, the device enters Hi-Z mode with low quiescent current. When the pin voltage is above 0.8 V, the device is out of Hi-Z mode.

PROCHOTn - Need to decide how or if to use this one.

Active low open drain output of processor hot indicator. It monitors adapter input current, battery discharge current, and system voltage. After any event in the PROCHOT profile is triggered, a pulse is asserted. The minimum pulse width is adjustable in REG0x36[5:2].

CHRG_OK - Use to detect charging faults. Only charge if signal is High. Stop charge if low.

Open drain active high indicator to inform the system good power source is connected to the charger input. Connect to the pullup rail via 10-kΩ resistor. When VBUS rises above 3.5V or falls below 24.5V, CHRG_OK is HIGH after 50ms deglitch time. When VBUS is falls below 3.2 V or rises above 26 V, CHRG_OK is LOW. When fault occurs, CHRG_OK is asserted LOW.

EN_OTG - Reserve for future use. Leave low.

Active HIGH to enable OTG mode. When EN_OTG pin is HIGH and REG0x35[4] is HIGH, OTG can be enabled, refer to USB On-The-Go (OTG) for details of how to enable OTG function

Balancing Algorithm

Write balancing algorithm. Control discharging each cell through CELL_XS_DIS_EN.

Take ADC reading from each cell, discharge the higher voltage cells until they are all within +-50mV.

How to calibate

I made circuit board according to LiPow-Hardware by myself.
I plug type-c wire then it told "NOT CALIBRATED".After that i plugged 4s battery and type "cal" command, it told "Incorrect command parameter(s)".
Could u tell me the correct way to calibrate the adc, thank you.

Here is my debug message:

Starting LiPow.
Type Help to view a list of registered commands.
Firmware Version: 1.2

Number of received Source PDOs: 4
PDO From Source: #0 PDO: 134320428 Voltage: 5000mV Current: 3000mA Power: 15000mW
PDO From Source: #1 PDO: 184620 Voltage: 9000mV Current: 3000mA Power: 27000mW
PDO From Source: #2 PDO: 307400 Voltage: 15000mV Current: 2000mA Power: 30000mW
PDO From Source: #3 PDO: 409750 Voltage: 20000mV Current: 1500mA Power: 30000mW
NOT CALIBRATED. Connect known good voltage to cells 1-4 and XT60 in the range of 3.3V - 4V and run cal command.
Then write then to flash with write_otp
cal
Incorrect command parameter(s). Enter "help" to view a list of available commands.

[Press ENTER to execute the previous command again]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.