Page 9 of 12

Re: Gen 3 inverter converter control software

Posted: Mon Mar 01, 2021 6:00 pm
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.

Re: Gen 3 inverter converter control software

Posted: Mon Mar 01, 2021 6:17 pm
by celeron55
Yeah controlling the lowside is probably a good idea. However I couldn't test it as my lowside is broken.

Re: Gen 3 inverter converter control software

Posted: Mon Mar 01, 2021 6:45 pm
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! :)

Re: Gen 3 inverter converter control software

Posted: Wed Mar 03, 2021 7:03 pm
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.

Re: Gen 3 inverter converter control software

Posted: Fri Mar 12, 2021 4:17 pm
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 214 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 187 times
CHG2_1_7_1.txt
Changed, with op-amp
(40.97 KiB) Downloaded 206 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!!

Re: Gen 3 inverter converter control software

Posted: Sat Mar 13, 2021 9:30 am
by Jack Bauer
Excellent Bexander. More mods for me to integrate:)

Re: Gen 3 inverter converter control software

Posted: Sun Mar 14, 2021 8:29 am
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.

Re: Gen 3 inverter converter control software

Posted: Sun Mar 14, 2021 9:29 am
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?

Re: Gen 3 inverter converter control software

Posted: Mon Mar 15, 2021 1:00 pm
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

Re: Gen 3 inverter converter control software

Posted: Mon Mar 15, 2021 7:26 pm
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 :-)

Re: Gen 3 inverter converter control software

Posted: Mon Mar 15, 2021 8:13 pm
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.

Re: Gen 3 inverter converter control software

Posted: Tue Mar 16, 2021 5:50 am
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.

Re: Gen 3 inverter converter control software

Posted: Tue Mar 16, 2021 5:56 am
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.

Re: Gen 3 inverter converter control software

Posted: Tue Mar 16, 2021 6:04 am
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?

Re: Gen 3 inverter converter control software

Posted: Tue Mar 16, 2021 8:51 am
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.

Re: Gen 3 inverter converter control software

Posted: Tue Mar 16, 2021 10:54 am
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!

Re: Gen 3 inverter converter control software

Posted: Tue Mar 16, 2021 2:32 pm
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

Re: Gen 3 inverter converter control software

Posted: Tue Mar 16, 2021 2:42 pm
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.

Re: Gen 3 inverter converter control software

Posted: Tue Mar 16, 2021 3:28 pm
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"?

Re: Gen 3 inverter converter control software

Posted: Tue Mar 16, 2021 4:38 pm
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:

Re: Gen 3 inverter converter control software

Posted: Tue Mar 16, 2021 5:12 pm
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.

Re: Gen 3 inverter converter control software

Posted: Tue Mar 16, 2021 5:57 pm
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?

Re: Gen 3 inverter converter control software

Posted: Tue Mar 16, 2021 9:15 pm
by Isaac96
Hmm... Reset should happen if the board is built 'properly'. Is there a manual reset you can try?

Re: Gen 3 inverter converter control software

Posted: Wed Mar 17, 2021 7:37 pm
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.

Re: Gen 3 inverter converter control software

Posted: Fri Mar 19, 2021 2:51 pm
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 162 times