Tesla charger programming/source code
Tesla charger programming/source code
Programming question, can you help Tom, or anyone....
I want to be able to close a relay to short phase 1.2.3, when I charge at 1 phase outlet. Relay is connected to DIG_out_3.
Is there a safe way to activate the relay in software?
I was thinking to read ACpres or acvolt.
If AC is only present on phase 1 chargermodule, then it should close the relay, and change charger mode from 3 phase to 1 phase, and stay in this mode until disconnect of EVSE.
All chargermodules will get AC, and can charge with higher amp.
I want to be able to close a relay to short phase 1.2.3, when I charge at 1 phase outlet. Relay is connected to DIG_out_3.
Is there a safe way to activate the relay in software?
I was thinking to read ACpres or acvolt.
If AC is only present on phase 1 chargermodule, then it should close the relay, and change charger mode from 3 phase to 1 phase, and stay in this mode until disconnect of EVSE.
All chargermodules will get AC, and can charge with higher amp.
Thomas A. Edison “I have not failed. I've just found 10,000 ways that won't work"
- tom91
- Posts: 2299
- Joined: Fri Mar 01, 2019 9:15 pm
- Location: Bristol
- Has thanked: 199 times
- Been thanked: 526 times
Re: Tesla charger programming/source code
You can do this, however it requires some clever timing.
The charger phases need to see AC voltage within 'x' amount of seconds of being enabled.
I would be very careful of doing this, as any relay failure will cause huge consequences. Quite a lot testing and validation would be required before I would use it on an EVSE.
The charger phases need to see AC voltage within 'x' amount of seconds of being enabled.
I would be very careful of doing this, as any relay failure will cause huge consequences. Quite a lot testing and validation would be required before I would use it on an EVSE.
Re: Tesla charger programming/source code
The OEM setup on the Tesla can do this.
The charger will always be in 3 phase mode, and only shift to 1 phase if missing AC on phase 2 and 3.
If relay should close when on 3 phase, then AC fuse in car and grid will blow, and relay would probably go bad...
No harm to charger or EVSE, as I can think of.
I was thinking of making a seperate module to close the "1 phase" relay, but the charger already has the circuitry to measure AC.
The charger will always be in 3 phase mode, and only shift to 1 phase if missing AC on phase 2 and 3.
If relay should close when on 3 phase, then AC fuse in car and grid will blow, and relay would probably go bad...
No harm to charger or EVSE, as I can think of.
I was thinking of making a seperate module to close the "1 phase" relay, but the charger already has the circuitry to measure AC.
Thomas A. Edison “I have not failed. I've just found 10,000 ways that won't work"
- Kevin Sharpe
- Posts: 1345
- Joined: Fri Dec 14, 2018 9:24 pm
- Location: Ireland and US
- Been thanked: 8 times
Re: Tesla charger programming/source code
Tesla have a module for this that connects to the Gen 2 charger AC. It's a stand alone unit that is not directly controlled by the charger. I posted some information on DIY Electric (here).
It may not work with the open source controller.
This is a personal post and I disclaim all responsibility for any loss or damage which any person may suffer from reliance on the information and material in this post or any opinion, conclusion or recommendation in the information and material.
Re: Tesla charger programming/source code
Thank you, will first try to use the relay and the charger board, have it already connected.Kevin Sharpe wrote: ↑Mon May 11, 2020 2:37 pmTesla have a module for this that connects to the Gen 2 charger AC. It's a stand alone unit that is not directly controlled by the charger. I posted some information on DIY Electric (here).
It may not work with the open source controller.
If I do like this I don't have to do timing of the startup/relay sequence.
I was thinking, to always start in 3 phase mode.
If connected to 3 phase, it will start in 3 phase mode and start all modules, and charge like normal.
If connected to 1 phase, it will start in same mode, but will only see voltage (AC) on phase 1.
Then it can restart, set the mode to 1 phase, close the relay on DIG_out_3, start all modules, and charge like normal.
If EVSE is disconnected it will start in 3 phase mode, when connected again.
If anyone want to help with some programming example, I will be very happy. Will probably manage to do it myself, with many long nights and struggles, I'm a not a good programmer!!
Thomas A. Edison “I have not failed. I've just found 10,000 ways that won't work"
- tom91
- Posts: 2299
- Joined: Fri Mar 01, 2019 9:15 pm
- Location: Bristol
- Has thanked: 199 times
- Been thanked: 526 times
Re: Tesla charger programming/source code
That sounds like it would work yes. all you have to change/over ride is the variable for the phase wiring type.
Re: Tesla charger programming/source code
Here is the code I use now, if you have nothing to do, please feel free to help

This could be a nice feature to have in the official version to.....
https://github.com/jomy-tech/My_Tesla_Charger
Thomas A. Edison “I have not failed. I've just found 10,000 ways that won't work"
Re: Tesla charger programming/source code
I think I found a simpler way to do this. Do you think it will work?
At least, this way it will not go boom, if contactor fails or get welded!!
The charger will be in 1Phase mode all time, N-L1 connected to all modules.
When there is 400VAC on L2-L3, contactor will close and connect phase123 to module 123, and set IN2 high.
It will still need some program changes, to tell the charger to switch to 3phase mode, when IN2 is high. Can not find a contactor/relay with 3PDT and 400VAC coil, but it should be possible to use something like this from RS:
https://uk.rs-online.com/web/p/contactors/7447184/

At least, this way it will not go boom, if contactor fails or get welded!!
The charger will be in 1Phase mode all time, N-L1 connected to all modules.
When there is 400VAC on L2-L3, contactor will close and connect phase123 to module 123, and set IN2 high.
It will still need some program changes, to tell the charger to switch to 3phase mode, when IN2 is high. Can not find a contactor/relay with 3PDT and 400VAC coil, but it should be possible to use something like this from RS:
https://uk.rs-online.com/web/p/contactors/7447184/
Thomas A. Edison “I have not failed. I've just found 10,000 ways that won't work"
Re: Tesla charger programming/source code
Here is the code that need to be changed:
You could also edit the setup description: pinMode(DIG_IN_2, INPUT); // High in 3phase mode.
You will not be able to change between 1ph and 3ph in the menu, so you might as well remove it.
Code: Select all
// Find this: (line 390 or something, depending on version)
evseread();
autoShutdown();
watchdogReset();
manualMode();
// Add the following:
if (digitalRead(DIG_IN_2) == HIGH)
parameters.phaseconfig = Threephase;
else
parameters.phaseconfig = Singlephase;
You will not be able to change between 1ph and 3ph in the menu, so you might as well remove it.
Thomas A. Edison “I have not failed. I've just found 10,000 ways that won't work"
Re: Tesla charger programming/source code
Charger stop charging at that voltage, set it a little higher than the BMS shut off voltage.
Remember to test it, because the charger don't measure accurately.
Remember to test it, because the charger don't measure accurately.
Thomas A. Edison “I have not failed. I've just found 10,000 ways that won't work"
- EV_Builder
- Posts: 1205
- Joined: Tue Apr 28, 2020 3:50 pm
- Location: The Netherlands
- Has thanked: 18 times
- Been thanked: 37 times
- Contact:
Re: Tesla charger programming/source code
The safest implementation of this is by hooking 2 extra 230VAC relais (small ones) parallel on each incomeing phase.
The contacts of them are then in series. And those are in the A1 or A2 side of your switch over relais.
Then the software detects there are missing phases and command the change over relais to bundle the phases and if the hardware detects otherwise it won't happen.... (You do need to make up your mind if you are willing to power the socket back to the charger with extra phases)...
I think this would be a Safe, level one, solution. In order to get into higher safety levels you need to read back contacts of the relais and use 'safety relais'. But i don't think that would be needed in this situation since i suspect there are electronic fuses in the charger which will detect some anomalies.
The contacts of them are then in series. And those are in the A1 or A2 side of your switch over relais.
Then the software detects there are missing phases and command the change over relais to bundle the phases and if the hardware detects otherwise it won't happen.... (You do need to make up your mind if you are willing to power the socket back to the charger with extra phases)...
I think this would be a Safe, level one, solution. In order to get into higher safety levels you need to read back contacts of the relais and use 'safety relais'. But i don't think that would be needed in this situation since i suspect there are electronic fuses in the charger which will detect some anomalies.
Converting an Porsche Panamera
see http://www.wdrautomatisering.nl for bespoke BMS modules.
see http://www.wdrautomatisering.nl for bespoke BMS modules.