I have a Raspberry Pi Pico modified with an AP33772 USB controller that allows me to…
- User
I have a Raspberry Pi Pico modified with an AP33772 USB controller that allows me to pull specific voltages from a PPS enabled USB C power supply. The Pi also includes sensors for the USB C current and voltage, as well as the Pico's normal ADC interface. I would like to implement Constant Current lithium ion cell charging by manipulating the USB C output voltage to maintain the constant current.
Following Ohms law, I need to determine what my resistance parameter is to manipulate voltage to control the output current. How do I best do that?
Assistant
To implement Constant Current (CC) lithium-ion cell charging using your Raspberry Pi Pico and AP33772 USB controller, you need to carefully control the voltage output of the USB-C power supply to maintain a constant current into the battery. Here's how you can approach this problem step by step:
1. Understand the Relationship Between Voltage, Current, and Resistance
Ohm's Law states:
Where:
- is the voltage across the load (the battery in this case),
- is the current flowing through the load,
- is the effective resistance of the load.
In your case, the "load" is the lithium-ion battery being charged. However, the internal resistance of the battery () is not fixed—it changes dynamically with the state of charge (SoC), temperature, and other factors. This means you cannot rely on a static value for .
Instead, you will use feedback from your sensors to dynamically adjust the voltage output of the USB-C power supply to maintain the desired charging current.
2. Feedback Loop for Constant Current Control
To achieve constant current charging:
- Measure the Charging Current: Use the current sensor on your setup to measure the actual current flowing into the battery.
- Compare with Desired Current: Compare the measured current () with your target charging current ().
- Adjust the Voltage Output: If , increase the voltage output of the USB-C power supply. If , decrease the voltage output.
This forms a closed-loop control system where the voltage output is continuously adjusted to maintain the desired current.
3. Determine the Effective Resistance
While you don't need to explicitly calculate the battery's internal resistance (), understanding the relationship between voltage and current is still important. The effective resistance seen by the power supply includes:
- The internal resistance of the battery (),
- Any additional resistance in the circuit (e.g., wiring, connectors).
The total resistance () can be approximated as:
Where:
- is the change in voltage applied by the USB-C power supply,
- is the resulting change in current.
You can estimate experimentally by making small adjustments to the voltage and observing the corresponding changes in current.
4. Implementation Steps
Here’s how you can implement this on your Raspberry Pi Pico:
a. Set Up Sensors
- Use the ADC interface to read the voltage across the battery.
- Use the current sensor to measure the charging current.
b. Define the Target Current
Choose a safe charging current for your lithium-ion cell (e.g., 0.5C or 1C, depending on the battery's capacity).
c. Control Loop
Write a control loop in your code to adjust the USB-C voltage based on the measured current:
import time # Constants TARGET_CURRENT = 1.0 # Amps (set your desired charging current here) VOLTAGE_STEP = 0.05 # Volts (small step size for adjustments) MAX_VOLTAGE = 5.0 # Maximum allowed voltage MIN_VOLTAGE = 3.0 # Minimum allowed voltage # Initialize variables current_voltage = 4.0 # Start with a safe voltage while True: # Read sensor values measured_current = read_current_sensor() # Function to read current measured_voltage = read_voltage_sensor() # Function to read voltage # Adjust voltage based on current error current_error = TARGET_CURRENT - measured_current if current_error > 0: # Increase voltage to boost current current_voltage += VOLTAGE_STEP elif current_error < 0: # Decrease voltage to reduce current current_voltage -= VOLTAGE_STEP # Clamp voltage within safe limits current_voltage = max(MIN_VOLTAGE, min(current_voltage, MAX_VOLTAGE)) # Set the new voltage on the USB-C power supply set_usb_c_voltage(current_voltage) # Wait before next iteration time.sleep(0.1)d. Safety Checks
- Ensure the voltage does not exceed the maximum safe charging voltage for the lithium-ion cell (typically 4.2V).
- Monitor the temperature of the battery and stop charging if it exceeds safe limits.
5. Calibration and Testing
- Test the system with a known load to verify that the current remains constant as the voltage is adjusted.
- Gradually increase the complexity by testing with an actual lithium-ion cell.
- Fine-tune the control parameters (e.g., ) to achieve stable and accurate current regulation.
6. Transition to Constant Voltage (CV) Mode
Once the battery voltage reaches 4.2V (or the specified maximum for your cell), switch to Constant Voltage (CV) mode. In this mode, the voltage is held constant at 4.2V, and the current naturally decreases as the battery approaches full charge.
Final Answer
To determine the "resistance parameter" for controlling the current, you don't need to calculate it explicitly. Instead, use a feedback loop to dynamically adjust the USB-C voltage based on the measured current. This ensures the charging current remains constant regardless of the battery's internal resistance or other factors.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.