Tesla gen2/gen3 charger arduino code current ramping up and down fix

Topics concerning the Tesla front and rear drive unit drop-in board
Post Reply
m.art.y
Posts: 550
Joined: Sat Jun 06, 2020 6:54 pm
Location: UK
Has thanked: 24 times
Been thanked: 17 times

Tesla gen2/gen3 charger arduino code current ramping up and down fix

Post by m.art.y »

Hi, so those who have used Tesla gen2 and gen3 chargers with arduino version of the control code knows that the code has an issue of the charge current constantly fluctuating - ramping up to preset value then dropping right down then ramping up again every few seconds throughout the entire charging process. Despite this little bug the code is very well written by Damien, Tom de Bree, Collin and whoever else worked on it so it would still be very useful. So with a bit of experimentation I discovered that the current fluctuation only happens when this line of code is in effect:

Code: Select all

modulelimcur = accurlim * 1.5;
. If I replace this line of code with

Code: Select all

modulelimcur = parameters.currReq;
then the charging current is rock solid throughout the charging process. The problem then is that I have to keep manually changing the current request value in the settings depending if I'm charging public or at home. I have noticed that the calculation accurlim = ((duration - (micros() - pilottimer)) * 60000) / duration; (cable current carrying capacity as calculated from CP) produces a little measurement jitter by a couple hundred mA. It still reports correct cable amperage in whole amps but perhaps this little jitter is what throws off the charger. Now my idea is to either modify the calculation of accurlim to round up the calculated value or to sample accurlim once in a while or so and set a new round number current request parameter accordingly which would only be overwritten if it starts differing significantly from what accurlim is reading. Now my coding skills are not yet up to the task to achieve either but it could be very easy for somebody more experienced. Would somebody have any suggestions, ideas and would be willing to give it a go? :)
tom91
Posts: 1278
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 97 times
Been thanked: 205 times

Re: Tesla gen2/gen3 charger arduino code current ramping up and down fix

Post by tom91 »

Easiest is to filter the accurlim and then put it into an rolling average. This means "false" values are ignored, and the response can be slowed.
Founder Volt Influx https://www.voltinflux.com/
m.art.y
Posts: 550
Joined: Sat Jun 06, 2020 6:54 pm
Location: UK
Has thanked: 24 times
Been thanked: 17 times

Re: Tesla gen2/gen3 charger arduino code current ramping up and down fix

Post by m.art.y »

tom91 wrote: Wed Jan 04, 2023 9:09 pm Easiest is to filter the accurlim and then put it into an rolling average. This means "false" values are ignored, and the response can be slowed.
Yes I mean something like that but I wouldn't know how to code it unfortunately. If you would be willing to include this I would be happy to test 😊
tom91
Posts: 1278
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 97 times
Been thanked: 205 times

Re: Tesla gen2/gen3 charger arduino code current ramping up and down fix

Post by tom91 »

I have no idea what hardware it is ran on, so possibly do not even have the right coding environment set up.
Founder Volt Influx https://www.voltinflux.com/
m.art.y
Posts: 550
Joined: Sat Jun 06, 2020 6:54 pm
Location: UK
Has thanked: 24 times
Been thanked: 17 times

Re: Tesla gen2/gen3 charger arduino code current ramping up and down fix

Post by m.art.y »

tom91 wrote: Wed Jan 04, 2023 9:16 pm I have no idea what hardware it is ran on, so possibly do not even have the right coding environment set up.
It is the code here for Damien's earlier boards with SAM3X chip:
https://github.com/damienmaguire/Tesla- ... rgerV4.ino
tom91
Posts: 1278
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 97 times
Been thanked: 205 times

Re: Tesla gen2/gen3 charger arduino code current ramping up and down fix

Post by tom91 »

m.art.y wrote: Wed Jan 04, 2023 9:27 pm It is the code here for Damien's earlier boards with SAM3X chip:
https://github.com/damienmaguire/Tesla- ... rgerV4.ino
Okay maybe got time this week, I have a due to test with.
Founder Volt Influx https://www.voltinflux.com/
m.art.y
Posts: 550
Joined: Sat Jun 06, 2020 6:54 pm
Location: UK
Has thanked: 24 times
Been thanked: 17 times

Re: Tesla gen2/gen3 charger arduino code current ramping up and down fix

Post by m.art.y »

tom91 wrote: Wed Jan 04, 2023 9:29 pm Okay maybe got time this week, I have a due to test with.
Thanks, very excited, happy to test on my charger. I was just thinking maybe my guess was wrong that the jitter is causing the charger to keep dropping the current. Could it be that as the mcu is executing the calculation the accurlim parameter goes 'missing' somehow for a split second?
tom91
Posts: 1278
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 97 times
Been thanked: 205 times

Re: Tesla gen2/gen3 charger arduino code current ramping up and down fix

Post by tom91 »

Updated code with an averaging filter. https://github.com/Tom-evnut/Tesla-Char ... aChargerV4
Founder Volt Influx https://www.voltinflux.com/
m.art.y
Posts: 550
Joined: Sat Jun 06, 2020 6:54 pm
Location: UK
Has thanked: 24 times
Been thanked: 17 times

Re: Tesla gen2/gen3 charger arduino code current ramping up and down fix

Post by m.art.y »

tom91 wrote: Sat Jan 07, 2023 7:14 pm Updated code with an averaging filter. https://github.com/Tom-evnut/Tesla-Char ... aChargerV4
Well I have tested this new code with a 10A granny cable so far and I have to say this has made a difference. Previously the current had been dropping to 1.33Aac then rising up again, now it still drops but only to about 8A when cable is reporting 10A. This then seems apparent where the problem was: once every 5 accurlim readings or so a 0 is dropped in there from somewhere. When using accurlim directly to calculate modulelimcur this then resulted in charger dropping current right down. Rolling average only takes a dip by couple amps 😊. Would you have any idea where this 0 is coming from or how to eliminate it?
User avatar
mjc506
Posts: 343
Joined: Wed Sep 09, 2020 9:36 pm
Location: Wales, United Kingdom
Has thanked: 30 times
Been thanked: 28 times

Re: Tesla gen2/gen3 charger arduino code current ramping up and down fix

Post by mjc506 »

A 'rolling median' might be more immune to those drops. But yeah, finding the true cause is probably a better fix!
Post Reply