Leaf Gen 1 Inverter Board

Nissan Leaf/e-NV200 drive stack topics
User avatar
Kevin Sharpe
Posts: 1345
Joined: Fri Dec 14, 2018 9:24 pm
Location: Ireland and US
Been thanked: 4 times

Re: Leaf Gen 1 Inverter Board

Post by Kevin Sharpe »

Cookie6000 wrote: Mon Aug 24, 2020 7:01 pm Just checked all three. Neg and precharge energised sit at 0 ohms. Positive... 1.5 ohms :? Not energised, Postive also exhibits variable value changes. Smoking gun?
If the positive contactor has welded closed then you will get very odd behaviour.

Can you confirm you are measuring these without anything connected to at least one of the contactor terminals? No HV connected as well? We need to ensure that you are measuring the contactor only.

If possible I would also suggest you verify the results with another meter. Very unlikely you have a meter or lead fault but it does happen and it's easier to check the results than buy a new contactor.

I also suggest you measure the value of the precharge resistor and check that the terminals on it are solid (these resistors can be damaged during soldering).

Final thought... are the inverter and motor cases securely attached to chassis ground?
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
Cookie6000
Posts: 246
Joined: Wed May 08, 2019 9:27 am
Location: Wicklow, IRL
Has thanked: 12 times
Been thanked: 32 times
Contact:

Re: Leaf Gen 1 Inverter Board

Post by Cookie6000 »

Can you confirm you are measuring these without anything connected to at least one of the contactor terminals? No HV connected as well? We need to ensure that you are measuring the contactor only.
I measured the contactor both in and out. When in the HVJB it measured 1.5 ohm. When I energised on the bench on its own, 0.3 ohm. Similar on another multimeter.
20200824_194555.jpg
I swapped the suspect kilovac for the 120A Pansonic AEV14012 just which was removed from the Gen 1 Leaf charger just for this test. I changed the HV presets to 350V, connected it all up and we are back to normal and motor spinning ;)
20200824_221304.jpg
I also suggest you measure the value of the precharge resistor and check that the terminals on it are solid (these resistors can be damaged during soldering)
Final thought... are the inverter and motor cases securely attached to chassis ground?
I checked the pre charge resistor the other day and it was good from a terminal and resistance point of view. I have a good earth strap to the motor which in turn is bolted to the frame holding the inverter. I may add another strap to the base of the inverter just to be sure. On this basis, would we be right to assume it's the contactor?
Home of the #Audi8e - https://twitter.com/FiachraCooke
User avatar
Kevin Sharpe
Posts: 1345
Joined: Fri Dec 14, 2018 9:24 pm
Location: Ireland and US
Been thanked: 4 times

Re: Leaf Gen 1 Inverter Board

Post by Kevin Sharpe »

Cookie6000 wrote: Mon Aug 24, 2020 9:41 pm I measured the contactor both in and out. When in the HVJB it measured 1.5 ohm. When I energised on the bench on its own, 0.3 ohm. Similar on another multimeter.
Hard to explain the difference between measurements inside and outside the HVJB. One possibility is that you had something else connected to the contactor terminal, or internal damage is impacted by movement.

It is difficult to measure low resistance accurately with cheap multimeters. It's always worth swapping the probes around to see if the readings change (this can also indicate whether you have something else influencing the measurements like an intrinsic diode or bias voltage).
Cookie6000 wrote: Mon Aug 24, 2020 9:41 pm I swapped the suspect kilovac for the 120A Pansonic AEV14012 just which was removed from the Gen 1 Leaf charger just for this test. I changed the HV presets to 350V, connected it all up and we are back to normal and motor spinning ;)
That is good news :)

We may need to get a bit clever with the HV preset in the future. When in Turtle mode the Leaf is at 3V per celI (288V pack voltage) and if you want to charge when at that level then a HV preset at ~280V would seem appropriate.
Battery_Charging_Voltage_2.png
Cookie6000 wrote: Mon Aug 24, 2020 9:41 pm I checked the pre charge resistor the other day and it was good from a terminal and resistance point of view. I have a good earth strap to the motor which in turn is bolted to the frame holding the inverter. I may add another strap to the base of the inverter just to be sure.
That all sounds good :)
Cookie6000 wrote: Mon Aug 24, 2020 9:41 pm On this basis, would we be right to assume it's the contactor?
It looks like a strong contender. What's the history of the contactor? Is it a new part from a reputable source?
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
Cookie6000
Posts: 246
Joined: Wed May 08, 2019 9:27 am
Location: Wicklow, IRL
Has thanked: 12 times
Been thanked: 32 times
Contact:

Re: Leaf Gen 1 Inverter Board

Post by Cookie6000 »

Hard to explain the difference between measurements inside and outside the HVJB. One possibility is that you had something else connected to the contactor terminal, or internal damage is impacted by movement.

It is difficult to measure low resistance accurately with cheap multimeters. It's always worth swapping the probes around to see if the readings change (this can also indicate whether you have something else influencing the measurements like an intrinsic diode or bias voltage).
Yeah, I tried the contactor with another multimeter (a little better this one ) energised it and it read 7.3 ohms. I gave it a knock off the bench, tried it again, 3.8 ohm :D
We may need to get a bit clever with the HV preset in the future. When in Turtle mode the Leaf is at 3V per celI (288V pack voltage) and if you want to charge when at that level then a HV preset at ~280V would seem appropriate.
Cool. That's a great piece of info to have. Done 8-)
It looks like a strong contender. What's the history of the contactor? Is it a new part from a reputable source?
Used and it was one of two I bought from ebay. The ones that always are there and that orginate from Isreal. Arber got a few too from the same guys and he reckons they are all ex military kit.

Since the VCU is no longer a suspect in this investigation I may as well leave it there to concentrate on VCU centric detail but if there is anything else on this I'll put it over on my own build thread with a link to this page.
Home of the #Audi8e - https://twitter.com/FiachraCooke
User avatar
Kevin Sharpe
Posts: 1345
Joined: Fri Dec 14, 2018 9:24 pm
Location: Ireland and US
Been thanked: 4 times

Re: Leaf Gen 1 Inverter Board

Post by Kevin Sharpe »

Cookie6000 wrote: Tue Aug 25, 2020 9:20 am Yeah, I tried the contactor with another multimeter (a little better this one ) energised it and it read 7.3 ohms. I gave it a knock off the bench, tried it again, 3.8 ohm :D
I think Damien would describe that as 'less than optimal behaviour' :D

Well done for posting the information needed to debug the issue. While we don't know why the contactor failed my guess is that it was faulty when you received it and driving the car (and maybe the low precharge voltage setting) tipped it over the edge.
Cookie6000 wrote: Tue Aug 25, 2020 9:20 am Used and it was one of two I bought from ebay. The ones that always are there and that orginate from Isreal. Arber got a few too from the same guys and he reckons they are all ex military kit.
I know Damien has also used this source without incident. Maybe we need to encourage people to run some basic tests on second user contactors before they use them :)
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
Cookie6000
Posts: 246
Joined: Wed May 08, 2019 9:27 am
Location: Wicklow, IRL
Has thanked: 12 times
Been thanked: 32 times
Contact:

Re: Leaf Gen 1 Inverter Board

Post by Cookie6000 »

Kevin Sharpe wrote: Tue Aug 25, 2020 10:41 am I think Damien would describe that as 'less than optimal behaviour' :D
:lol:
Kevin Sharpe wrote: Tue Aug 25, 2020 10:41 am While we don't know why the contactor failed my guess is that it was faulty when you received it and driving the car (and maybe the low precharge voltage setting) tipped it over the edge.
Yep, I agree. I did a lot of testing with various parameter changes and triggering of the contactors on and off repeatedly. I have ordered another two from the same supplier as they are overall and by all accounts, relatively bullet proof.

I have completely rewired everything back up today, VCU in the footwell and it's all looking and sounding good. Thanks again. I will get the schematic tidied up fire it up to the Wiki for reference. Next challenge up, I'll be hanging out on the Tesla charger thread :D
Home of the #Audi8e - https://twitter.com/FiachraCooke
Alibro
Posts: 829
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 248 times
Been thanked: 144 times
Contact:

Re: Leaf Gen 1 Inverter Board

Post by Alibro »

Hi guys
I am in the process of soldering connectors for the VCU (don't trust my crimping), and have done a quick power up of the VCU over USB and it seems to be operating as advertised so I hope to be testing soon but just wondered what the minimum voltage is I can run the inverter?
I have a pile of good 12V lead acid batteries I can run in series so could go all the way to 400V if necessary but would prefer to start at a much lower voltage.
This is only for bench testing and I know the motor will run at 50V but unsure about the minimum voltage for the inverter

I need a bigger hammer!
User avatar
james@N52E01
Posts: 144
Joined: Wed Sep 18, 2019 7:02 am
Has thanked: 2 times
Been thanked: 3 times

Re: Leaf Gen 1 Inverter Board

Post by james@N52E01 »

I’m running it comfortably at 196v. The pack sags to 190v under load but the VCU seems quite happy. According to the original 8dromeda info, the Inverter needs to receive a minimum of 140v within 10s of startup, but they changed the info to 180v since then. Not tested the voltage that low.

That ebike controller works great! :D
Alibro
Posts: 829
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 248 times
Been thanked: 144 times
Contact:

Re: Leaf Gen 1 Inverter Board

Post by Alibro »

james@N52E01 wrote: Sun Sep 27, 2020 7:43 pm I’m running it comfortably at 196v. The pack sags to 190v under load but the VCU seems quite happy. According to the original 8dromeda info, the Inverter needs to receive a minimum of 140v within 10s of startup, but they changed the info to 180v since then. Not tested the voltage that low.

That ebike controller works great! :D
That's great thanks. I'll set it up with around 180V and see what happens.
I have a 3kW ebike controller I could use to move the car around if I needed to. 😉
I need a bigger hammer!
User avatar
james@N52E01
Posts: 144
Joined: Wed Sep 18, 2019 7:02 am
Has thanked: 2 times
Been thanked: 3 times

Re: Leaf Gen 1 Inverter Board

Post by james@N52E01 »

That’s super cool! Did you just hook up hall sensors to the ebike controller? Has given me an idea for another project
Alibro
Posts: 829
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 248 times
Been thanked: 144 times
Contact:

Re: Leaf Gen 1 Inverter Board

Post by Alibro »

No hall sensors connected. The cheap Chinese ebike controllers don't need them. They probably don't get the timing perfect but still work. I built a couple of ebikes with a car alternator and had a lot of fun with them. Check out my other videos.
I need a bigger hammer!
Alibro
Posts: 829
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 248 times
Been thanked: 144 times
Contact:

Re: Leaf Gen 1 Inverter Board

Post by Alibro »

Kevin Sharpe wrote: Tue Aug 25, 2020 10:41 am
Cookie6000 wrote: Tue Aug 25, 2020 9:20 am Yeah, I tried the contactor with another multimeter (a little better this one ) energised it and it read 7.3 ohms. I gave it a knock off the bench, tried it again, 3.8 ohm :D
I think Damien would describe that as 'less than optimal behaviour' :D

Well done for posting the information needed to debug the issue. While we don't know why the contactor failed my guess is that it was faulty when you received it and driving the car (and maybe the low precharge voltage setting) tipped it over the edge.
Cookie6000 wrote: Tue Aug 25, 2020 9:20 am Used and it was one of two I bought from ebay. The ones that always are there and that orginate from Isreal. Arber got a few too from the same guys and he reckons they are all ex military kit.
I know Damien has also used this source without incident. Maybe we need to encourage people to run some basic tests on second user contactors before they use them :)
I'm still gathering bits for my project and spotted this listing in ebay
https://www.ebay.co.uk/itm/Kilovac-Cont ... SwyaNeHx15
Just wondered if these would be equally suitable as they are the same price but available locally. I didn't want to spend £70 on them to find in my ignorance I had ordered the wrong thing.
I need a bigger hammer!
User avatar
Cookie6000
Posts: 246
Joined: Wed May 08, 2019 9:27 am
Location: Wicklow, IRL
Has thanked: 12 times
Been thanked: 32 times
Contact:

Re: Leaf Gen 1 Inverter Board

Post by Cookie6000 »

You can see from the 2nd photo it is only rated for 320v. Ideally, you would want to be >400v DC to make sure it is reliable. Also, there is no economiser on that by the looks of things so again, not best suited.
I have bought from these guys twice now on ebay. The EV200HAANA is common among conversions, is more than reliable and used by the military... which is where we think these have come from ;) Has a switched voltage capability >900v DC at 500A. Worth the extra €€€.
https://www.ebay.co.uk/itm/Lot-of-2-Kil ... SwkV5aYhlR
Home of the #Audi8e - https://twitter.com/FiachraCooke
Alibro
Posts: 829
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 248 times
Been thanked: 144 times
Contact:

Re: Leaf Gen 1 Inverter Board

Post by Alibro »

Cookie6000 wrote: Wed Sep 30, 2020 9:48 pm You can see from the 2nd photo it is only rated for 320v. Ideally, you would want to be >400v DC to make sure it is reliable. Also, there is no economiser on that by the looks of things so again, not best suited.
I have bought from these guys twice now on ebay. The EV200HAANA is common among conversions, is more than reliable and used by the military... which is where we think these have come from ;) Has a switched voltage capability >900v DC at 500A. Worth the extra €€€.
https://www.ebay.co.uk/itm/Lot-of-2-Kil ... SwkV5aYhlR
Thanks Cookie, I hadn't noticed the low voltage. Sorry to any others interested in ordering these but I just bought the last 2. :lol:
I need a bigger hammer!
Alibro
Posts: 829
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 248 times
Been thanked: 144 times
Contact:

Re: Leaf Gen 1 Inverter Board

Post by Alibro »

Hi Guys
So I got the VCU cabled up and had a test today to see what would happen
16 x 12V lead acid batteries
6 x 4R7 50W resistors for pre charge
1 cooker switch to turn the high voltage on in steps.
1 rocker switch for ignition
And after cocking about for a bit IT WORKS. :D

Sort of :?

It is doing the same thing as Fiachra's in this video


The motor spins but won't stop or it stops and won't spin again.
I'm assuming this is because the pedal I'm using is from the Leaf and Damien calibrated it for his E46.
This is mentioned extensively on page 9 of this thread so I'm going have a go at updating the software with Cookie's numbers and see what happens.

I'm still a bit unsure about reprogramming it but for now I'm very pleased as this was a major step forward. :)
I need a bigger hammer!
User avatar
james@N52E01
Posts: 144
Joined: Wed Sep 18, 2019 7:02 am
Has thanked: 2 times
Been thanked: 3 times

Re: Leaf Gen 1 Inverter Board

Post by james@N52E01 »

Nice work. You’re welcome to use the latest version of firmware I’ve adapted from Damien’s last V1.5. It incorporates the ISA shunt and It’s configured for the leaf pedal, but you’ll want to check the presets (HVPreset and any reference to 280v needs to be changed to match your setup.

Code: Select all

/*
Leaf Gen1 Inverter driver. Alpha software for testing.
Runs on the Arduino Due SAM3X8E MCU. V1 Leaf open source vcu.
Enter torque request on serial window.
As of now only responds to negative torque requests. e.g. -10
Positive torque requests trigger the inverter pwm but do not rotate the motor.

V5 incorporates ISA can shunt on CAN0. Let's hope the leaf inverter doesnt mind the isa messages and vice versa:)
WiFi on Serial2.
Precharge control : out1 = precharge , out2= main contactor


Copyright 2019 
Perttu Ahola (all the hard work!)
http://productions.8dromeda.net/c55-leaf-inverter-protocol.html

Damien Maguire (copy and paste).
OpenSource VCU hardware design available on Github :
https://github.com/damienmaguire/Nissan-Leaf-Inverter-Controller

2011 Nisan Leaf Gen 1 EV CAN logs on Github:
https://github.com/damienmaguire/LeafLogs


    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.



*/
#include <Metro.h>
#include <due_can.h>  
#include <due_wire.h> 
#include <DueTimer.h>  
#include <Wire_EEPROM.h> 
#include <ISA.h>  //isa can shunt library



#define Serial SerialUSB
template<class T> inline Print &operator <<(Print &obj, T arg) { obj.print(arg); return obj; }


CAN_FRAME outFrame;  //A structured variable according to due_can library for transmitting CAN data.
CAN_FRAME inFrame;    //structure to keep inbound inFrames

//////timers//////////////////////////////
Metro timer_Frames10 = Metro(10);
Metro timer_Frames100 = Metro(100);
Metro timer_wifi = Metro(1100);
Metro timer_hv = Metro(1000);

float Version=2.00;           //JAMES@N52E01 Added
uint16_t loopcount=0;         //JAMES@N52E01 Added
unsigned long startime=0;     //JAMES@N52E01 Added
unsigned long elapsedtime=0;  //JAMES@N52E01 Added
uint port=0;                  //JAMES@N52E01 Added
uint16_t datarate=500;        //JAMES@N52E01 Added

int inv_volts_local;
int16_t final_torque_request = 0;
#define INVERTER_BITS_PER_VOLT 2
#define INVERTER_BITS_PER_RPM 2


////////////////////Pin Map////////////////////////////////////////////////////
int led = 13;         //onboard led for diagnosis
#define Throttle1 A0  //Analog throttle channel 1
#define Throttle2 A1  //Analog throttle channel 2
#define Brake 61      //Brake pedal switch. High = brake on
#define IN1 6         //General purpose digital input 1. High =12v
#define IN2 7         //General purpose digital input 2. High =12v
#define OUT1  48      //Low side switched general purpose digital output 1. high = on.
#define OUT2  49      //Low side switched general purpose digital output 2. high = on.
#define OUT3  50      //Low side switched general purpose digital output 3. high = on.
/////////////////////////////////////////////////////////////////////////////////

#define HVPreset 280 //voltage at which to enable main contactor

uint16_t ThrotVal =0; //analog value of throttle position.
uint16_t outRPM;      //calculated value of rpm for e46 ike
static int16_t MaxTrq=2000;  //max torque request
struct InverterStatus {
  uint16_t voltage = 0;
  int16_t speed = 0;
  int8_t inverter_temperature = 0;
  int8_t motor_temperature = 0;
  bool error_state = false;
} inverter_status;

String readString;
byte ABSMsg=0x11;
uint8_t tempValue; //value to send to e46 temp gauge.

bool T15Status; //flag to keep status of Terminal 15 from In1
bool can_status;  //flag for turning off and on can sending.
bool Pch_Flag;    //precharge status flag
bool HV_Flag;     //hv on flag

ISA Sensor;  //Instantiate ISA Module Sensor object to measure current and voltage 

void setup() 
  {
  Can0.begin(CAN_BPS_500K);   // Inverter CAN
  Can1.begin(CAN_BPS_500K);   // Vehicle CAN
  //Can0.watchFor(0x1da); //set message filter for inverter can. Note sure if I can use two seperate values here. it might just pick 1!
  Can0.watchFor();
  Can1.watchFor(0x1ff); //just a blank message to block receive from e46 messages.
    
    Serial.begin(115200);  //Initialize our USB port which will always be redefined as SerialUSB to use the Native USB port tied directly to the SAM3X processor.
    Serial2.begin(19200);  //Serial comms with ESP32 WiFi module on serial 2
    Sensor.begin(port,datarate);  //Start ISA object on CAN 0 at 500 kbps // JAMES@N52E01 Added
   // Timer3.attachInterrupt(Msgs10ms).start(10000); // 10ms CAN Message Timer
   // Timer4.attachInterrupt(Msgs100ms).start(100000); //100ms CAN Message Timer
    
  pinMode(led, OUTPUT);
  pinMode(Brake, INPUT);
  pinMode(IN1, INPUT);  //T15 input from ign on switch
  pinMode(IN2, INPUT);
  pinMode(OUT1, OUTPUT);
  pinMode(OUT2, OUTPUT);
  pinMode(OUT3, OUTPUT);
  
  //digitalWrite(led, HIGH);
  digitalWrite(OUT1, LOW);  //precharge
  digitalWrite(OUT2, LOW);  //main contactor
  digitalWrite(OUT3, LOW);  //inverter power
  

 
  }

  
  
void loop()
{ 
Check_T15();  //is the ignition on?  
if (timer_hv.check()) HV_Con(); //control hv system
Msgs100ms();  //fire the 100ms can messages
Msgs10ms();   //fire the 10ms can messages
readPedals(); //read throttle and brake pedal status.
SendTorqueRequest();  //send torque request to inverter.
ProcessRPM(); //send rpm and temp to e46 instrument cluster
CheckCAN(); //check for incoming can
handle_wifi();  //send wifi data

}

void Check_T15()
{
if (digitalRead(IN1))
{
T15Status=true;
can_status=true;
}
else
{
T15Status=false;
can_status=false;
Pch_Flag=false;
HV_Flag=false;
inv_volts_local==0;
}

}

void HV_Con()
{

  inv_volts_local=(inverter_status.voltage / INVERTER_BITS_PER_VOLT);


if (T15Status && !Pch_Flag)  //if terminal 15 is on and precharge not enabled
{
  digitalWrite(OUT3, HIGH);  //inverter power on
  if(inv_volts_local<280)
  {
  digitalWrite(OUT1, HIGH);  //precharge on
  Pch_Flag=true;
  }
}
if (T15Status && !HV_Flag && Pch_Flag)  //using inverter measured hv for initial tests. Will use ISA derived voltage in final version.
{
  if (inv_volts_local>280)
  {
  digitalWrite(OUT2, HIGH);  //main contactor on
  HV_Flag=true;  //hv on flag
  }
}

if (!T15Status)
{
  digitalWrite(OUT1, LOW);  //precharge off
  digitalWrite(OUT2, LOW);  //main contactor off
  digitalWrite(OUT3, LOW);  //inverter power off
  
}

}

void handle_wifi(){
  if (timer_wifi.check())
  {
/*
 * 
 * Routine to send data to wifi on serial 2
The information will be provided over serial to the esp8266 at 19200 baud 8n1 in the form :
vxxx,ixxx,pxxx,mxxxx,oxxx,rxxx* where :

v=pack voltage (0-700Volts)
i=current (0-1000Amps)
p=power (0-300kw)
m=motor rpm (0-10000rpm)
o=motor temp (-20 to 120C)
r=inverter temp (-20 to 120C)
*=end of string
xxx=three digit integer for each parameter eg p100 = 100kw.
updates will be every 1100ms approx.

v100,i200,p35,m3000,o20,r100*JAME
*/
  
//Serial2.print("v100,i200,p35,m3000,o20,r100*"); //test string

digitalWrite(13,!digitalRead(13));//blink led every time we fire this interrrupt.
      Serial.print(inv_volts_local);
      Serial.print(F(" Volts"));
      Serial.println();
      Serial.println(HV_Flag);

      
Serial2.print("v");//dc bus voltage
Serial2.print(Sensor.Voltage3);//voltage derived from ISA shunt // JAMES@N52E01 Added "3" to voltage
Serial2.print(",i");//dc current
Serial2.print(Sensor.Amperes);//current derived from ISA shunt
Serial2.print(",p");//total motor power
Serial2.print(Sensor.KW);//Power value derived from ISA Shunt
Serial2.print(",m");//motor rpm
Serial2.print(inverter_status.speed);
Serial2.print(",o");//motor temp
Serial2.print(inverter_status.motor_temperature);
Serial2.print(",r");//inverter temp
Serial2.print(inverter_status.inverter_temperature);
Serial2.print("*");// end of data indicator
  }
}

  



void Msgs10ms()                       //10ms messages here
{
if(timer_Frames10.check())
{
  if(can_status)
  {
    
  
  static uint8_t counter_11a_d6 = 0;
  static uint8_t counter_1d4 = 0;
  static uint8_t counter_1db = 0;
   static uint8_t counter_329 = 0;
    static uint8_t counter_100ms = 0;

  // Send VCM gear selection signal (gets rid of P3197)
  

        outFrame.id = 0x11a;            // Set our transmission address ID
        outFrame.length = 8;            // Data payload 3 bytes
        outFrame.extended = 0;          // Extended addresses - 0=11-bit 1=29bit
        outFrame.rtr=1;                 //No request



    
 //   CAN_FRAME inFrame;
  //  inFrame.id = 0x11a;
  //  inFrame.length = 8;

    // Data taken from a gen1 inFrame where the car is starting to
    // move at about 10% throttle: 4E400055 0000017D

    // All possible gen1 values: 00 01 0D 11 1D 2D 2E 3D 3E 4D 4E
    // MSB nibble: Selected gear (gen1/LeafLogs)
    //   0: some kind of non-gear before driving
    //   1: some kind of non-gear after driving
    //   2: R
    //   3: N
    //   4: D
    // LSB nibble: ? (LeafLogs)
    //   0: sometimes at startup, not always; never when the
    //      inverted is powered on (0.06%)
    //   1: this is the usual value (55% of the time in LeafLogs)
    //   D: seems to occur for ~90ms when changing gears (0.2%)
    //   E: this also is a usual value, but never occurs with the
    //      non-gears 0 and 1 (44% of the time in LeafLogs)


    
    outFrame.data.bytes[0] = 0x4E;
    //outFrame.data.bytes[0] = 0x01;

    // 0x40 when car is ON, 0x80 when OFF, 0x50 when ECO
    outFrame.data.bytes[1] = 0x40;

    // Usually 0x00, sometimes 0x80 (LeafLogs), 0x04 seen by canmsgs
    outFrame.data.bytes[2] = 0x00;

    // Weird value at D3:4 that goes along with the counter
    // NOTE: Not actually needed, you can just send constant AA C0
    const static uint8_t weird_d34_values[4][2] = {
      {0xaa, 0xc0},
      {0x55, 0x00},
      {0x55, 0x40},
      {0xaa, 0x80},
    };
    outFrame.data.bytes[3] = weird_d34_values[counter_11a_d6][0];
    outFrame.data.bytes[4] = weird_d34_values[counter_11a_d6][1];

    // Always 0x00 (LeafLogs, canmsgs)
    outFrame.data.bytes[5] = 0x00;

    // A 2-bit counter
    outFrame.data.bytes[6] = counter_11a_d6;

    counter_11a_d6++;
    if(counter_11a_d6 >= 4)
      counter_11a_d6 = 0;

    // Extra CRC
    nissan_crc(outFrame.data.bytes, 0x85);

    /*Serial.print(F("Sending "));
    print_fancy_inFrame(inFrame);
    Serial.println();*/

 Can0.sendFrame(outFrame);
 
    
  
  
  // Send target motor torque signal
  

        outFrame.id = 0x1d4;            // Set our transmission address ID
        outFrame.length = 8;            // Data payload 3 bytes
        outFrame.extended = 0;          // Extended addresses - 0=11-bit 1=29bit
        outFrame.rtr=1;                 //No request

    // Data taken from a gen1 inFrame where the car is starting to
    // move at about 10% throttle: F70700E0C74430D4

    // Usually F7, but can have values between 9A...F7 (gen1)
    outFrame.data.bytes[0] = 0xF7;
    // 2016: 6E
   // outFrame.data.bytes[0] = 0x6E;

    // Usually 07, but can have values between 07...70 (gen1)
    outFrame.data.bytes[1] = 0x07;
    // 2016: 6E
    //outFrame.data.bytes[1] = 0x6E;

    // Requested torque (signed 12-bit value + always 0x0 in low nibble)
    static int16_t last_logged_final_torque_request = 0;
    if(final_torque_request != last_logged_final_torque_request){
      last_logged_final_torque_request = final_torque_request;
      //log_print_timestamp();
      //Serial.print(F("Sending torque request "));
      //Serial.print(final_torque_request);
      //Serial.print(F(" (speed: "));
      //Serial.print(inverter_status.speed / INVERTER_BITS_PER_RPM);
      //Serial.print(F(" rpm)"));
      //Serial.print(inverter_status.voltage / INVERTER_BITS_PER_VOLT);
      //Serial.print(F(" Volts)"));
      //Serial.println();
    }
    if(final_torque_request >= -2048 && final_torque_request <= 2047){
      outFrame.data.bytes[2] = ((final_torque_request < 0) ? 0x80 : 0) |
          ((final_torque_request >> 4) & 0x7f);
      outFrame.data.bytes[3] = (final_torque_request << 4) & 0xf0;
    } else {
      outFrame.data.bytes[2] = 0x00;
      outFrame.data.bytes[3] = 0x00;
    }

    // MSB nibble: Runs through the sequence 0, 4, 8, C
    // LSB nibble: Precharge report (precedes actual precharge
    //             control)
    //   0: Discharging (5%)
    //   2: Precharge not started (1.4%)
    //   3: Precharging (0.4%)
    //   5: Starting discharge (3x10ms) (2.0%)
    //   7: Precharged (93%)
    outFrame.data.bytes[4] = 0x07 | (counter_1d4 << 6);
    //outFrame.data.bytes[4] = 0x02 | (counter_1d4 << 6);

    counter_1d4++;
    if(counter_1d4 >= 4)
      counter_1d4 = 0;

    // MSB nibble:
    //   0: 35-40ms at startup when gear is 0, then at shutdown 40ms
    //      after the car has been shut off (6% total)
    //   4: Otherwise (94%)
    // LSB nibble:
    //   0: ~100ms when changing gear, along with 11A D0 b3:0 value
    //      D (0.3%)
    //   2: Reverse gear related (13%)
    //   4: Forward gear related (21%)
    //   6: Occurs always when gear 11A D0 is 01 or 11 (66%)
    //outFrame.data.bytes[5] = 0x44;
    //outFrame.data.bytes[5] = 0x46;

    // 2016 drive cycle: 06, 46, precharge, 44, drive, 46, discharge, 06
    // 0x46 requires ~25 torque to start
    //outFrame.data.bytes[5] = 0x46;
    // 0x44 requires ~8 torque to start
    outFrame.data.bytes[5] = 0x44;

    // MSB nibble:
    //   In a drive cycle, this slowly changes between values (gen1):
    //     leaf_on_off.txt:
    //       5 7 3 2 0 1 3 7
    //     leaf_on_rev_off.txt:
    //       5 7 3 2 0 6
    //     leaf_on_Dx3.txt:
    //       5 7 3 2 0 2 3 2 0 2 3 2 0 2 3 7
    //     leaf_on_stat_DRDRDR.txt:
    //       0 1 3 7
    //     leaf_on_Driveincircle_off.txt:
    //       5 3 2 0 8 B 3 2 0 8 A B 3 2 0 8 A B A 8 0 2 3 7 
    //     leaf_on_wotind_off.txt:
    //       3 2 0 8 A B 3 7
    //     leaf_on_wotinr_off.txt:
    //       5 7 3 2 0 8 A B 3 7
    //     leaf_ac_charge.txt:
    //       4 6 E 6
    //   Possibly some kind of control flags, try to figure out
    //   using:
    //     grep 000001D4 leaf_on_wotind_off.txt | cut -d' ' -f10 | uniq | ~/projects/leaf_tools/util/hex_to_ascii_binary.py
    //   2016:
    //     Has different values!
    // LSB nibble:
    //   0: Always (gen1)
    //   1:  (2016)

    // 2016 drive cycle:
    //   E0: to 0.15s
    //   E1: 2 messages
    //   61: to 2.06s (inverter is powered up and precharge
    //                 starts and completes during this)
    //   21: to 13.9s
    //   01: to 17.9s
    //   81: to 19.5s
    //   A1: to 26.8s
    //   21: to 31.0s
    //   01: to 33.9s
    //   81: to 48.8s
    //   A1: to 53.0s
    //   21: to 55.5s
    //   61: 2 messages
    //   60: to 55.9s
    //   E0: to end of capture (discharge starts during this)

    // This value has been chosen at the end of the hardest
    // acceleration in the wide-open-throttle pull, with full-ish
    // torque still being requested, in
    //   LeafLogs/leaf_on_wotind_off.txt
    //outFrame.data.bytes[6] = 0x00;

    // This value has been chosen for being seen most of the time
    // when, and before, applying throttle in the wide-open-throttle
    // pull, in
    //   LeafLogs/leaf_on_wotind_off.txt
    outFrame.data.bytes[6] = 0x30;    //brake applied heavilly.

    // Value chosen from a 2016 log
    //outFrame.data.bytes[6] = 0x61;

    // Value chosen from a 2016 log
    // 2016-24kWh-ev-on-drive-park-off.pcap #12101 / 15.63s
   // outFrame.data.bytes[6] = 0x01;
    //byte 6 brake signal

    // Extra CRC
    nissan_crc(outFrame.data.bytes, 0x85);

    /*Serial.print(F("Sending "));
    print_fancy_inFrame(inFrame);
    Serial.println();*/

 Can0.sendFrame(outFrame);

//We need to send 0x1db here with voltage measured by inverter

        outFrame.id = 0x1db;            // Set our transmission address ID
        outFrame.length = 8;            // Data payload 3 bytes
        outFrame.extended = 0;          // Extended addresses - 0=11-bit 1=29bit
        outFrame.rtr=1;                 //No request
        outFrame.data.bytes[0]=0x00;  
        outFrame.data.bytes[1]=0x00;
        outFrame.data.bytes[2]=0x00;
        outFrame.data.bytes[3]=0x00;
        outFrame.data.bytes[4]=0x00;
        outFrame.data.bytes[5]=0x00;
        outFrame.data.bytes[6]=counter_1db;
        outFrame.data.bytes[7]=0x00;


    counter_1db++;
    if(counter_1db >= 4)
      counter_1db = 0;

        

        Can0.sendFrame(outFrame);

///////////////Originally sent as 100ms messages.///////////////////////////////////////////

  

        outFrame.id = 0x50b;            // Set our transmission address ID
        outFrame.length = 7;            // Data payload 8 bytes
        outFrame.extended = 0;          // Extended addresses - 0=11-bit 1=29bit
        outFrame.rtr=1;                 //No request
    // Statistics from 2016 capture:
    //     10 00000000000000
    //     21 000002c0000000
    //    122 000000c0000000
    //    513 000006c0000000

    // Let's just send the most common one all the time
    // FIXME: This is a very sloppy implementation
  //  hex_to_data(outFrame.data.bytes, "00,00,06,c0,00,00,00");
        outFrame.data.bytes[0]=0x00;
        outFrame.data.bytes[1]=0x00;  
        outFrame.data.bytes[2]=0x06;
        outFrame.data.bytes[3]=0xc0;
        outFrame.data.bytes[4]=0x00;
        outFrame.data.bytes[5]=0x00;
        outFrame.data.bytes[6]=0x00;

    /*CONSOLE.print(F("Sending "));
    print_fancy_inFrame(inFrame);
    CONSOLE.println();*/
        Can0.sendFrame(outFrame); 

/////////////////////////////////////////////////////////////////////////////////////////////////////


//these messages go out on vehicle can and are specific to driving the E46 instrument cluster etc.

//////////////////////DME Messages //////////////////////////////////////////////////////////

        outFrame.id = 0x316;            // Set our transmission address ID
        outFrame.length = 8;            // Data payload 8 bytes
        outFrame.extended = 0;          // Extended addresses - 0=11-bit 1=29bit
        outFrame.rtr=1;                 //No request
        outFrame.data.bytes[0]=0x05;
        outFrame.data.bytes[1]=0x00;
        outFrame.data.bytes[2]=lowByte(outRPM);  //RPM LSB
        outFrame.data.bytes[3]=highByte(outRPM);  //RPM MSB [RPM=(hex2dec("byte3"&"byte2"))/6.4]  0x12c0 should be 750rpm on tach
       // outFrame.data.bytes[2]=0xc0;  //RPM LSB
       // outFrame.data.bytes[3]=0x12;  //RPM MSB [RPM=(hex2dec("byte3"&"byte2"))/6.4]  0x12c0 should be 750rpm on tach
 //       outFrame.data.bytes[2]=0xff;  //RPM LSB
 //       outFrame.data.bytes[3]=0x4f;  //RPM MSB [RPM=(hex2dec("byte3"&"byte2"))/6.4]  0x4fff gives 3200rpm on tach
        outFrame.data.bytes[4]=0x00;
        outFrame.data.bytes[5]=0x00;
        outFrame.data.bytes[6]=0x00;
        outFrame.data.bytes[7]=0x00;
        Can1.sendFrame(outFrame);


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////        


  //********************temp sense  *******************************
 // tempValue=analogRead(tempIN); //read Analog pin voltage
//  The sensor and gauge are not linear.  So if the sensed 
//  Voltage is less than the mid point the Map function
//  is used to map the input values to output values For the gauge
//  output values (in decimal):
//  86 = First visible movment of needle starts
//  93 = Begining of Blue section
//  128 = End of Blue Section
//  169 = Begin Straight up
//  193 = Midpoint of needle straight up values
//  219 = Needle begins to move from center
//  230 = Beginning of Red section
//  254 = needle pegged to the right
// MAP program statement: map(value, fromLow, fromHigh, toLow, toHigh)

 // if(tempValue < 964){  //if pin voltage < mid point value 
tempValue= inverter_status.inverter_temperature;  //read temp from leaf inverter can.
tempValue= map(tempValue,15,80,88,254); //Map to e46 temp gauge
 //   }
//  else {
 //   tempValue= map(tempValue,964,1014,219,254); //Map upper half of range
 // }

//Can bus data packet values to be sent
        outFrame.id = 0x329;            // Set our transmission address ID
        outFrame.length = 8;            // Data payload 8 bytes
        outFrame.extended = 0;          // Extended addresses - 0=11-bit 1=29bit
        outFrame.rtr=1;                 //No request
        outFrame.data.bytes[0]=ABSMsg;  //needs to cycle 11,86,d9
        outFrame.data.bytes[1]=tempValue; //temp bit tdata 
        outFrame.data.bytes[2]=0xc5;
        outFrame.data.bytes[3]=0x00;
        outFrame.data.bytes[4]=0x00;
        outFrame.data.bytes[5]=0x00; //Throttle position currently just fixed value
        outFrame.data.bytes[6]=0x00;
        outFrame.data.bytes[7]=0x00;
        Can1.sendFrame(outFrame);


    counter_329++;
    if(counter_329 >= 22) counter_329 = 0;
    if(counter_329==0) ABSMsg=0x11;
    if(counter_329==8) ABSMsg=0x86;
    if(counter_329==15) ABSMsg=0xd9;
   
    



//From ECU, MPG, MIL, overheat light, Cruise
// ErrorState variable controls:
//Check engine(binary 10), Cruise (1000), EML (10000)
//Temp light Variable controls temp light.  Hex 08 is on zero off


  //**************** set Error Lights & cruise light ******
 // hex 08 = Overheat light on
//  // hex 08 = Overheat light on
 //Set check engine. Binary 0010 (hex 02)
// No error light (zero)


 // int z = 0x60; // + y;  higher value lower MPG


//Can bus data packet values to be sent
        outFrame.id = 0x545;            // Set our transmission address ID
        outFrame.length = 8;            // Data payload 8 bytes
        outFrame.extended = 0;          // Extended addresses - 0=11-bit 1=29bit
        outFrame.rtr=1;                 //No request
        outFrame.data.bytes[0]=0x00;  //2=check ewwngine on , 0=check engine off
        outFrame.data.bytes[1]=0x00; //LSB fuel comp
        outFrame.data.bytes[2]=0x00;  //MSB fuel comp
        outFrame.data.bytes[3]=0x00;   // hex 08 = Overheat light on
        outFrame.data.bytes[4]=0x7E;
        outFrame.data.bytes[5]=0x10; 
        outFrame.data.bytes[6]=0x00;
        outFrame.data.bytes[7]=0x18;
        Can1.sendFrame(outFrame);



}
}
 
    }
    



void Msgs100ms()                      ////100ms messages here
{
if(timer_Frames100.check())
{
  if(can_status)
   {

//  digitalWrite(led, !digitalRead(led)); //toggle led everytime we fire the 100ms messages.

        outFrame.id = 0x50b;            // Set our transmission address ID
        outFrame.length = 7;            // Data payload 8 bytes
        outFrame.extended = 0;          // Extended addresses - 0=11-bit 1=29bit
        outFrame.rtr=1;                 //No request
    // Statistics from 2016 capture:
    //     10 00000000000000
    //     21 000002c0000000
    //    122 000000c0000000
    //    513 000006c0000000

    // Let's just send the most common one all the time
    // FIXME: This is a very sloppy implementation
  //  hex_to_data(outFrame.data.bytes, "00,00,06,c0,00,00,00");
        outFrame.data.bytes[0]=0x00;
        outFrame.data.bytes[1]=0x00;  
        outFrame.data.bytes[2]=0x06;
        outFrame.data.bytes[3]=0xc0;
        outFrame.data.bytes[4]=0x00;
        outFrame.data.bytes[5]=0x00;
        outFrame.data.bytes[6]=0x00;

    /*CONSOLE.print(F("Sending "));
    print_fancy_inFrame(inFrame);
    CONSOLE.println();*/
        Can0.sendFrame(outFrame); 
}
}      
}



void readPedals()
{
ThrotVal = analogRead(Throttle1); //read throttle channel 1 directly
ThrotVal = constrain(ThrotVal, 65, 350);
ThrotVal = map(ThrotVal, 65, 350, 0, MaxTrq); //will need to work here for cal.
if(ThrotVal<0) ThrotVal=0;  //no negative numbers for now.
if(digitalRead(Brake)) ThrotVal=0;  //if brake is pressed we zero the throttle value.
//Serial.println(ThrotVal);   //print for calibration. 
}



void SendTorqueRequest()
{

final_torque_request = ThrotVal;  //send mapped throttle signal to inverter.  
  
}



void ProcessRPM() //here we convert motor rpm values received from the leaf inverter into BMW E46 RPM can message.
{
outRPM = (inverter_status.speed)*6.4;
if(outRPM<4800) outRPM=4800;  //set lowest rpm to 750 displayed on tach to keep car alive thinking engine is running.
if(outRPM>44800) outRPM=44800;  //DONT READ MORE THAN 7000RPM!
//Serial.println(outRPM);  
}




static int8_t fahrenheit_to_celsius(uint16_t fahrenheit)
{
  int16_t result = ((int16_t)fahrenheit - 32) * 5 / 9;
  if(result < -128)
    return -128;
  if(result > 127)
    return 127;
  return result;
}

void CheckCAN()
{

///////////////////////////////////////////////////////////////////////////////////////////////////////////
//read incomming data from inverter//////////////////
//////////////////////////////////////////////////////
  if(Can0.available())
  {
    Can0.read(inFrame);
    //Serial.println(inFrame.id, HEX);
  

  if(inFrame.id == 0x1da && inFrame.length == 8){
  //  last_received_from_inverter_timestamp = millis();

    inverter_status.voltage = ((uint16_t)inFrame.data.bytes[0] << 2) |
        (inFrame.data.bytes[1] >> 6);

    int16_t parsed_speed = ((uint16_t)inFrame.data.bytes[4] << 8) |
        (uint16_t)inFrame.data.bytes[5];
    inverter_status.speed = (parsed_speed == 0x7fff ? 0 : parsed_speed);

    inverter_status.error_state = (inFrame.data.bytes[6] & 0xb0) != 0x00;
  }

  if(inFrame.id == 0x55a && inFrame.length == 8){
   // last_received_from_inverter_timestamp = millis();

    inverter_status.inverter_temperature = fahrenheit_to_celsius(inFrame.data.bytes[2]);
    inverter_status.motor_temperature = fahrenheit_to_celsius(inFrame.data.bytes[1]);
    //Serial.println(inverter_status.inverter_temperature);
  }

  }

////////////////////////////////////////////////////////////////////////////////////////////////

  
}

static void nissan_crc(uint8_t *data, uint8_t polynomial)
{
  // We want to process 8 bytes with the 8th byte being zero
  data[7] = 0;
  uint8_t crc = 0;
  for(int b=0; b<8; b++)
  {
    for(int i=7; i>=0; i--)
    {
      uint8_t bit = ((data[b] &(1 << i)) > 0) ? 1 : 0;
      if(crc >= 0x80) 
        crc = (byte)(((crc << 1) + bit) ^ polynomial);
      else 
        crc = (byte)((crc << 1) + bit);
    }
  }
  data[7] = crc;
}
Alibro
Posts: 829
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 248 times
Been thanked: 144 times
Contact:

Re: Leaf Gen 1 Inverter Board

Post by Alibro »

Thanks James
I take it I just treat the VCU like an Arduino and upload the software after tweaking it as you suggest?
Damien sent it pre-configured so all I had to do was solder in the connectors.
I guess I've had an easy time so far compared to many of you guys. Thanks D. :D

I also meant to say thanks to the rest of you guys who blazed a trail here. I'd have been lost without you. :)
I need a bigger hammer!
User avatar
james@N52E01
Posts: 144
Joined: Wed Sep 18, 2019 7:02 am
Has thanked: 2 times
Been thanked: 3 times

Re: Leaf Gen 1 Inverter Board

Post by james@N52E01 »

Alibro wrote: Sun Oct 04, 2020 9:47 pm I take it I just treat the VCU like an Arduino and upload the software after tweaking it as you suggest?
Basically yes, the board is a heavily modified Arduino Due so you’ll want to make sure you have Arduino Due Native USB available in the boards manager. You’ll also want to download all of the library files referenced at the top of the code.

If it’s your first time configuring the board you may want to reduce the MaxTrq (max torque value, basically limits the torque relative to the pedal position) for testing purposes. I started at 100 for testing and brought it up from there.

Glad there’s someone else working with the VCU, give us a shout if there’s anything you’re not sure about
Alibro
Posts: 829
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 248 times
Been thanked: 144 times
Contact:

Re: Leaf Gen 1 Inverter Board

Post by Alibro »

james@N52E01 wrote: Mon Oct 05, 2020 6:10 am
Alibro wrote: Sun Oct 04, 2020 9:47 pm I take it I just treat the VCU like an Arduino and upload the software after tweaking it as you suggest?
Basically yes, the board is a heavily modified Arduino Due so you’ll want to make sure you have Arduino Due Native USB available in the boards manager. You’ll also want to download all of the library files referenced at the top of the code.

If it’s your first time configuring the board you may want to reduce the MaxTrq (max torque value, basically limits the torque relative to the pedal position) for testing purposes. I started at 100 for testing and brought it up from there.

Glad there’s someone else working with the VCU, give us a shout if there’s anything you’re not sure about
Brilliant thanks James
Really appreciate the advise.
I need a bigger hammer!
User avatar
mackoffgrid
Posts: 93
Joined: Thu Jan 02, 2020 10:18 am
Location: Brisbane Australia
Has thanked: 4 times

Re: Leaf Gen 1 Inverter Board

Post by mackoffgrid »

Alibro wrote: Sun Sep 27, 2020 3:54 pm I have a pile of good 12V lead acid batteries I can run in series so could go all the way to 400V if necessary but would prefer to start at a much lower voltage.
This is only for bench testing and I know the motor will run at 50V but unsure about the minimum voltage for the inverter
I tested for minimum voltage on my Gen 1 inverter and found it would throw an error in the 175v to 185v (was a bit hard to be exact) as a minimum voltage.

Good luck with your bench test :)
https://github.com/mackelec/SolarUte
meFDCAN Arduino Library 3 FDCAN port stm32G4xx
meCAN Arduino Library 2023 version 2/3 CAN port stm32F0xx, stm32F1xx, stm32F4xx, stm32L4xx
User avatar
james@N52E01
Posts: 144
Joined: Wed Sep 18, 2019 7:02 am
Has thanked: 2 times
Been thanked: 3 times

Re: Leaf Gen 1 Inverter Board

Post by james@N52E01 »

Yeah that sound spot on with what Fiachra and I both found. I was able to turn the wheels while off the ground at 190v but with weight on the wheels the inverter would throw an error with even a little torque.
Alibro
Posts: 829
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 248 times
Been thanked: 144 times
Contact:

Re: Leaf Gen 1 Inverter Board

Post by Alibro »

I have 16 batteries connected giving approx 205V but can add more if needed.
I've connected them through an old cooker switch so that initially they connect through 6 x 4R7 50W resistors, then after a second or so I turn the switch again to connect them directly and disconnect the resistors.
Obviously this is only a temporary solution for bench testing but it seems to work.
I'm having some issues calibrating the throttle pedal though so if anyone has any pointers I'd appreciate a little help.
I've set the code to send data to the serial monitor so I have the numbers for both hall sensors in the pedal.
I then reloaded the default code and tried entering the numbers but although the motor isn't going mad now when the ignition is turned on, it's still not being controlled correctly and keeps over speeding then cutting out.

I tried James's code with my Leaf pedal but it didn't work for me. I hadn't calibrated the throttle pedal at that point so I maybe mine is different but I now have my Freelander pedal connected as that's the one I want to use.

Would using a higher voltage be helpful?

Should I use the higher voltage hall sensor in the throttle pedal or lower one?

Do I set the numbers exactly as they are from calibration or go higher/lower?

James mentioned I need to change max torque so I tried changing it from (I think) 2000 to 100 earlier but it made no difference however I hadn't calibrated the throttle pedal at that point.

Is it normal to have to unplug the molex connectors every time you need to reload the code? Mine seems to crash if they're connected as I'm uploading. Having to pull the connectors off every time I make a change and reload is a pain.

Should I have full control of the motor speed using the throttle pedal while unloaded on the bench?

Hopefully by the time you read this I'll have answered some of these questions myself but sharing your experiences will be helpful for others
I need a bigger hammer!
User avatar
james@N52E01
Posts: 144
Joined: Wed Sep 18, 2019 7:02 am
Has thanked: 2 times
Been thanked: 3 times

Re: Leaf Gen 1 Inverter Board

Post by james@N52E01 »

I’ll have a go at answering questions as they appear, please weigh in anyone else if I miss anything
Alibro wrote: Sat Oct 10, 2020 6:30 am I have 16 batteries connected giving approx 205V but can add more if needed.
This should be enough to test that the VCU/inverter/motor work as long as you don’t have much friction added to the motor (e.g. if the motor is connected to the vehicle already). Because this is still well below the minimum Leaf battery voltage the inverter misbehaves when you add too much torque or get above a certain rpm (my inverter cut out completely and went into an error state around 5500rpm or with a torque command that would get it there too quickly possibly due to voltage sag). If you want to eliminate this during testing and you have the batteries available, suggest you just add a few cells at a time and then retest noting the effect it has on max rpm/torque before it cuts out. This would be very valuable information for anyone planning to use a lower voltage pack. I’m hoping to test at 250v next week once my new 50v test battery is finished so will let you know how that goes.
I'm having some issues calibrating the throttle pedal though so if anyone has any pointers I'd appreciate a little help.
I've set the code to send data to the serial monitor so I have the numbers for both hall sensors in the pedal.
I then reloaded the default code and tried entering the numbers but although the motor isn't going mad now when the ignition is turned on, it's still not being controlled correctly and keeps over speeding then cutting out.
As above, this sounds more like the issue associated with under voltage than an incorrectly calibrated throttle pedal. I had another look and the figures I posted are for the higher voltage signal 1 line, but they are off a bit. You might want to use ‘70, 310’ if you want to leave a bit of margins for Min Max. Not sure about the lower voltage signal wire but there is a really good video by thatguyoverthere posted earlier in this thread on how to calibrate your Freelander pedal from scratch. I’m sure he won’t mind me relinking it. All his work and helped a lot so thanks again for that:


Would using a higher voltage be helpful?
As above really, may help to separate any issues.
Should I use the higher voltage hall sensor in the throttle pedal or lower one?
Good question, technically the answer should be both. All drive by wire systems that I’ve seen use 2 wires for redundancy (for obvious reasons). It should be quite straight forward to incorporate the information from the second signal wire and add a function to discard either signal if it exceeds a given voltage boundary and throw up a warning but that’s still on the to do list. For now though as long as it’s calibrated properly it doesn’t matter which one you use. Not a very straight answer I know but thought it might help to have context.
Do I set the numbers exactly as they are from calibration or go higher/lower?
Another interesting question, you’ll want to add a margin to the bottom figure to prevent fluctuating torque commands even with your foot off the pedal just based off noise and mechanical defects/play in the pedal itself. You might want to reduce the upper figure a bit to ensure you have access to the full range of torque without trying to break the pedal off with your foot.
James mentioned I need to change max torque so I tried changing it from (I think) 2000 to 100 earlier but it made no difference however I hadn't calibrated the throttle pedal at that point.
That will be why. The max torque parameter is just saying where do you want the top of the scale to be for the torque command translated from the throttle pedal position (I.e. the range of available torque is from 0 - max torque). As long as the throttle pedal is calibrated correctly, setting this figure as 100 should just restrict the available torque to 5% of what is being implemented on the latest version of the code. I honestly don’t know though if 2000 would be the full 250nm torque available from the inverter, will hopefully find out soon during testing.
Is it normal to have to unplug the molex connectors every time you need to reload the code? Mine seems to crash if they're connected as I'm uploading. Having to pull the connectors off every time I make a change and reload is a pain.
We’ve all experienced that problem Fiachra figured this one out, it probably means you haven’t grounded the screening to the usb wires on the molex so the electrical noise they are generating is playing merry hell with your USB port. Suggest either screening the usb wires or if you’re lazy like me, just remove them from the plug altogether.
Should I have full control of the motor speed using the throttle pedal while unloaded on the bench?
As above, it depends on the voltage you are using.
Hopefully by the time you read this I'll have answered some of these questions myself but sharing your experiences will be helpful for others
Hopefully some of this helps, I’m going to incorporate some of this into the Leaf VCU wiki when I can find a bit of time. Looking forward to seeing how you get on.
Alibro
Posts: 829
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 248 times
Been thanked: 144 times
Contact:

Re: Leaf Gen 1 Inverter Board

Post by Alibro »

Thanks for such a comprehensive answer James. I haven't been able to get back to it yet as currently fighting with SWMBO's Ford Kuga ABS sensor. :(
Just grabbing a chance to read and answer this while having lunch and waiting for the WD40 to do nothing at all (probably).

Annoyingly the Leaf motor is on the bench beside me as I work just teasing me. :lol:

I'll throw a couple more batteries in to bring the voltage up and try again. I managed to salvage around 50 x 12V cells from UPS's that were being scrapped but the cells are still good.

Removing the USB wires is a good call as I discovered before the connectors are fairly easy to take apart. Don't ask why I had to take it apart. :?

BTW talking about Molex connectors has anyone else found the 20 way has one of the guides in the wrong position. I ordered 5 from RS along with the rest of the connectors and pins but when they came back saying they would be 4-8 weeks coming I ordered one from ebay. I thought maybe the ebay one was wrong but the 5 from RS arrived and they are too. Of course I took the dremmel to the connector rather than the socket. :(
I need a bigger hammer!
Alibro
Posts: 829
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 248 times
Been thanked: 144 times
Contact:

Re: Leaf Gen 1 Inverter Board

Post by Alibro »

So I spent a good part of the day working at this and I think I'm almost there. I can control it OK if I use a very small amount of throttle but if I go to around a quarter to half throttle it spins up but won't slow down when I release the throttle. If I then just touch the throttle it spins faster and won't stop until I turn off the ignition. It's pretty much like Fiachra's did in one of his videos.
Is this normal and does the inverter need a load to pull it back down?
I need a bigger hammer!
Post Reply