Help with a Simple (Hopefully) CCS Charge Curve? Topic is solved

Development and discussion of fast charging systems eg Chademo , CCS etc
Post Reply
P.S.Mangelsdorf
Posts: 946
Joined: Tue Sep 17, 2019 8:33 pm
Location: Raleigh, NC, USA
Has thanked: 150 times
Been thanked: 199 times

Help with a Simple (Hopefully) CCS Charge Curve?

Post by P.S.Mangelsdorf »

Since FOCCCI requires something else to tell it what current to request from the charge station, and my BMS is not set up to do that, I'm working on a simple board to take the battery voltage (in my case from the ISA shunt, but from the BMS could work too) and then output a current request based on these and basic ramping (reduce current at low voltage, ramp down to full charge). Later, I hope to add controls for temperature, but for right now I'm focused on ramping based on SOC.

I'm basing it off of this board: https://www.longan-labs.cc/1030018.html
Which uses this library: https://github.com/Longan-Labs/Arduino_ ... ree/master

The code block below is the best effort of myself and ChatGPT. Can anyone check my work? I'm really out of my depth here:

Code: Select all

#include <SPI.h>
#include <mcp_canbus.h>

#define SPI_CS_PIN  17 

MCP_CAN CAN(SPI_CS_PIN); // Set CS pin


unsigned long lastSendTime = 0;
const unsigned long sendInterval = 250; // 0.25 seconds
const int maxChargePower = 50000; // 50kW in watts
const int targetVoltage = 400; // Target voltage in volts
const int maxVoltage = 398; // Maximum voltage in volts
const int minVoltage = 288; // Minimum voltage in volts

void setup() {
  SPI.begin();
  if (CAN.begin(CAN_500KBPS) == CAN_OK) {
    Serial.begin(9600);
    Serial.println("CAN init ok!");
  } else {
    Serial.println("CAN init fail");
    while (1);
  }
}

void loop() {
  if (millis() - lastSendTime >= sendInterval) {
    lastSendTime = millis();
    
    // Receive voltage message
    if (CAN_MSGAVAIL == CAN.checkReceive()) {
      unsigned char len = 0;
      unsigned char buf[8];
      CAN.readMsgBuf(&len, buf);
      unsigned long canId = CAN.getCanId();
      if (canId == 0x522) {
        int voltage = (buf[2] << 8) | buf[3]; // Voltage in millivolts
        voltage /= 1000; // Convert to volts

        // Calculate charge current request
        int chargeCurrent = calculateChargeCurrent(voltage);

        // Send charge current request
        sendChargeCurrentRequest(chargeCurrent);

        // Send target voltage
        sendTargetVoltage(targetVoltage);

        // Calculate and send SOC
        int soc = calculateSOC(voltage);
        sendSOC(soc);
      }
    }
  }
}

int calculateChargeCurrent(int voltage) {
  int chargePower;
  if (voltage < 300) {
    chargePower = 20000; // 20kW
  } else if (voltage < 320) {
    chargePower = 35000; // 35kW
  } else if (voltage < 376) {
    chargePower = maxChargePower; // 50kW
  } else if (voltage < maxVoltage) {
    chargePower = maxChargePower * (maxVoltage - voltage) / (maxVoltage - 376);
  } else {
    chargePower = 0;
  }
  return chargePower / voltage; // Current in amps
}

void sendChargeCurrentRequest(int chargeCurrent) {
  unsigned char data[8] = {0};
  data[0] = chargeCurrent & 0xFF;
  data[1] = (chargeCurrent >> 8) & 0xFF;
  CAN.sendMsgBuf(0x300, 0, 8, data);
}

void sendTargetVoltage(int targetVoltage) {
  unsigned char data[8] = {0};
  data[0] = targetVoltage & 0xFF;
  data[1] = (targetVoltage >> 8) & 0xFF;
  CAN.sendMsgBuf(0x301, 0, 8, data);
}

int calculateSOC(int voltage) {
  return (voltage - minVoltage) * 100 / (maxVoltage - minVoltage);
}

void sendSOC(int soc) {
  unsigned char data[8] = {0};
  data[0] = soc & 0xFF;
  data[1] = (soc >> 8) & 0xFF;
  CAN.sendMsgBuf(0x301, 0, 8, data);
}
If at first you don't succeed, buy a bigger hammer.

1940 Chevrolet w/ Tesla LDU - "Shocking Chevy" - Completed Hot Rod Drag Week 2023 and 2024

https://www.youtube.com/@MangelsdorfSpeed
User avatar
johu
Site Admin
Posts: 6227
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 228 times
Been thanked: 1273 times
Contact:

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by johu »

Here my 3 step version https://github.com/jsphuebner/stm32-car ... s.cpp#L121

It is based on the highest individual cell voltage though not total pack
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
P.S.Mangelsdorf
Posts: 946
Joined: Tue Sep 17, 2019 8:33 pm
Location: Raleigh, NC, USA
Has thanked: 150 times
Been thanked: 199 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by P.S.Mangelsdorf »

johu wrote: Sun Sep 08, 2024 8:21 am Here my 3 step version https://github.com/jsphuebner/stm32-car ... s.cpp#L121

It is based on the highest individual cell voltage though not total pack
Thanks, I'm going this much cruder route given my time constraints and what I have on hand. Eventually, my very ambitious plan is to have a Zombie-esque STM32 board that just handles battery stuff - talks to the OEM BMS, charger, DC-DC, FOCCCI. But right now I just need CCS to work, and unfortunately my CANDue based CAN interface has crapped out, so I can't easily see what's getting sent. I have stuff on the way to hopefully address that, but not arriving until Wednesday.
If at first you don't succeed, buy a bigger hammer.

1940 Chevrolet w/ Tesla LDU - "Shocking Chevy" - Completed Hot Rod Drag Week 2023 and 2024

https://www.youtube.com/@MangelsdorfSpeed
P.S.Mangelsdorf
Posts: 946
Joined: Tue Sep 17, 2019 8:33 pm
Location: Raleigh, NC, USA
Has thanked: 150 times
Been thanked: 199 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by P.S.Mangelsdorf »

Just to update in case it helps anyone else: I did eventually get this code working, on the 4th revision. Using some of the examples from Longan Labs, I figured out a better way to structure/handle the CAN messages. It took a bit of common sense and basic code knowledge to catch the issues with the ChatGPT proposed code. Namely, ChatGPT kept wanting to structure it so that the outgoing message timer was only triggered after a new battery voltage message came it.

My code is below, in case anyone wants to use it. It is intended for a Longan Labs CANBed RP2040. Please note, there are a few things hard coded you'll likely want to adjust, including max/min voltages, max power (in my case its set to 50kW), and the voltages at which ramping occurs.

Code: Select all

#include <Arduino.h>
#include <SPI.h>
#include <mcp_canbus.h>

#define SPI_CS_PIN  9 

MCP_CAN CAN(SPI_CS_PIN); // Set CS pin

#define CAN_500KBPS         16

unsigned long lastSendTime = 0;
const unsigned long sendInterval = 250; // 0.25 seconds
const int maxChargePower = 50000; // 50kW in watts
const int targetVoltage = 398; // Target voltage in volts
const int maxVoltage = 398; // Maximum voltage in volts
const int minVoltage = 288; // Minimum voltage in volts

int voltage = 0;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  while (CAN_OK != CAN.begin(CAN_500KBPS)) {    // init can bus : baudrate = 500k
    Serial.println("CAN BUS FAIL!");
    delay(100);
  }
  Serial.println("CAN BUS OK!");

  // Set mask to accept all bits
  CAN.init_Mask(0, 0, 0x7FF);
  CAN.init_Mask(1, 0, 0x7FF);

  // Set filter for specific ID 0x522
  CAN.init_Filt(0, 0, 0x522); // Filter 0 for ID 0x522
}

void loop() {
    // Declare required variables
    long unsigned int rxId;
    unsigned char len = 0;
    unsigned char rxBuf[8];
    int batteryVoltage = 0;

    // Check for new CAN messages
    if (CAN.checkReceive() == CAN_MSGAVAIL) { // Check if data is available
        CAN.readMsgBufID(&rxId, &len, rxBuf);
        if (rxId == 0x522) { // Process only messages with ID 0x522
            // Extract battery voltage from CAN message
            long batteryVoltage = (long)((rxBuf[5] << 24) | (rxBuf[4] << 16) | (rxBuf[3] << 8) | rxBuf[2]); // Voltage in millivolts
            voltage = batteryVoltage / 1000; // Convert to volts and store
        }
    }
  
  if (millis() - lastSendTime >= sendInterval) {
    lastSendTime = millis();
    
        // Calculate charge current request
        int chargeCurrent = calculateChargeCurrent(voltage);

        // Send charge current request
        sendChargeCurrentRequest(chargeCurrent);

        // Send target voltage
        sendTargetVoltage(targetVoltage);

        // Calculate and send SOC
        int soc = calculateSOC(voltage);
        sendSOC(soc);
      
    }
  }


int calculateChargeCurrent(int voltage) {
  int chargePower;
  if (voltage < 300) {
    chargePower = 20000; // 20kW
  } else if (voltage < 320) {
    chargePower = 35000; // 35kW
  } else if (voltage < 376) {
    chargePower = maxChargePower; // 50kW
  } else if (voltage < maxVoltage) {
    chargePower = maxChargePower * (maxVoltage - voltage) / (maxVoltage - 376);
  } else {
    chargePower = 0;
  }
  return chargePower / voltage; // Current in amps
}

void sendChargeCurrentRequest(int chargeCurrent) {
  unsigned char data[8] = {0};
  data[0] = chargeCurrent & 0xFF;
  data[1] = (chargeCurrent >> 8) & 0xFF;
  CAN.sendMsgBuf(0x300, 0, 8, data);
}

void sendTargetVoltage(int targetVoltage) {
  unsigned char data[8] = {0};
  data[0] = targetVoltage & 0xFF;
  data[1] = (targetVoltage >> 8) & 0xFF;
  CAN.sendMsgBuf(0x301, 0, 8, data);
}

int calculateSOC(int voltage) {
  return (voltage - minVoltage) * 100 / (maxVoltage - minVoltage);
}

void sendSOC(int soc) {
  unsigned char data[8] = {0};
  data[0] = soc & 0xFF;
  data[1] = (soc >> 8) & 0xFF;
  CAN.sendMsgBuf(0x305, 0, 8, data); // Changed message ID to 0x305
}
If at first you don't succeed, buy a bigger hammer.

1940 Chevrolet w/ Tesla LDU - "Shocking Chevy" - Completed Hot Rod Drag Week 2023 and 2024

https://www.youtube.com/@MangelsdorfSpeed
User avatar
uhi22
Posts: 917
Joined: Mon Mar 14, 2022 3:20 pm
Location: Ingolstadt/Germany
Has thanked: 133 times
Been thanked: 527 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by uhi22 »

Would it help if we integrate such quick and dirty BMS functionality into Foccci? (Not as a recommended approach, but just to simplify the life for situations where a real BMS is not yet funished)
P.S.Mangelsdorf
Posts: 946
Joined: Tue Sep 17, 2019 8:33 pm
Location: Raleigh, NC, USA
Has thanked: 150 times
Been thanked: 199 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by P.S.Mangelsdorf »

uhi22 wrote: Sun Sep 29, 2024 9:12 pm Would it help if we integrate such quick and dirty BMS functionality into Foccci? (Not as a recommended approach, but just to simplify the life for situations where a real BMS is not yet funished)
I'm not sure. I do like that the old CHAdeMO control board could handle everything itself, but I also see the argument for safety and simplicity of wanting some other part of the car to provide the current request. I don't know enough about other BMS's to know if they are capable of sending the requests FOCCCI wants, or if that will require customization/separate boards as I have done here.

This code is just my first stab at it - I do eventually want to add temperature derating and other functionality.

Stepping way back, I think it would be more useful long term to develop a Zombie-type master control board for handling battery functions (communicate with OEM BMS, control chargers, control DC-DC, talk to FOCCCI, etc) and leave FOCCCI for just CCS comms and Zombie for just drivetrain control, but I understand that a) that is personal preference and b) I should improve my C++ skills and do that myself rather than hoping/suggesting someone else do it. It's on my long term project list.
If at first you don't succeed, buy a bigger hammer.

1940 Chevrolet w/ Tesla LDU - "Shocking Chevy" - Completed Hot Rod Drag Week 2023 and 2024

https://www.youtube.com/@MangelsdorfSpeed
tom91
Posts: 1741
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 149 times
Been thanked: 339 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by tom91 »

P.S.Mangelsdorf wrote: Mon Sep 30, 2024 3:46 pm Zombie-type master control board for handling battery functions (communicate with OEM BMS, control chargers, control DC-DC, talk to FOCCCI, etc
Zombie is doing this already, upcoming release will make Foccci supported and a few BMS options also.
Founder Volt Influx https://www.voltinflux.com/
Webstore: https://citini.com/
User avatar
uhi22
Posts: 917
Joined: Mon Mar 14, 2022 3:20 pm
Location: Ingolstadt/Germany
Has thanked: 133 times
Been thanked: 527 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by uhi22 »

Okay, this sounds like the "dirty BMS" inside Foccci is not really helping. Because:
- For cars which have the Zombie, this can calculate the charge current and provide it to Foccci.
- For cars where the BMS itself provides the charge current, Foccci can take this.
- For the Shocking Chevy, Paul has the CANBed RP2040 with a basic charge curve and can improve this step by step, which is a good learing experience.
- Maybe there are more cases, which we can discuss in detail as soon as they occur.
P.S.Mangelsdorf
Posts: 946
Joined: Tue Sep 17, 2019 8:33 pm
Location: Raleigh, NC, USA
Has thanked: 150 times
Been thanked: 199 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by P.S.Mangelsdorf »

tom91 wrote: Mon Sep 30, 2024 5:31 pm Zombie is doing this already, upcoming release will make Foccci supported and a few BMS options also.
I knew Zombie was handling chargers and DCDC, did not know it would be supporting OEM BMSs.

My line of thinking was a Zombie based board that in some ways took the place of SimpBMS for those of us in North America, and handled just battery functions. Personally, I'd like battery functions to be handled separately from drivetrain, but as noted I know that's a personal preference.
uhi22 wrote: Mon Sep 30, 2024 6:55 pm - For cars where the BMS itself provides the charge current, Foccci can take this.
...
- Maybe there are more cases, which we can discuss in detail as soon as they occur.
I do wonder how many BMSs currently can do this, but I agree it is the preferrable option.
uhi22 wrote: Mon Sep 30, 2024 6:55 pm Paul has the CANBed RP2040 with a basic charge curve and can improve this step by step, which is a good learing experience.
It's certainly a learning experience!

I also just want to add my thanks to both of you for the work you've done on BMSs and FOCCCI respectively, it is a huge service to the community and I really respect your work and knowledge. I don't think we all thank you enough for your efforts, so once again, thank you.
If at first you don't succeed, buy a bigger hammer.

1940 Chevrolet w/ Tesla LDU - "Shocking Chevy" - Completed Hot Rod Drag Week 2023 and 2024

https://www.youtube.com/@MangelsdorfSpeed
tom91
Posts: 1741
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 149 times
Been thanked: 339 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by tom91 »

P.S.Mangelsdorf wrote: Tue Oct 01, 2024 1:33 pm My line of thinking was a Zombie based board that in some ways took the place of SimpBMS for those of us in North America, and handled just battery functions. Personally, I'd like battery functions to be handled separately from drivetrain, but as noted I know that's a personal preference.
Zombie does not handle batteries it handles BMS information, so it would function with/along side a SimpBMS/OEM BMS/EVS-BMS

The BMS MUST define the charge curve as it has all the info to hand. Believe Thunderstruck BMS was forced to do this to handle the Fellten CCS kit.
At the very least it must handle battery limits and be capable of stopping charging.
Founder Volt Influx https://www.voltinflux.com/
Webstore: https://citini.com/
Aragorn
Posts: 153
Joined: Wed Jan 04, 2023 10:23 am
Has thanked: 6 times
Been thanked: 61 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by Aragorn »

Why are you limiting charge current so much at lower SOC?

Dont most EV's see thier highest charging powers at those lowest points?
User avatar
uhi22
Posts: 917
Joined: Mon Mar 14, 2022 3:20 pm
Location: Ingolstadt/Germany
Has thanked: 133 times
Been thanked: 527 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by uhi22 »

I think the idea is: At low SOC there is an increased inner resistance. Pushing the full current would produce heat, which speeds up the aging. But depending on the cell type this seems to be not always necessary, my Ioniq takes 175A constant from 0% to 78% at normal temperatures.
P.S.Mangelsdorf
Posts: 946
Joined: Tue Sep 17, 2019 8:33 pm
Location: Raleigh, NC, USA
Has thanked: 150 times
Been thanked: 199 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by P.S.Mangelsdorf »

Aragorn wrote: Tue Oct 01, 2024 3:18 pm Why are you limiting charge current so much at lower SOC?

Dont most EV's see thier highest charging powers at those lowest points?
uhi22 wrote: Tue Oct 01, 2024 7:19 pm I think the idea is: At low SOC there is an increased inner resistance. Pushing the full current would produce heat, which speeds up the aging. But depending on the cell type this seems to be not always necessary, my Ioniq takes 175A constant from 0% to 78% at normal temperatures.
I had mostly read that they had highest power at the middle of the charge curve.

From the DOE testing of these batteries, they can take more power and abuse than I am giving them, but I do want to be careful and not add to the degradation. I'm already doing the inadvisable heavy depletion and charge to 100% repeatedly on these road trips, so I want to be as gentle as I can otherwise.

I definitely will be making adjustments to this curve over time as I learn more.
If at first you don't succeed, buy a bigger hammer.

1940 Chevrolet w/ Tesla LDU - "Shocking Chevy" - Completed Hot Rod Drag Week 2023 and 2024

https://www.youtube.com/@MangelsdorfSpeed
Aragorn
Posts: 153
Joined: Wed Jan 04, 2023 10:23 am
Has thanked: 6 times
Been thanked: 61 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by Aragorn »

Take a look at the Fastned charging curves for various EV's, they all go hard right from the low end then taper off as the SOC increases.

Perhaps be careful below 10%, especially if you've run it really low, but from 10% upwards you should be able to run 50kw

An example:
Fastned_Chargingcurve_Volkswagen_IDBuzz_82kWh_2023_Q4.png
User avatar
muehlpower
Posts: 635
Joined: Fri Oct 11, 2019 10:51 am
Location: Germany Fürstenfeldbruck
Has thanked: 12 times
Been thanked: 116 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by muehlpower »

I found this charging curve from Texas Instruments. It shows that up to 3V cell voltage is only charged with 10%, then full power until the maximum cell voltage of 4.1V is reached. This is maintained until the current has dropped to 10%. This is the end of charging. This behavior corresponds to what I have seen in OEM cars, but there is always no indication of the cell voltage, which is required for control.
Ladekurve.png
Aragorn
Posts: 153
Joined: Wed Jan 04, 2023 10:23 am
Has thanked: 6 times
Been thanked: 61 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by Aragorn »

Yeah, i imagine most OEM cars wouldnt let the battery get below 3v per cell anyway... Hence they all go very quickly to full current.
P.S.Mangelsdorf
Posts: 946
Joined: Tue Sep 17, 2019 8:33 pm
Location: Raleigh, NC, USA
Has thanked: 150 times
Been thanked: 199 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by P.S.Mangelsdorf »

muehlpower wrote: Thu Oct 03, 2024 2:08 pm I found this charging curve from Texas Instruments. It shows that up to 3V cell voltage is only charged with 10%, then full power until the maximum cell voltage of 4.1V is reached. This is maintained until the current has dropped to 10%. This is the end of charging. This behavior corresponds to what I have seen in OEM cars, but there is always no indication of the cell voltage, which is required for control.

Ladekurve.png
That's interesting - so they're continuing to provide (decreasing) current after reaching full voltage?

I do know that these Volt packs' charge/discharge curve is more linear than that example, so not sure how that impacts it.
If at first you don't succeed, buy a bigger hammer.

1940 Chevrolet w/ Tesla LDU - "Shocking Chevy" - Completed Hot Rod Drag Week 2023 and 2024

https://www.youtube.com/@MangelsdorfSpeed
User avatar
muehlpower
Posts: 635
Joined: Fri Oct 11, 2019 10:51 am
Location: Germany Fürstenfeldbruck
Has thanked: 12 times
Been thanked: 116 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by muehlpower »

Actually it should be quite easy. Up to 3V 0.1C, so in my case 74000Wh/360V/10=20A, then 200A. At the same time transmit a voltage of 4.1Vx96= 393V. Then the charging station should automatically reduce the amps so as not to go above 393V. For the 3V, the cell with the lowest voltage is crucial. To transmit the maximum voltage, the cell with the highest voltage must be observed and the value corrected if necessary. There is no need to reduce the amps, just observe and stop charging at 20A.

In addition, the temperatures of the battery and the connection should be monitored and the current reduced if necessary. Battery 10°C to 45°C, connection up to max 70°C
P.S.Mangelsdorf
Posts: 946
Joined: Tue Sep 17, 2019 8:33 pm
Location: Raleigh, NC, USA
Has thanked: 150 times
Been thanked: 199 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by P.S.Mangelsdorf »

After doing some testing this weekend, I'm definitely going to do some tweaking to the curve. It ramps down way too early and too far. Not sure the details yet, but hoping to work on that this week and test again next weekend.
If at first you don't succeed, buy a bigger hammer.

1940 Chevrolet w/ Tesla LDU - "Shocking Chevy" - Completed Hot Rod Drag Week 2023 and 2024

https://www.youtube.com/@MangelsdorfSpeed
User avatar
uhi22
Posts: 917
Joined: Mon Mar 14, 2022 3:20 pm
Location: Ingolstadt/Germany
Has thanked: 133 times
Been thanked: 527 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by uhi22 »

Missing Pete. The charge curve would be a perfect topic for testing on a simulator...
P.S.Mangelsdorf
Posts: 946
Joined: Tue Sep 17, 2019 8:33 pm
Location: Raleigh, NC, USA
Has thanked: 150 times
Been thanked: 199 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by P.S.Mangelsdorf »

No update on testing this week - I had to get caught up on things around the house. Weather here in NC decided to jump straight from summer to late fall and I was behind on yard work. Maybe some opportunities this week.
If at first you don't succeed, buy a bigger hammer.

1940 Chevrolet w/ Tesla LDU - "Shocking Chevy" - Completed Hot Rod Drag Week 2023 and 2024

https://www.youtube.com/@MangelsdorfSpeed
Zieg
Posts: 231
Joined: Mon Apr 25, 2022 3:31 am
Has thanked: 104 times
Been thanked: 92 times

Re: Help with a Simple (Hopefully) CCS Charge Curve?

Post by Zieg »

So is 1c kind of a safe limit to follow, assuming temps stay down? And would that be defined as charging amps = 1 x the amp hour capacity, or charging kW = 1 x the kWh capacity?
Post Reply