Tesla charger programming/source code

Topics concerning the Tesla front and rear drive unit drop-in board
Post Reply
User avatar
joromy
Posts: 371
Joined: Fri Jun 28, 2019 12:56 pm
Has thanked: 1 time
Been thanked: 3 times

Tesla charger programming/source code

Post by joromy »

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.
Thomas A. Edison “I have not failed. I've just found 10,000 ways that won't work"
tom91
Posts: 1275
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 97 times
Been thanked: 204 times

Re: Tesla charger programming/source code

Post by tom91 »

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.
Founder Volt Influx https://www.voltinflux.com/
User avatar
joromy
Posts: 371
Joined: Fri Jun 28, 2019 12:56 pm
Has thanked: 1 time
Been thanked: 3 times

Re: Tesla charger programming/source code

Post by joromy »

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.
Thomas A. Edison “I have not failed. I've just found 10,000 ways that won't work"
User avatar
Kevin Sharpe
Posts: 1345
Joined: Fri Dec 14, 2018 9:24 pm
Location: Ireland and US
Been thanked: 4 times

Re: Tesla charger programming/source code

Post by Kevin Sharpe »

joromy wrote: Mon May 11, 2020 9:43 am The OEM setup on the Tesla can do this.
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.
User avatar
joromy
Posts: 371
Joined: Fri Jun 28, 2019 12:56 pm
Has thanked: 1 time
Been thanked: 3 times

Re: Tesla charger programming/source code

Post by joromy »

Kevin Sharpe wrote: Mon May 11, 2020 2:37 pm
joromy wrote: Mon May 11, 2020 9:43 am The OEM setup on the Tesla can do this.
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.
Thank you, will first try to use the relay and the charger board, have it already connected.
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.
Capture_1phase.JPG
Capture_1phase_x3.JPG
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: 1275
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 97 times
Been thanked: 204 times

Re: Tesla charger programming/source code

Post by tom91 »

That sounds like it would work yes. all you have to change/over ride is the variable for the phase wiring type.
Founder Volt Influx https://www.voltinflux.com/
User avatar
joromy
Posts: 371
Joined: Fri Jun 28, 2019 12:56 pm
Has thanked: 1 time
Been thanked: 3 times

Re: Tesla charger programming/source code

Post by joromy »

tom91 wrote: Mon May 11, 2020 6:34 pm That sounds like it would work yes. all you have to change/over ride is the variable for the phase wiring type.
Here is the code I use now, if you have nothing to do, please feel free to help :D
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"
User avatar
joromy
Posts: 371
Joined: Fri Jun 28, 2019 12:56 pm
Has thanked: 1 time
Been thanked: 3 times

Re: Tesla charger programming/source code

Post by joromy »

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.
1phase_3phase.JPG
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"
User avatar
joromy
Posts: 371
Joined: Fri Jun 28, 2019 12:56 pm
Has thanked: 1 time
Been thanked: 3 times

Re: Tesla charger programming/source code

Post by joromy »

Here is the code that need to be changed:

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 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.
Thomas A. Edison “I have not failed. I've just found 10,000 ways that won't work"
Chad B
Posts: 8
Joined: Fri Apr 12, 2019 9:40 pm

Re: Tesla charger programming/source code

Post by Chad B »

What is the function of the termination voltage setting?
User avatar
joromy
Posts: 371
Joined: Fri Jun 28, 2019 12:56 pm
Has thanked: 1 time
Been thanked: 3 times

Re: Tesla charger programming/source code

Post by joromy »

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.
Thomas A. Edison “I have not failed. I've just found 10,000 ways that won't work"
User avatar
EV_Builder
Posts: 1199
Joined: Tue Apr 28, 2020 3:50 pm
Location: The Netherlands
Has thanked: 16 times
Been thanked: 33 times
Contact:

Re: Tesla charger programming/source code

Post by EV_Builder »

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.
Converting an Porsche Panamera
see http://www.wdrautomatisering.nl for bespoke BMS modules.
Post Reply