[DRIVING] Renault Clio Electrique -97

Tell us about the project you do with the open inverter
User avatar
bexander
Posts: 835
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: [DRIVING] Renault Clio Electrique -97

Post by bexander »

I have confirmed communication with a Prius inverter so my HW is ok.
Not sure what my next step should be other then to test and spin the motor. But might be good to use current limited supply instead of 400Vdc battery if something goes bad... Will have to up my SW so it communicates with the car as well.
User avatar
bexander
Posts: 835
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: [DRIVING] Renault Clio Electrique -97

Post by bexander »

Tried to spin the MGR today, without success :(
The motor yerks and want's to produce torque for a very short time. Keeps pulsing but no steady torque.
I did only use a power supply of 36V, 10A. Maybe needs higher voltage? Damien used 60V in the video.
Did test all 4 resolver possibilities, no changes. Also tested swapping two motor phases, for every resolver possibility, no change.
Also possible my SW is wrong somehow but comunication runs and the inverter responds to torque command.

SW used. I have relized that the type defs in struct InverterStatus should be signed but they are never sent to the inverter so should not matter.

Code: Select all

// Change log
/*

2
* Changes in setup() to get USART working correctly

1
* Initial version based on GS450h_v3 and GS450h.cpp, by T.Darby and D.Maguire

*/

// Include libraries
#include "due_can.h"

// Constant declaration
const uint16_t maxSpeed = 10000;
const uint8_t htm_data_init[7][100]=
{
   {0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,4,0,25,0,0,0,0,0,0,0,0,0,0,136,0,0,0,160,0,0,0,0,0,0,0,95,1},
   {0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,4,0,25,0,0,0,0,0,0,0,0,0,0,136,0,0,0,160,0,0,0,0,0,0,0,95,1},
   {0,30,0,0,0,0,0,18,0,154,250,0,0,0,0,97,4,0,0,0,0,0,173,255,82,0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,4,75,25,60,246,52,8,0,0,0,0,0,0,138,0,0,0,168,0,0,0,1,0,0,0,72,7},
   {0,30,0,0,0,0,0,18,0,154,250,0,0,0,0,97,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,4,75,25,60,246,52,8,0,0,0,0,0,0,138,0,0,0,168,0,0,0,2,0,0,0,75,5},
   {0,30,0,0,0,0,0,18,0,154,250,0,0,0,0,97,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,4,75,25,60,246,52,8,0,0,0,0,0,0,138,0,0,0,168,0,0,0,2,0,0,0,75,5},
   {0,30,0,0,0,0,0,18,0,154,250,0,0,255,0,97,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,255,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,255,4,73,25,60,246,52,8,0,0,255,0,0,0,138,0,0,0,168,0,0,0,3,0,0,0,70,9},
   {0,30,0,2,0,0,0,18,0,154,250,0,0,16,0,97,0,0,0,0,0,0,200,249,56,6,165,0,136,0,63,0,16,0,0,0,63,0,16,0,3,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,16,0,75,12,45,248,21,6,0,0,16,0,0,0,202,0,211,0,16,0,0,0,134,16,0,0,130,10}
};

// Variable declaration
uint8_t htm_data[100];
uint8_t mth_data[120];
uint16_t inCounter = 0;
uint16_t outCounter = 0;

struct InverterRequest {
	int16_t mg1Torque = 0;
	int16_t mg2Torque = 0;
	uint8_t gear = 'N'; 
} inverterRequest;

struct InverterStatus {
	uint16_t dcBusVoltage = 0;
  uint16_t tempInvWater = 0;
  uint16_t tempInvInductor = 0;
  uint16_t mg1Speed = 0;
  uint16_t mg2Speed = 0;
} inverterStatus;

// I/O-PINS
const uint8_t reqPIN = 22; // D22
const uint8_t invPwrPIN = 54; // D54, inverter 12V supply
const uint8_t igctPIN = 57; // D57, dc/dc 12V supply
const uint8_t vloPIN = 60; // D60, voltage cont for dc/dc
const uint8_t mgrTempPIN = 61; // A7, MGR stator temperature
const uint8_t drivePIN = 7; // D7
const uint8_t reversePIN = 6; // D6
const uint8_t accPIN = 63; // A9


/********
* SETUP *
********/
void setup()
{
	pinMode(reqPIN, OUTPUT);
	digitalWrite(reqPIN, HIGH);
	
	pinMode(invPwrPIN, OUTPUT);
	digitalWrite(invPwrPIN, LOW);
	
	pinMode(igctPIN, OUTPUT);
	digitalWrite(igctPIN, LOW);
	
	pinMode(vloPIN, OUTPUT);
	digitalWrite(vloPIN, LOW);
	
	pinMode(drivePIN, INPUT_PULLUP);
	pinMode(reversePIN, INPUT_PULLUP);
	
	Serial1.begin(250000);
	
	PIOA->PIO_ABSR |= 1<<17;
  PIOA->PIO_PDR |= 1<<17;
	USART0->US_MR |= 1<<4 | 1<<8 | 1<<18;
	
	Can0.begin(CAN_BPS_250K);  //CAN bus at 250kbit/s
	
	Serial.begin(115200);
  Serial.print("Setup done!");
}


/*******
* LOOP *
*******/
void loop()
{
  controlInverter();
  printData();
}


/***************************************************
* Prepare data and send it to the Inverter (Motor) *
***************************************************/
void controlInverter()
{
	static uint32_t lastMillisData = millis();
	static uint32_t lastMillisInput = millis();
	
	if (millis() - lastMillisData >= 1) // 1ms
  {
		static uint8_t dataState = 0;
		static uint8_t setupState = 0;
		
		lastMillisData = millis();  // Reset timer
		
		if(0 == dataState)
		{
			uint8_t mth_byte = 0;
			
			digitalWrite(reqPIN, LOW);
			
			for(int i=0; i<120; i++) // Clear array
			{
				mth_data[i]=0;
			}
			
			while(Serial1.available()) // Receive data
			{
				mth_data[mth_byte] = Serial1.read();
				mth_byte++;
			}
			
			if(mth_byte >= 120) // Increase counter if all data received
			{
				inCounter++;
			}
			
			dataState++;
		}
		
		else if(1 == dataState)
		{
			digitalWrite(reqPIN, HIGH);
			
			if(setupState > 5)
			{
				for(int i=0; i<100; i++)
				{
					Serial1.write(htm_data[i]);
				}
				
				outCounter++;
			}
			else
			{
				for(int i=0; i<100; i++)
				{
					Serial1.write(htm_data_init[setupState][i]);
				}
				
				setupState++;
				outCounter++;
			}
			dataState++;
		}
		
		else if(2 == dataState)
		{
			dataState++;
		}
		
		else if(3 == dataState)
		{
			if(verifyMTHChecksum())
			{
				inverterStatus.dcBusVoltage = ((mth_data[100] | mth_data[101] << 8) - 5) / 2;
        inverterStatus.tempInvWater = mth_data[42] | mth_data[43] << 8;
        inverterStatus.tempInvInductor = mth_data[86] | mth_data[87] << 8;
        inverterStatus.mg1Speed = mth_data[6] | mth_data[7] << 8;
        inverterStatus.mg2Speed = mth_data[38] | mth_data[39] << 8;
			}
			else
			{
				// Error
			}
			dataState++;
		}
		
		else if(4 == dataState)
		{
			static boolean frameCount = false;
			
			// MG1
			htm_data[76] = (inverterRequest.mg1Torque * 4) & 0xFF;
      htm_data[75] = ((inverterRequest.mg1Torque * 4) >> 8) & 0xFF;

      htm_data[5] = (inverterRequest.mg1Torque) & 0xFF;  // Negative is forward
      htm_data[6] = ((inverterRequest.mg1Torque) >> 8);
      htm_data[11] = htm_data[5];
      htm_data[12] = htm_data[6];

      // MG2
      htm_data[30] = (inverterRequest.mg2Torque) & 0xFF; // Positive is forward
      htm_data[31] = ((inverterRequest.mg2Torque) >> 8) & 0xFF;

      if(inverterRequest.mg2Torque > 0)
      {
         // Forward direction these bytes should match
         htm_data[26] = htm_data[30];
         htm_data[27] = htm_data[31];
         htm_data[28] = (inverterRequest.mg2Torque / 2) & 0xFF; // Positive is forward
         htm_data[29] = ((inverterRequest.mg2Torque / 2) >> 8) & 0xFF;
      }

      if(inverterRequest.mg2Torque < 0)
      {
         // Reverse direction these bytes should match
         htm_data[28] = htm_data[30];
         htm_data[29] = htm_data[31];
         htm_data[26] = (inverterRequest.mg2Torque / 2) & 0xFF; // Negative is reverse
         htm_data[27] = ((inverterRequest.mg2Torque / 2) >> 8) & 0xFF;
      }

      // Other settings
      htm_data[85] = (-5000) & 0xFF;  // Charge ability of battery
      htm_data[86] = ((-5000) >> 8);

      htm_data[87] = (-10000) & 0xFF;  // Discharge ability of battery
      htm_data[88] = ((-10000) >> 8);

      /*// Checksum
      if(++frame_count & 0x01)
      {
         htm_data[94]++;
      }*/
      
      // Checksum
      if(frameCount)
      {
				htm_data[94]++;
			}
			frameCount = !frameCount;

      calcHTMChecksum();

      dataState = 0;
		}
		
		else
		{
			// Error
		}
	}
	
	if (millis() - lastMillisInput >= 10) // 10ms, read input and convert to torque command
  {
		lastMillisInput = millis();  // Reset timer
  
    if(!digitalRead(drivePIN) && digitalRead(reversePIN))
    {
			inverterRequest.gear = 'D';
		}
		if(digitalRead(drivePIN) && !digitalRead(reversePIN))
    {
			inverterRequest.gear = 'R';
		}
		if(digitalRead(drivePIN) && digitalRead(reversePIN))
    {
			inverterRequest.gear = 'N';
		}
    
    uint16_t accPedal = analogRead(accPIN);
    accPedal = max(100, accPedal);
    accPedal = min(900, accPedal);
		
		if('N' == inverterRequest.gear)
		{
			inverterRequest.mg2Torque = 0;
		}
		else if('D' == inverterRequest.gear)
		{
			inverterRequest.mg2Torque = map(accPedal, 100, 900, 0, 1000);
		}
		else if('R' == inverterRequest.gear)
		{
			inverterRequest.mg2Torque = map(accPedal, 100, 900, 0, -1000);
		}
    
    /*if((inverterStatus.mg2Speed > maxSpeed) || (inverterStatus.mg2Speed < -maxSpeed))
    {
			inverterRequest.mg2Torque = 0;
		}*/
	}
}


/*********************************
* Check if checksum matches data *
*********************************/
boolean verifyMTHChecksum()
{
   uint16_t mth_checksum = 0;

   for(int i=0; i<118; i++)
   {
		 mth_checksum += mth_data[i];
	 }

   /*if((mth_data[118] | (mth_data[119] << 8)) == mth_checksum)
   {
		 return true;
	 }
	 else
	 {
		 return false;
	 }*/
	 
	 boolean checksumStatus = ((mth_data[118] | (mth_data[119] << 8)) == mth_checksum);
	 
	 return checksumStatus;
}


/****************************************
* Calculates checksum for outgoing data *
****************************************/
void calcHTMChecksum()
{
   uint16_t htm_checksum = 0;

   for(int i=0; i<(98); i++)
   {
		 htm_checksum += htm_data[i];
	 }
	 
   htm_data[98] = htm_checksum & 0xFF;
   htm_data[99] = htm_checksum >> 8;
}


/***************************
* Sends data to USB-Serial *
***************************/
void printData()
{
	static uint32_t lastMillisPrint = millis();
	
	if (millis() - lastMillisPrint >= 1000) // 1000ms
  {
		lastMillisPrint = millis();  // Reset timer
		
		// Inverter request
		Serial.print("Request, MG1_T: ");
		Serial.print(inverterRequest.mg1Torque);
		Serial.print(" MG2_T: ");
		Serial.print(inverterRequest.mg2Torque);
		Serial.print(" Gear: ");
		Serial.println(inverterRequest.gear);
		
		// Inverter data
		Serial.print("Data, DC_bus: ");
		Serial.print(inverterStatus.dcBusVoltage);
		Serial.print(" Temp W: ");
		Serial.print(inverterStatus.tempInvWater);
		Serial.print(" Temp I: ");
		Serial.print(inverterStatus.tempInvInductor);
		Serial.print(" MG1_S: ");
		Serial.print(inverterStatus.mg1Speed);
		Serial.print(" MG2_S: ");
		Serial.println(inverterStatus.mg2Speed);
		
		// Data
		Serial.print("Incomming packages: ");
		Serial.print(inCounter);
		Serial.print(" Outgoing packages: ");
		Serial.println(outCounter);
	}
}
I could try to source another power supply with higher voltage output.
Could alse source a Yaris or Prius transaxle to test as reference but have no other use for it. The MGR differs from the MG1 and MG2 but I was hoping it would work anyway...
Any suggestion from the forum on how to proceed?
User avatar
Ev8
Posts: 801
Joined: Sat Jan 30, 2021 11:05 am
Has thanked: 41 times
Been thanked: 149 times

Re: [DRIVING] Renault Clio Electrique -97

Post by Ev8 »

Fairly sure people have experienced the same when testing gs450h transmissions with very low voltages.
User avatar
bexander
Posts: 835
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: [DRIVING] Renault Clio Electrique -97

Post by bexander »

Ev8 wrote: Fri Sep 29, 2023 12:09 pm Fairly sure people have experienced the same when testing gs450h transmissions with very low voltages.
Ok, so focus on finding a supply with higher voltage then.

EDIT: Just put in an order for a cheap 120V 3A bench top power supply. Slow delivery though so will have to wait a bit.
User avatar
Ev8
Posts: 801
Joined: Sat Jan 30, 2021 11:05 am
Has thanked: 41 times
Been thanked: 149 times

Re: [DRIVING] Renault Clio Electrique -97

Post by Ev8 »

So you have another power supply you could add in series to your 36v? Should in theory work if you disconnect the earths! Lol just for a quick test
User avatar
bexander
Posts: 835
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: [DRIVING] Renault Clio Electrique -97

Post by bexander »

Yes, well I have 7pcs of Eltek FP 2 HE 48V power supplies, but they aren't great at limiting current down to 0V so not the best for this kind if experimenting but I'm thinking about using 2pcs for ~100V and using a current limiting light bulb in series or something...
The PSU I ordered seem to ship from Poland so could arrive quickly if I'm lucky.
User avatar
bexander
Posts: 835
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: [DRIVING] Renault Clio Electrique -97

Post by bexander »

New power supply arrived and I have tested to spin the MGR using 80V and YES, it spins!!
At the moment it only works in reverse gear and wheels in the air so not producing a lot of torque.
Will try to figure out why it woun't work in forward. It only consumes power and my thinking is that the inverter tries to do regen or something so will have a play with signing of torque request and other things.

EDIT:
The SW used.

Code: Select all

// Change log
/*

2_1
* Changes to Inverter.Status struct
* Changed how dcBusVoltage is calculated in controlInverter()
* Changed to Serial.write for gear print out in printData()

2
* Changes in setup() to get USART working correctly

1
* Initial version based on GS450h_v3 and GS450h.cpp, by T.Darby and D.Maguire

*/

// Include libraries
#include "due_can.h"

// Constant declaration
const uint16_t maxSpeed = 10000;
const uint8_t htm_data_init[7][100]=
{
   {0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,4,0,25,0,0,0,0,0,0,0,0,0,0,136,0,0,0,160,0,0,0,0,0,0,0,95,1},
   {0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,4,0,25,0,0,0,0,0,0,0,0,0,0,136,0,0,0,160,0,0,0,0,0,0,0,95,1},
   {0,30,0,0,0,0,0,18,0,154,250,0,0,0,0,97,4,0,0,0,0,0,173,255,82,0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,4,75,25,60,246,52,8,0,0,0,0,0,0,138,0,0,0,168,0,0,0,1,0,0,0,72,7},
   {0,30,0,0,0,0,0,18,0,154,250,0,0,0,0,97,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,4,75,25,60,246,52,8,0,0,0,0,0,0,138,0,0,0,168,0,0,0,2,0,0,0,75,5},
   {0,30,0,0,0,0,0,18,0,154,250,0,0,0,0,97,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,4,75,25,60,246,52,8,0,0,0,0,0,0,138,0,0,0,168,0,0,0,2,0,0,0,75,5},
   {0,30,0,0,0,0,0,18,0,154,250,0,0,255,0,97,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,255,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,255,4,73,25,60,246,52,8,0,0,255,0,0,0,138,0,0,0,168,0,0,0,3,0,0,0,70,9},
   {0,30,0,2,0,0,0,18,0,154,250,0,0,16,0,97,0,0,0,0,0,0,200,249,56,6,165,0,136,0,63,0,16,0,0,0,63,0,16,0,3,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,16,0,75,12,45,248,21,6,0,0,16,0,0,0,202,0,211,0,16,0,0,0,134,16,0,0,130,10}
};

// Variable declaration
uint8_t htm_data[100];
uint8_t mth_data[120];
uint16_t inCounter = 0;
uint16_t outCounter = 0;

struct InverterRequest {
	int16_t mg1Torque = 0;
	int16_t mg2Torque = 0;
	uint8_t gear = 'N'; 
} inverterRequest;

struct InverterStatus {
	uint16_t dcBusVoltage = 0;
  int16_t tempInvWater = 0;
  int16_t tempInvInductor = 0;
  int16_t mg1Speed = 0;
  int16_t mg2Speed = 0;
} inverterStatus;

// I/O-PINS
const uint8_t reqPIN = 22; // D22
const uint8_t invPwrPIN = 54; // D54, inverter 12V supply
const uint8_t igctPIN = 57; // D57, dc/dc 12V supply
const uint8_t vloPIN = 60; // D60, voltage cont for dc/dc
const uint8_t mgrTempPIN = 61; // A7, MGR stator temperature
const uint8_t drivePIN = 7; // D7
const uint8_t reversePIN = 6; // D6
const uint8_t accPIN = 63; // A9


/********
* SETUP *
********/
void setup()
{
	pinMode(reqPIN, OUTPUT);
	digitalWrite(reqPIN, HIGH);
	
	pinMode(invPwrPIN, OUTPUT);
	digitalWrite(invPwrPIN, LOW);
	
	pinMode(igctPIN, OUTPUT);
	digitalWrite(igctPIN, LOW);
	
	pinMode(vloPIN, OUTPUT);
	digitalWrite(vloPIN, LOW);
	
	pinMode(drivePIN, INPUT_PULLUP);
	pinMode(reversePIN, INPUT_PULLUP);
	
	Serial1.begin(250000);
	
	PIOA->PIO_ABSR |= 1<<17;
  PIOA->PIO_PDR |= 1<<17;
	USART0->US_MR |= 1<<4 | 1<<8 | 1<<18;
	
	Can0.begin(CAN_BPS_250K);  //CAN bus at 250kbit/s
	
	Serial.begin(115200);
  Serial.print("Setup done!");
}


/*******
* LOOP *
*******/
void loop()
{
  controlInverter();
  printData();
}


/***************************************************
* Prepare data and send it to the Inverter (Motor) *
***************************************************/
void controlInverter()
{
	static uint32_t lastMillisData = millis();
	static uint32_t lastMillisInput = millis();
	
	if (millis() - lastMillisData >= 1) // 1ms
  {
		static uint8_t dataState = 0;
		static uint8_t setupState = 0;
		
		lastMillisData = millis();  // Reset timer
		
		if(0 == dataState)
		{
			uint8_t mth_byte = 0;
			
			digitalWrite(reqPIN, LOW);
			
			for(int i=0; i<120; i++) // Clear array
			{
				mth_data[i]=0;
			}
			
			while(Serial1.available()) // Receive data
			{
				mth_data[mth_byte] = Serial1.read();
				mth_byte++;
			}
			
			if(mth_byte >= 120) // Increase counter if all data received
			{
				inCounter++;
			}
			
			dataState++;
		}
		
		else if(1 == dataState)
		{
			digitalWrite(reqPIN, HIGH);
			
			if(setupState > 5)
			{
				for(int i=0; i<100; i++)
				{
					Serial1.write(htm_data[i]);
				}
				
				outCounter++;
			}
			else
			{
				for(int i=0; i<100; i++)
				{
					Serial1.write(htm_data_init[setupState][i]);
				}
				
				setupState++;
				outCounter++;
			}
			dataState++;
		}
		
		else if(2 == dataState)
		{
			dataState++;
		}
		
		else if(3 == dataState)
		{
			if(verifyMTHChecksum())
			{
				//inverterStatus.dcBusVoltage = ((mth_data[100] | mth_data[101] << 8) - 5) / 2;
        //inverterStatus.dcBusVoltage = ((mth_data[100] | mth_data[101] << 8) - 0) * 0.615;
        inverterStatus.dcBusVoltage = ((mth_data[100] | mth_data[101] << 8) - 0) * 30 / 49;
        inverterStatus.tempInvWater = mth_data[42] | mth_data[43] << 8;
        inverterStatus.tempInvInductor = mth_data[86] | mth_data[87] << 8;
        inverterStatus.mg1Speed = mth_data[6] | mth_data[7] << 8;
        inverterStatus.mg2Speed = mth_data[38] | mth_data[39] << 8;
			}
			else
			{
				// Error
			}
			dataState++;
		}
		
		else if(4 == dataState)
		{
			static boolean frameCount = false;
			
			// MG1
			htm_data[76] = (inverterRequest.mg1Torque * 4) & 0xFF;
      htm_data[75] = ((inverterRequest.mg1Torque * 4) >> 8) & 0xFF;

      htm_data[5] = (inverterRequest.mg1Torque) & 0xFF;  // Negative is forward
      htm_data[6] = ((inverterRequest.mg1Torque) >> 8);
      htm_data[11] = htm_data[5];
      htm_data[12] = htm_data[6];

      // MG2
      htm_data[30] = (inverterRequest.mg2Torque) & 0xFF; // Positive is forward
      htm_data[31] = ((inverterRequest.mg2Torque) >> 8) & 0xFF;

      if(inverterRequest.mg2Torque > 0)
      {
         // Forward direction these bytes should match
         htm_data[26] = htm_data[30];
         htm_data[27] = htm_data[31];
         htm_data[28] = (inverterRequest.mg2Torque / 2) & 0xFF; // Positive is forward
         htm_data[29] = ((inverterRequest.mg2Torque / 2) >> 8) & 0xFF;
      }

      if(inverterRequest.mg2Torque < 0)
      {
         // Reverse direction these bytes should match
         htm_data[28] = htm_data[30];
         htm_data[29] = htm_data[31];
         htm_data[26] = (inverterRequest.mg2Torque / 2) & 0xFF; // Negative is reverse
         htm_data[27] = ((inverterRequest.mg2Torque / 2) >> 8) & 0xFF;
      }

      // Other settings
      htm_data[85] = (-5000) & 0xFF;  // Charge ability of battery
      htm_data[86] = ((-5000) >> 8);

      htm_data[87] = (-10000) & 0xFF;  // Discharge ability of battery
      htm_data[88] = ((-10000) >> 8);

      /*// Checksum
      if(++frame_count & 0x01)
      {
         htm_data[94]++;
      }*/
      
      // Checksum
      if(frameCount)
      {
				htm_data[94]++;
			}
			frameCount = !frameCount;

      calcHTMChecksum();

      dataState = 0;
		}
		
		else
		{
			// Error
		}
	}
	
	if (millis() - lastMillisInput >= 10) // 10ms, read input and convert to torque command
  {
		lastMillisInput = millis();  // Reset timer
  
    if(!digitalRead(drivePIN) && digitalRead(reversePIN))
    {
			inverterRequest.gear = 'D';
		}
		if(digitalRead(drivePIN) && !digitalRead(reversePIN))
    {
			inverterRequest.gear = 'R';
		}
		if(digitalRead(drivePIN) && digitalRead(reversePIN))
    {
			inverterRequest.gear = 'N';
		}
    
    uint16_t accPedal = analogRead(accPIN);
    accPedal = max(100, accPedal);
    accPedal = min(900, accPedal);
		
		if('N' == inverterRequest.gear)
		{
			inverterRequest.mg2Torque = 0;
		}
		else if('D' == inverterRequest.gear)
		{
			inverterRequest.mg2Torque = map(accPedal, 100, 900, 0, 1000);
		}
		else if('R' == inverterRequest.gear)
		{
			inverterRequest.mg2Torque = map(accPedal, 100, 900, 0, -1000);
		}
    
    if((inverterStatus.mg2Speed > maxSpeed) || (inverterStatus.mg2Speed < -maxSpeed))
    {
			inverterRequest.mg2Torque = 0;
		}
	}
}


/*********************************
* Check if checksum matches data *
*********************************/
boolean verifyMTHChecksum()
{
   uint16_t mth_checksum = 0;

   for(int i=0; i<118; i++)
   {
		 mth_checksum += mth_data[i];
	 }

   /*if((mth_data[118] | (mth_data[119] << 8)) == mth_checksum)
   {
		 return true;
	 }
	 else
	 {
		 return false;
	 }*/
	 
	 boolean checksumStatus = ((mth_data[118] | (mth_data[119] << 8)) == mth_checksum);
	 
	 return checksumStatus;
}


/****************************************
* Calculates checksum for outgoing data *
****************************************/
void calcHTMChecksum()
{
   uint16_t htm_checksum = 0;

   for(int i=0; i<(98); i++)
   {
		 htm_checksum += htm_data[i];
	 }
	 
   htm_data[98] = htm_checksum & 0xFF;
   htm_data[99] = htm_checksum >> 8;
}


/***************************
* Sends data to USB-Serial *
***************************/
void printData()
{
	static uint32_t lastMillisPrint = millis();
	
	if (millis() - lastMillisPrint >= 1000) // 1000ms
  {
		lastMillisPrint = millis();  // Reset timer
		
		// Inverter request
		Serial.print("Request, MG1_T: ");
		Serial.print(inverterRequest.mg1Torque);
		Serial.print(" MG2_T: ");
		Serial.print(inverterRequest.mg2Torque);
		Serial.print(" Gear: ");
		Serial.write(inverterRequest.gear);
		Serial.println();
		
		// Inverter data
		Serial.print("Data, DC_bus: ");
		Serial.print(inverterStatus.dcBusVoltage);
		Serial.print(" Temp W: ");
		Serial.print(inverterStatus.tempInvWater);
		Serial.print(" Temp I: ");
		Serial.print(inverterStatus.tempInvInductor);
		Serial.print(" MG1_S: ");
		Serial.print(inverterStatus.mg1Speed);
		Serial.print(" MG2_S: ");
		Serial.println(inverterStatus.mg2Speed);
		
		// Data
		Serial.print("Incomming packages: ");
		Serial.print(inCounter);
		Serial.print(" Outgoing packages: ");
		Serial.println(outCounter);
	}
}
User avatar
bexander
Posts: 835
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: [DRIVING] Renault Clio Electrique -97

Post by bexander »

I can't make the MGR run in reverse. I suspect it is down to resolver timing?
When I swap resolver pinout I get same behaviour but in both directions, i.e. no motor rotation, inverter only draws current and whines.
At this point I have no other idea on what to test?

BTW, the inverter/motor runs fine on 36V. Don't now why it didn't work the first time.
Also, it seem to be enough to send torque command on htm_data[30] and [31] to get motor spining.

EDIT:
I also found this:
https://www.youtube.com/watch?v=d1XRV5c1Cq8
Tested with the SW linked in the comments, still no luck.
User avatar
celeron55
Posts: 776
Joined: Thu Jul 04, 2019 3:04 pm
Location: Finland
Has thanked: 28 times
Been thanked: 110 times
Contact:

Re: [DRIVING] Renault Clio Electrique -97

Post by celeron55 »

I would assume it's down to resolver wiring or offset, or phase wiring.

If absolutely necessary, it might be possible to rotate the resolver in the MGR slightly by using the center opening and the bolts behind the motor. Never tried that myself and I doubt it would help:
User avatar
bexander
Posts: 835
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: [DRIVING] Renault Clio Electrique -97

Post by bexander »

Did some more test, without and success.
I'm calling this fail at the moment. If anyone have any idea on what to test, let me now. It is fairly easy to do the needed setup now that I have all parts needed.
Even if several persons have reached spining motor, it does not mean it is garanteed to work when at high speed and high torque. Probably bigger chance of success with a prius transaxle though.
User avatar
Ev8
Posts: 801
Joined: Sat Jan 30, 2021 11:05 am
Has thanked: 41 times
Been thanked: 149 times

Re: [DRIVING] Renault Clio Electrique -97

Post by Ev8 »

Surely if it was a resolver offset issue you’d be seeing similar results to using an incorrect resolver offset in OI … motor running away with itself not following throttle commands
Yahha777
Posts: 52
Joined: Wed Feb 27, 2019 7:03 am
Location: Belorussia. Borisov
Has thanked: 15 times
Been thanked: 1 time
Contact:

Re: [DRIVING] Renault Clio Electrique -97

Post by Yahha777 »

Dear! What do you want to achieve? Make the MGR rotate at low voltage with rated torque? Explain. Can I help you? I have 2 MGRs connected to the Auris inverter, all of which are powered by 10 pcs 12 volt lead batteries. Unfortunately, I can’t connect the load to the drive. I uploaded the firmware recommended by Johannes in this thread to the mg2 controller. Your configs are the latest with my syncofs settings (but they are clearly not accurate). If I can be of any help, let me know!
User avatar
Ev8
Posts: 801
Joined: Sat Jan 30, 2021 11:05 am
Has thanked: 41 times
Been thanked: 149 times

Re: [DRIVING] Renault Clio Electrique -97

Post by Ev8 »

I know this many be a little late but I was reading the gs450h inverter communication thread yesterday and picked up on someone having similar problems to what you encountered when trying to use a Prius gen3 inverter to drive a gs450 motor, turns out the wiring diagram’s for the Prius inverter had confused them into connecting the resolver to mg1 whilst trying to drive with mg2, where you also decoding the received data back from the inverter? Getting a motor speed reading back on mg2?
User avatar
bexander
Posts: 835
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: [DRIVING] Renault Clio Electrique -97

Post by bexander »

Honestly, I can't remember if I got speed feedback or not but I "think" I did. It worked fine in one direction but not in the other. If the resolver is connected to MG1 while motor on MG2, would the motor spin at all?
Do you have a link to their attempts?
User avatar
Ev8
Posts: 801
Joined: Sat Jan 30, 2021 11:05 am
Has thanked: 41 times
Been thanked: 149 times

Re: [DRIVING] Renault Clio Electrique -97

Post by Ev8 »

about halfway down this page
viewtopic.php?t=205&hilit=gs450h+invert ... n&start=75
arturk mentions he's having difficulty with reverse, using a prius gen3 on gs450 motor

a couple of pages later:
arturk wrote: Tue Nov 26, 2019 5:06 am
I did test few things and wanted to share my findings.

Indeed, there was a problem with resolver connections but not with noise or signal quality.
Problem was again with documentation, I wired resolvers according to Camry documentation using inverter's external connector (keep in mind Camry inverter has this dedicated 13 pin connector for resolvers unlike GS450h). All of GXX(X) signals for Generator (MG1) and all MXX(X) signals for Motor (MG2). Turns out that does not work, in this configuration MG1 was matched wih MG2 resolver and vice versa. I was able to spin motors but reported positions were not accurate therefore I was getting rattling noise and stalling (great catch Damien!).

Fix was very easy, just swapped resolver cables at the transmission end and I get silky smooth response from motors! They now seem extremely powerful, spin up super fast and without an effort. Amazing!

but still he had issues with reverse.
later on in this thread he abandons the gen3 inverter and everything worked fine with a gs450 inverter.

this is however before it was discovered that the htm data for the gen3 is 100 bytes not 80 bytes like the gs450

your code looks to be using the same htm data as the gen3 prius in the zombieverter code so it should be right
User avatar
bexander
Posts: 835
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: [DRIVING] Renault Clio Electrique -97

Post by bexander »

Interesting.
If I would give this another go I would start with sourcing a Yaris gearbox so I can test the inverter against it's original HW. That way it can only be SW. When I can confirm that's working I could test with MGR.
BTW, that is also another issue, the Yaris inverter seem to change mid series to a different internal SW. So maybe better to test with Prius inverter as well?
However, I do have another project in the pipe with higher priority than the Clio so this kind of testing will have to wait.
User avatar
Ev8
Posts: 801
Joined: Sat Jan 30, 2021 11:05 am
Has thanked: 41 times
Been thanked: 149 times

Re: [DRIVING] Renault Clio Electrique -97

Post by Ev8 »

Fair enough, I was just reading up on Toyota sync serial comms and thought of you, reason being I have an rx450h inverter here that I’d like to get working via serial. Not sure how feasible finding the ham commands without a working car to log is going to be, if I do get it working, (I have a spare front transaxle and mgr to test all 3 inverters with) that could be another option for you just running the mgr inverter
User avatar
bexander
Posts: 835
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: [DRIVING] Renault Clio Electrique -97

Post by bexander »

Yes, that is a good option. The downside is that the RX450h inverter is quite bulky and the ones I've found cost a lot more than the Yaris/Prius ones.
Post Reply