Skip to content

Commit

Permalink
Merge branch 'Heater-Update-12-2024' into Developmental_NOT_VEHICLE
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-evnut committed Feb 14, 2025
2 parents 894a361 + 9d3c6b9 commit 3cfe40c
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 22 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ OBJSL = $(BINARY).o hwinit.o stm32scheduler.o params.o terminal.o terminal_prj.
param_save.o errormessage.o stm32_can.o leafinv.o utils.o terminalcommands.o i3LIM.o \
chademo.o amperaheater.o amperacharger.o subaruvehicle.o iomatrix.o bmw_sbox.o NissanPDM.o teslaCharger.o extCharger.o vag_sbox.o \
daisychainbms.o simpbms.o outlanderCharger.o Can_OBD2.o cansdo.o TeslaDCDC.o BMW_E31.o F30_Lever.o \
CPC.o ElconCharger.o RearOutlanderinverter.o linbus.o VWheater.o JLR_G1.o JLR_G2.o Foccci.o digipot.o\
OutlanderHeartBeat.o E65_Lever.o leafbms.o V_Classic.o kangoobms.o OutlanderCanHeater.o NissLeafMng.o
CPC.o ElconCharger.o RearOutlanderinverter.o linbus.o VWCoolantHeater.o JLR_G1.o JLR_G2.o Focci.o digipot.o\
OutlanderHeartBeat.o E65_Lever.o leafbms.o V_Classic.o kangoobms.o OutlanderCanHeater.o VWAirHeater.o\
MGCoolantHeater.o

OBJS = $(patsubst %.o,$(OUT_DIR)/%.o, $(OBJSL))
vpath %.c src/ libopeninv/src/
Expand Down
45 changes: 45 additions & 0 deletions include/MGCoolantHeater.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* This file is part of the Zombieverter VCU project.
*
* Copyright (C) 2018 Johannes Huebner <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef MGCOOLANTHEATER_H
#define MGCOOLANTHEATER_H

//#include <libopencm3/stm32/usart.h>
#include <heater.h>


class mgCoolantHeater : public Heater
{
public:
void SetTargetTemperature(float temp);
void SetCanInterface(CanHardware* c);
void DecodeCAN(int id, uint32_t data[2]);
void SetPower(uint16_t power, bool HeatReq);
void Task100Ms();

private:
int8_t currentTemperature;
int8_t desiredTemperature;

bool shouldHeat;
static void handle2B5(uint32_t data[2]);
static void handle2B6(uint32_t data[2]);

};

#endif // MGCOOLANTHEATER_H
41 changes: 41 additions & 0 deletions include/VWAirHeater.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file is part of the Zombieverter VCU project.
*
* Copyright (C) 2024 Tom de Bree <[email protected]>
* Copyright (C) 2018 Johannes Huebner <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
* Controls the VW LIN based heater as : https://openinverter.org/wiki/Volkswagen_Heater
*/
#ifndef VWAIRHEATER_H
#define VWAIRTHEATER_H

//#include <libopencm3/stm32/usart.h>
#include <heater.h>
#include "linbus.h"


class vwAirHeater : public Heater
{
public:
void SetTargetTemperature(float temp) { (void)temp; } //Not supported (yet)?
void SetPower(uint16_t power, bool HeatReq);
void SetLinInterface(LinBus* l);

private:
bool isAwake=false;
LinBus* lin;
};

#endif // VWAirHEATER_H
11 changes: 5 additions & 6 deletions include/VWheater.h → include/VWCoolantHeater.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* Controls the VW LIN based heater as : https://openinverter.org/wiki/Volkswagen_Heater
*/

#ifndef VWHEATER_H
#define VWHEATER_H
#ifndef VWCOOLANTHEATER_H
#define VWCOOLANTHEATER_H

//#include <libopencm3/stm32/usart.h>
#include <heater.h>
#include "linbus.h"


class vwHeater : public Heater
class vwCoolantHeater : public Heater
{
public:
void SetTargetTemperature(float temp) { (void)temp; } //Not supported (yet)?
Expand All @@ -36,6 +35,6 @@ class vwHeater : public Heater
private:
bool isAwake=false;
LinBus* lin;
};

#endif // VWHEATER_H
};
#endif // VWCOOLANTHEATER_H
13 changes: 7 additions & 6 deletions include/param_prj.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#define VER 2.22.A
#define VER 2.30.TA


/* Entries must be ordered as follows:
Expand Down Expand Up @@ -105,7 +104,7 @@
PARAM_ENTRY(CAT_BMS, BMS_VmaxLimit, "V", 0, 10, 4.2, 93 ) \
PARAM_ENTRY(CAT_BMS, BMS_TminLimit, "°C", -100, 100, 5, 94 ) \
PARAM_ENTRY(CAT_BMS, BMS_TmaxLimit, "°C", -100, 100, 50, 95 ) \
PARAM_ENTRY(CAT_HEATER, Heater, HTTYPE, 0, 3, 0, 57 ) \
PARAM_ENTRY(CAT_HEATER, Heater, HTTYPE, 0, 5, 0, 57 ) \
PARAM_ENTRY(CAT_HEATER, Control, HTCTRL, 0, 2, 0, 58 ) \
PARAM_ENTRY(CAT_HEATER, HeatPwr, "W", 0, 6500, 0, 59 ) \
PARAM_ENTRY(CAT_HEATER, HeatPercnt, "%", 0, 100, 0, 124 ) \
Expand Down Expand Up @@ -285,7 +284,7 @@
#define ERRLIGHTS "0=Off, 4=EPC, 8=engine"
#define CRUISESTATES "0=None, 1=On, 2=Disable, 4=Set, 8=Resume"
#define CDMSTAT "1=Charging, 2=Malfunction, 4=ConnLock, 8=BatIncomp, 16=SystemMalfunction, 32=Stop"
#define HTTYPE "0=None, 1=Ampera, 2=VW, 3=OutlanderCan"
#define HTTYPE "0=None, 1=Ampera, 2=VWCoolant, 3=VWAir, 4=OutlanderCan, 5=MGCoolant"
#define HTCTRL "0=Disable, 1=Enable, 2=Timer"
#define CHGMODS "0=Off, 1=EXT_DIGI, 2=Volt_Ampera, 3=Leaf_PDM, 4=TeslaOI, 5=Out_lander, 6=Elcon"
#define CHGCTRL "0=Enable, 1=Disable, 2=Timer"
Expand Down Expand Up @@ -388,8 +387,10 @@ enum HeatType
{
Noheater = 0,
AmpHeater = 1,
VW = 2,
OutlanderHeater = 3
VWCoolant = 2,
VWAir = 3,
OutlanderHeater = 4,
MGCoolant = 5
};

enum BMSModes
Expand Down
110 changes: 110 additions & 0 deletions src/MGCoolantHeater.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* This file is part of the Zombieverter VCU project.
*
* Copyright (C) 2018 Johannes Huebner <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
* Controls the MG heater as : https://openinverter.org/wiki/MG_Coolant_Heater
*
* Based on reverse engineer work by Tom de Bree
*
*/

#include <MGCoolantHeater.h>

static uint16_t HvVolt = 0;

void mgCoolantHeater::SetPower(uint16_t power, bool HeatReq)
{
shouldHeat = HeatReq;
power = power;//mask warning
}

void mgCoolantHeater::SetCanInterface(CanHardware* c)
{

can = c;
can->RegisterUserMessage(0x2B5);
can->RegisterUserMessage(0x2B6);
}

void mgCoolantHeater::Task100Ms()
{
uint8_t bytes[8];
bytes[0] = 0x00; //No Power!
bytes[1] = 0x00; //No Power!
bytes[2] = 0x01; //Fixed
bytes[3] = 0x00; //Fixed
bytes[4] = 0x00; //Fixed
bytes[5] = 0x60; //Fixed
bytes[6] = 0x00; //Fixed
bytes[7] = 0x00; //Fixed

if (shouldHeat)
{
bytes[0] = 0x04; //Max Power!!!! 0x04 gives 19A
bytes[1] = 0x0F; //Max Power!!!! 0x0F gives 19A
}
else
{

}

can->Send(0x2A0, (uint32_t*)bytes, 8);
}

void mgCoolantHeater::SetTargetTemperature(float temp)
{
desiredTemperature = temp;
}

void mgCoolantHeater::DecodeCAN(int id, uint32_t data[2])
{
switch (id)
{
case 0x2B5:
mgCoolantHeater::handle2B5(data);
break;
case 0x2B6:
mgCoolantHeater::handle2B6(data);
break;
}
}

void mgCoolantHeater::handle2B5(uint32_t data[2])
{
uint8_t* bytes = (uint8_t*)data;// arrgghhh this converts the two 32bit array into bytes. See comments are useful:)

uint8_t HvCur = bytes[4];//0.75A/1

Param::SetFloat(Param::powerheater,(HvVolt*HvCur*0.75));
}

void mgCoolantHeater::handle2B6(uint32_t data[2])
{
uint8_t* bytes = (uint8_t*)data;// arrgghhh this converts the two 32bit array into bytes. See comments are useful:)

uint8_t temp1 = bytes[6];
uint16_t temp2 = bytes[4]|((bytes[3] &0x0F)<<8);

temp2 = temp2; //remove warning for unused variable

HvVolt = bytes[2]; //tbc scaling

Param::SetFloat(Param::tmpheater, temp1*0.75); //temp 1 appears to be scaled by 0.75C/1


Param::SetInt(Param::udcheater,HvVolt);

}
84 changes: 84 additions & 0 deletions src/VWAirHeater.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* This file is part of the Zombieverter VCU project.
*
* Copyright (C) 2024 Tom de Bree <[email protected]>
* Copyright (C) 2018 Johannes Huebner <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
* Controls the VW LIN based heater as : https://openinverter.org/wiki/VAG_PTC_Air_Heater
*
* Based on reverse engineer work by Tom de Bree
*
*/

#include <VWAirHeater.h>

static uint8_t processedPower=0;
static uint8_t TenCount=0;


void vwAirHeater::SetLinInterface(LinBus* l)
{
lin = l;
DigIo::lin_wake.Clear();//Not used on TJA1027
DigIo::lin_nslp.Set();//Wakes the device

}

void vwAirHeater::SetPower(uint16_t power, bool HeatReq)
{
TenCount++;
if(TenCount==5)//slow down to 50ms as this is called in 10ms task.
{
TenCount=0;
HeatReq=HeatReq;
//going to ignore heatreq here, already used to determine to run this sequence.

if(power>=255) power = 255;//Constrain power to max for VW heater.
processedPower=power;//10;

static bool read = true;

if (lin->HasReceived(19, 8))//0x13 hex address
{
uint8_t* data = lin->GetReceivedBytes();

Param::SetFloat(Param::tmpheater, data[5]*0.25);//Looks like the temp feedback 1
Param::SetFloat(Param::udcheater, data[1]*2);//HV Voltage feedback
Param::SetFloat(Param::powerheater,data[0]*data[1]);//HV current is Byte 0 in 0.5A per/1 and HV voltage is byte 1 2V/1 so they cancel
}

if (read)
{
lin->Request(19, 0, 0);//0x13 hex address
}

else
{
uint8_t PowReq = Param::GetInt(Param::HeatPercnt);//VW heater uses a % setting as opposed to a set power val. Regulates its temps to this.
uint8_t lindata[8];
lindata[0] = 0x39; //fixed
lindata[1] = 0xC5;//fixed
lindata[2] = PowReq; //Left Request 0-100, tested even at 120 to confirm max values
lindata[3] = PowReq; //Right Request 0-100, tested even at 120 to confirm max values
lindata[4] = 0; //fixed
lindata[5] = 0xAA; //fixed
lindata[6] = 0x78; //Power Limit? 0x50 and 0x78 tested
lindata[7] = 0; //fixed
lin->Request(38, lindata, sizeof(lindata));//0x26 hex address
}

read = !read;
}
}
6 changes: 3 additions & 3 deletions src/VWheater.cpp → src/VWCoolantHeater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
* Observed data with heater running approx 4kw : 0x32, 0xFC, 0x80, 0x80, 0x8D, 0x5D, 0x7A, 0x77
*/

#include <VWheater.h>
#include <VWCoolantHeater.h>

static uint8_t processedPower=0;
static uint8_t TenCount=0;


void vwHeater::SetLinInterface(LinBus* l)
void vwCoolantHeater::SetLinInterface(LinBus* l)
{
lin = l;
DigIo::lin_wake.Clear();//Not used on TJA1027
Expand All @@ -42,7 +42,7 @@

}

void vwHeater::SetPower(uint16_t power, bool HeatReq)
void vwCoolantHeater::SetPower(uint16_t power, bool HeatReq)
{
TenCount++;
if(TenCount==5)//slow down to 50ms as this is called in 10ms task.
Expand Down
Loading

0 comments on commit 3cfe40c

Please sign in to comment.