Several hundred miles later, after making a few changes to the code above I'm happy to report I have regen working reliably. It's not perfect and is dialled back to help keep things smooth but is working well enough for me to move on to something else.
And that is charging.
Up to now I have been plugging the car in during the day, turning on the ignition and setting a timer for the approximate time charging should finish. This is partly to check the charging had stopped as it should but mainly to turn the ignition off again. It has worked for over a year but is a tad suboptimal.
So for the last couple of weeks I've been working on automating the charging process and today I finally got the last part of the puzzle sorted that will allow me to install it.
The first thing I did was build a circuit to detect when the charging plug was shoved in.
This is from a post in another thread.
viewtopic.php?p=79533#p79533
Alibro wrote: ↑Mon Feb 03, 2025 2:39 pm
So after a bit of messing about I came up with a circuit that works well enough to turn on the relays when the charger plug is inserted and turn off the relays when the catch is pressed on the J1772 handle so that I can't pull the handle out with the current still flowing.
PP_Sense.png
In my case the J1772 socket already has a 2.7k resistor going to ground built into it so I took that out of the circuit.
I also found that with 3.3k resistor in the voltage divider circuit from 12V to pin 2 the relays were on all the time even without the cable plugged in. I tried changing the 2.7k resistor but couldn't get the circuit to trigger when the catch was pressed so changed the 3.3k resistor instead. I used a POT fo figure out what the ideal resistance was and it ended up being 255R. I didn't have a 255R resistor have so used a 240R and 13R in series which was close enough.
The relay module I'm using is a 12V 8 way block that can be set to trigger on a neg or pos signal.
https://amzn.to/4hroiOX
This is it on some strip board and so far it's working so now I need to work out how to implement it.
IMG_20250203_145120687.jpg
Next step was to ensure I had a backup or failsafe to prevent over charging so I made some changes to the VCU code. I never used O/P 3 to power up the inverter as it was originally intended so it's now providing GND to the charger. If the pack exceeds a preset voltage which is 2 volts higher than it the default max it will power off the charger which basically crashes out of the over charge situation, in fairness I should have done this earlier and my only excuse is it was less of an issue as I always set an alarm.
Now the charger will turn off when the Charge Control Arduino Due sees the pack reach a preset voltage from the shunt.
And if it fails to stop charging for any reason the VCU uses the Inverter voltage to turn off the charger at a preset voltage
So now I have a circuit that detects when the charger plug is in I needed to figure out how to implement it. I wrote a list of everything required for charging and spent a few nights wiring in a 6 way relay module I intend to use.
To get my head around what was required I wrote it out.
Current Setup
Plug in the cable
Turn on ignition to power up all devices.
The VCU sends GND to the charger to power it up
An Arduino Due checks the voltage from an Isabellenhutte shunt using CAN. If the voltage is within a preset range the Due closes the CP line using a relay (CP Relay) to allow charging to begin. This Arduino Due also sends Voltage, current and power info to the Android head unit over WiFi.
When the Due sees the voltage above a certain level it turns off the relay which disconnects CP and stops charging.
A backup safety is provided by the VCU which will power off the charger if it sees an over volt situation.
New Setup
Scenario 1 - Charging starts and completes
Plug in the charger cable.
LM393 detects EVSE present from PP and sends GND to a relay (ChargeEnable) and PIN8 on the Nano.
The ChargeEnable relay sends GND to power the Nano and at the same time removes GND from Throttle pedal to prevent driving off while plugged in.
The Nano powers the Due using a MOSFET or single relay module then pauses for 2 seconds. This happens only once when the Nano is turned on.
If the voltage is within a preset range the Due closes the CP relay to enable charging to begin.
The CP relay as well as connecting the CP to the charger sends GND to PIN10 of the Nano using 2nd set of contacts.
We push the button to start charging (momentary GND to PIN9) or it starts automagically at 2am.
The Nano checks for PIN8 and PIN10 to GND and if so activates the relays with the last relay sending a second (latching) ground to power the Nano. This is to prevent the Nano crashing should the plug be pulled.
Charging completes and the Arduino Due releases the CP relay to stop the charger.
The relay also disconnects GND from PIN10 so the Nano turns off the Module relays and removes power from the Due.
The Nano will still receive power from the LM393 as the EVSE is still plugged in and the Charge Enable Relay is still closed but this should be OK as even with the relay and LM393 they should only draw around 100 to 150mA with the module relays turned off.
Scenario 2 - Plug pulled while charging
Everything as above.
If the Plug is pulled while the car is charging the LM393 removes GND from the ChargeEnable relay and PIN8 of the Nano
The Nano still has GND through the last relay on the module so remains powered on.
Because the Nano has lost GND on PIN8 it turns off the relays.
When the last relay turns off it removes GND from the Nano which powers it off.
The critical thing both now and when this is implemented is that the battery should never be allowed to charge above 400V.
The Due I use to control this gets it's voltage from the shunt and the VCU which is a fail safe gets it's voltage from the Inverter so hopefully I've mitigated as best I can.