Gen 3 inverter converter control software

Topics concerning the Toyota and Lexus inverter drop in boards
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Gen 3 inverter converter control software

Post by bexander »

bexander wrote: Mon Mar 01, 2021 6:24 am Use one of them as input to PWM. Change PWM max once every 20ms or if you will, after complete N number samples as per above.
After further thinking, I don't believe this to be the case. Using a running RMS calculation the PWM update frequency can be left as is.
The problem is the current and not the PWM update speed.
User avatar
celeron55
Posts: 774
Joined: Thu Jul 04, 2019 3:04 pm
Location: Finland
Has thanked: 27 times
Been thanked: 110 times
Contact:

Re: Gen 3 inverter converter control software

Post by celeron55 »

Yeah controlling the lowside is probably a good idea. However I couldn't test it as my lowside is broken.
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Gen 3 inverter converter control software

Post by bexander »

celeron55 wrote: Mon Mar 01, 2021 6:17 pm Yeah controlling the lowside is probably a good idea. However I couldn't test it as my lowside is broken.
If you write the code I'll test it! :)
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Gen 3 inverter converter control software

Post by bexander »

I have done a little adjusting of the code and some tests and I don't think it is the SW, but rather the current measurement at these low currents. I have a extra Yaris inverter and a logic board so I will make measurements on voltage levels and currents for the MG1 current sensors. Will test if I can at least remove the 2,7 times damping and add a small gain to the current sensor output.
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Gen 3 inverter converter control software

Post by bexander »

I have now added a op-amp circuit instead of voltage division on MG1 current sensor output. This removes the 2 time damping and adds a 2,5 time amplification so in total 5 times the voltage at the 328P and a max measurable current of 50A.
MG1_IL_Amp.pdf
Schematics of added circuit
(18.79 KiB) Downloaded 203 times
IMG_1599_crop.JPG
The result is a more stable current and PWM from the charger. This is with the original code concerning the PWM.
Compare the before and after change.
CHG2_1_2_10A.txt
Stock, with voltage division
(13.56 KiB) Downloaded 179 times
CHG2_1_7_1.txt
Changed, with op-amp
(40.97 KiB) Downloaded 196 times
Will test with some adjustments made to the code as well to see if I can make it even more stable.

BTW, I think I finally understand the SW regarding PWM and how the current is treated and processed. Really brilliant work celeron55!!
User avatar
Jack Bauer
Posts: 3563
Joined: Wed Dec 12, 2018 5:24 pm
Location: Ireland
Has thanked: 1 time
Been thanked: 87 times
Contact:

Re: Gen 3 inverter converter control software

Post by Jack Bauer »

Excellent Bexander. More mods for me to integrate:)
I'm going to need a hacksaw
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Gen 3 inverter converter control software

Post by bexander »

Well, just trying to get it to work as I want it to.
Regarding the filtering capacitors (C3 and C4) I would go a bit higher, like 68-100pF. I only had 36pF or 1nF at home...

I think it is better to set a input current limit rather than setting a output current limit as I have now. The reason beeing that the input current is measured were as the the output current is calculated using the input current and the input and output voltage. This will adds more variables as the input voltage moves a bit as well. I'm going to test this but my FTDI cable gave up on me so will have to wait until I get hold of a new one.
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Gen 3 inverter converter control software

Post by bexander »

Celeron55, or anyone else with programing skills, please can you explain what this particular piece of code does.

Code: Select all

int16_t max_input_a = [&]() -> int16_t {
	// If force_ac_input_amps is set, it overrides everything except
	// INPUT_CURRENT_MAX_A.
	if(force_ac_input_amps != 0)
		return force_ac_input_amps;
	// Otherwise use EVSE CP PWM limit
	return evse_allowed_amps;
}();
I understand it as it does the same thing as

Code: Select all

int16_t max_input_a;
if(force_ac_input_amps != 0) 
{
	max_input_a = force_ac_input_amps;
}
else
{
	max_input_a = evse_allowed_amps;
}
What is the difference or benefit of the above or what am I missing?
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Gen 3 inverter converter control software

Post by bexander »

Apparently this is a lamda expression, a C++ feature.
More info can be found here:
https://en.cppreference.com/w/cpp/language/lambda
glink
Posts: 18
Joined: Mon Mar 15, 2021 7:02 pm
Been thanked: 3 times

Re: Gen 3 inverter converter control software

Post by glink »

Hi, lots of advanced discussions, great! But do we have some descriptions for actually getting the code into the 328p? Nothing here: https://openinverter.org/wiki/Toyota_Pr ... p_Firmware, and I'm having trouble and probably not setting stuff up correctly :-)
Attachments
20210315_201619.jpg
20210315_194629.jpg
User avatar
celeron55
Posts: 774
Joined: Thu Jul 04, 2019 3:04 pm
Location: Finland
Has thanked: 27 times
Been thanked: 110 times
Contact:

Re: Gen 3 inverter converter control software

Post by celeron55 »

I tend to use lambdas in that way to avoid code duplication. Gets rid of a number of accidents one can have with if-else constructs with repeated variable names without having to write separate functions.
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Gen 3 inverter converter control software

Post by bexander »

glink wrote: Mon Mar 15, 2021 7:26 pm Hi, lots of advanced discussions, great! But do we have some descriptions for actually getting the code into the 328p? Nothing here: https://openinverter.org/wiki/Toyota_Pr ... p_Firmware, and I'm having trouble and probably not setting stuff up correctly :-)
Do you have a bootloader on in the 328p? Did you buy the logic board as a complete kit from EVBMW then there should be a bootloader present.
Then, in Arduino IDE, you need to select board: "Arduino Nano". There are some notes in the beginning of the .ino file that describes this.
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Gen 3 inverter converter control software

Post by bexander »

glink wrote: Mon Mar 15, 2021 7:26 pm Hi, lots of advanced discussions, great! But do we have some descriptions for actually getting the code into the 328p? Nothing here: https://openinverter.org/wiki/Toyota_Pr ... p_Firmware, and I'm having trouble and probably not setting stuff up correctly :-)
I think you have the programming cable in the opposite direction, the gnd (black) should be facing the center of the board and not the edge. The silk screen (white text on the board) should read "blk" where the gnd goes.
If none of this works, try swapping rx and tx on the programming cable.
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Gen 3 inverter converter control software

Post by bexander »

celeron55 wrote: Mon Mar 15, 2021 8:13 pm I tend to use lambdas in that way to avoid code duplication. Gets rid of a number of accidents one can have with if-else constructs with repeated variable names without having to write separate functions.
I really struggle understanding the lamda part and what it does exactly. This is very much above my level of coding.
Could you make a quick re-write of the function "get_max_input_a()" without the lamda, just so I can understand what the lamda does?
User avatar
celeron55
Posts: 774
Joined: Thu Jul 04, 2019 3:04 pm
Location: Finland
Has thanked: 27 times
Been thanked: 110 times
Contact:

Re: Gen 3 inverter converter control software

Post by celeron55 »

Actually that particular code ended up simple enough to be written clearer using the ternary operator, so the lamda is there just for some extension I was expecting to make but didn't. I'd replace it with this which does the same thing but usually makes a mess when extended more.

Code: Select all

// If force_ac_input_amps is set, it overrides everything except INPUT_CURRENT_MAX_A.
// Otherwise use EVSE CP PWM limit
int16_t max_input_a = (force_ac_input_amps != 0 ? force_ac_input_amps : evse_allowed_amps);
Your if-else translation looks correct also.
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Gen 3 inverter converter control software

Post by bexander »

celeron55 wrote: Tue Mar 16, 2021 8:51 am Actually that particular code ended up simple enough to be written clearer using the ternary operator, so the lamda is there just for some extension I was expecting to make but didn't. I'd replace it with this which does the same thing but usually makes a mess when extended more.

Code: Select all

// If force_ac_input_amps is set, it overrides everything except INPUT_CURRENT_MAX_A.
// Otherwise use EVSE CP PWM limit
int16_t max_input_a = (force_ac_input_amps != 0 ? force_ac_input_amps : evse_allowed_amps);
Your if-else translation looks correct also.
Ok, great! Thank you for the explanation!
glink
Posts: 18
Joined: Mon Mar 15, 2021 7:02 pm
Been thanked: 3 times

Re: Gen 3 inverter converter control software

Post by glink »

bexander wrote: Tue Mar 16, 2021 5:50 am
glink wrote: Mon Mar 15, 2021 7:26 pm Hi, lots of advanced discussions, great! But do we have some descriptions for actually getting the code into the 328p? Nothing here: https://openinverter.org/wiki/Toyota_Pr ... p_Firmware, and I'm having trouble and probably not setting stuff up correctly :-)
Do you have a bootloader on in the 328p? Did you buy the logic board as a complete kit from EVBMW then there should be a bootloader present.
Then, in Arduino IDE, you need to select board: "Arduino Nano". There are some notes in the beginning of the .ino file that describes this.
Sure, was programmed by Damien, but just to be 100% sure I reprogrammed the bootloader using the Atmel ICE
glink
Posts: 18
Joined: Mon Mar 15, 2021 7:02 pm
Been thanked: 3 times

Re: Gen 3 inverter converter control software

Post by glink »

bexander wrote: Tue Mar 16, 2021 5:56 am
glink wrote: Mon Mar 15, 2021 7:26 pm Hi, lots of advanced discussions, great! But do we have some descriptions for actually getting the code into the 328p? Nothing here: https://openinverter.org/wiki/Toyota_Pr ... p_Firmware, and I'm having trouble and probably not setting stuff up correctly :-)
I think you have the programming cable in the opposite direction, the gnd (black) should be facing the center of the board and not the edge. The silk screen (white text on the board) should read "blk" where the gnd goes.
If none of this works, try swapping rx and tx on the programming cable.
Crap, was laser focused on the "5V" on the silk screen, but that just tells "FTDI 5V"...stupid me not measuring first. But same thing, not working still, but now I maybe have fried some parts of the 328p...well Damien, maybe another order coming soon...
Thanks, Bexander, that definitely was one issue. Have also tried not crossing the TX/RX just to try it, but expect them to be crossed. Have some other FTDI boards coming also in case there is an issue with that part of the equation.
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Gen 3 inverter converter control software

Post by bexander »

glink wrote: Tue Mar 16, 2021 2:42 pm
bexander wrote: Tue Mar 16, 2021 5:56 am
glink wrote: Mon Mar 15, 2021 7:26 pm Hi, lots of advanced discussions, great! But do we have some descriptions for actually getting the code into the 328p? Nothing here: https://openinverter.org/wiki/Toyota_Pr ... p_Firmware, and I'm having trouble and probably not setting stuff up correctly :-)
I think you have the programming cable in the opposite direction, the gnd (black) should be facing the center of the board and not the edge. The silk screen (white text on the board) should read "blk" where the gnd goes.
If none of this works, try swapping rx and tx on the programming cable.
Crap, was laser focused on the "5V" on the silk screen, but that just tells "FTDI 5V"...stupid me not measuring first. But same thing, not working still, but now I maybe have fried some parts of the 328p...well Damien, maybe another order coming soon...
Thanks, Bexander, that definitely was one issue. Have also tried not crossing the TX/RX just to try it, but expect them to be crossed. Have some other FTDI boards coming also in case there is an issue with that part of the equation.
There are 1k series resistors between connector rx and tx pins and 328 so you should... be ok. When I program I used a FTDI cable with the pinout as per stock so I expect that you should have the same pinout from your FTDI-board and hence not crossing TX/RX should be the way to go.
What is happening when you try to upload, with board set to "Arduino Nano"?
glink
Posts: 18
Joined: Mon Mar 15, 2021 7:02 pm
Been thanked: 3 times

Re: Gen 3 inverter converter control software

Post by glink »

bexander wrote: Tue Mar 16, 2021 3:28 pm
glink wrote: Tue Mar 16, 2021 2:42 pm
bexander wrote: Tue Mar 16, 2021 5:56 am

I think you have the programming cable in the opposite direction, the gnd (black) should be facing the center of the board and not the edge. The silk screen (white text on the board) should read "blk" where the gnd goes.
If none of this works, try swapping rx and tx on the programming cable.
Crap, was laser focused on the "5V" on the silk screen, but that just tells "FTDI 5V"...stupid me not measuring first. But same thing, not working still, but now I maybe have fried some parts of the 328p...well Damien, maybe another order coming soon...
Thanks, Bexander, that definitely was one issue. Have also tried not crossing the TX/RX just to try it, but expect them to be crossed. Have some other FTDI boards coming also in case there is an issue with that part of the equation.
There are 1k series resistors between connector rx and tx pins and 328 so you should... be ok. When I program I used a FTDI cable with the pinout as per stock so I expect that you should have the same pinout from your FTDI-board and hence not crossing TX/RX should be the way to go.
What is happening when you try to upload, with board set to "Arduino Nano"?
Sweet, maybe the FTDI board never worked. Tried with different baud rates, same...also traced the rx and tx pins to the 328p
Here is what is happening:
Attachments
20210316_172554.jpg
Isaac96
Posts: 656
Joined: Sat Oct 05, 2019 6:50 pm
Location: Northern California, USA
Been thanked: 1 time
Contact:

Re: Gen 3 inverter converter control software

Post by Isaac96 »

0xf0 - at least you're getting a response. Is the board resetting properly? And have you tried the 'atmega328p (old bootloader)' option? They changed baud rate a year or two ago...

EDIT Also be sure you're using the right COM port, COM4 is suspiciously low.
glink
Posts: 18
Joined: Mon Mar 15, 2021 7:02 pm
Been thanked: 3 times

Re: Gen 3 inverter converter control software

Post by glink »

Isaac96 wrote: Tue Mar 16, 2021 5:12 pm 0xf0 - at least you're getting a response. Is the board resetting properly? And have you tried the 'atmega328p (old bootloader)' option? They changed baud rate a year or two ago...

EDIT Also be sure you're using the right COM port, COM4 is suspiciously low.
Thanks for having a look, have tried the old bootloader option also, afaik it only lowers the baud rate. I have tried all baud rates down to 9600 from the command line. The RX led is blinking at each retry, so some kind of communication is going on. Resetting happens after the upload, right?
Isaac96
Posts: 656
Joined: Sat Oct 05, 2019 6:50 pm
Location: Northern California, USA
Been thanked: 1 time
Contact:

Re: Gen 3 inverter converter control software

Post by Isaac96 »

Hmm... Reset should happen if the board is built 'properly'. Is there a manual reset you can try?
glink
Posts: 18
Joined: Mon Mar 15, 2021 7:02 pm
Been thanked: 3 times

Re: Gen 3 inverter converter control software

Post by glink »

Isaac96 wrote: Tue Mar 16, 2021 9:15 pm Hmm... Reset should happen if the board is built 'properly'. Is there a manual reset you can try?
For now, the culprit imho is the FTDI board. Uploaded a sketch with the Atmel ICE, but still no serial I/O. Until I get a new FTDI board I will program using the Atmel ICE, but it's a bit more cumbersome.
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: Gen 3 inverter converter control software

Post by bexander »

Ok, I think I have found another source of error for the inverter converter control.
My dc-bus voltage never goes above 375V... I don't think this is a SW issue but rather a limit in Toyotas HW design so I have created a new thread about this, which can be found here:
viewtopic.php?f=14&t=1503

Log from latest charging:
CHG_1_10_2.txt
(52.49 KiB) Downloaded 150 times
Post Reply