forked from achamaikin/CCSModuleSW30Web
Clamp connector current from InfoBlock connector1CurrentLimitA (v1.0.36).
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "board.h"
|
||||
|
||||
#include "charger_config.h"
|
||||
#include "adc.h"
|
||||
#include "main.h"
|
||||
#include "sma_filter.h"
|
||||
@@ -7,6 +8,37 @@
|
||||
|
||||
InfoBlock_t *InfoBlock = (InfoBlock_t *)(VERSION_OFFSET);
|
||||
|
||||
static uint16_t s_connector_max_current_0p1A = (uint16_t)PSU_MAX_CURRENT * 10u;
|
||||
|
||||
static uint16_t Board_ResolveConnectorCurrentLimitA(uint16_t raw_limit_a)
|
||||
{
|
||||
return (raw_limit_a == 0u) ? (uint16_t)PSU_MAX_CURRENT : raw_limit_a;
|
||||
}
|
||||
|
||||
void Board_LoadInfoBlockLimits(void)
|
||||
{
|
||||
const uint16_t limit_a = Board_ResolveConnectorCurrentLimitA(InfoBlock->connector1CurrentLimitA);
|
||||
uint32_t limit_0p1a = (uint32_t)limit_a * 10u;
|
||||
const uint32_t hw_max_0p1a = (uint32_t)PSU_MAX_CURRENT * 10u;
|
||||
|
||||
if (limit_0p1a > hw_max_0p1a) {
|
||||
limit_0p1a = hw_max_0p1a;
|
||||
}
|
||||
|
||||
s_connector_max_current_0p1A = (uint16_t)limit_0p1a;
|
||||
}
|
||||
|
||||
uint16_t Board_GetConnectorCurrentLimit_0p1A(void)
|
||||
{
|
||||
return s_connector_max_current_0p1A;
|
||||
}
|
||||
|
||||
uint16_t Board_ClampCurrent_0p1A(uint16_t current_0p1A)
|
||||
{
|
||||
const uint16_t limit = Board_GetConnectorCurrentLimit_0p1A();
|
||||
return (current_0p1A > limit) ? limit : current_0p1A;
|
||||
}
|
||||
|
||||
uint8_t RELAY_State[RELAY_COUNT];
|
||||
static volatile uint8_t adc_lock = 0;
|
||||
static SMAFilter_t conn_temp_adc_filter[2];
|
||||
|
||||
@@ -214,8 +214,12 @@ int main(void)
|
||||
SC_Init();
|
||||
log_printf(LOG_INFO, "CCS module start\n");
|
||||
ReadVersion();
|
||||
CCS_UpdateMaxLoadFromInfoBlock();
|
||||
log_printf(LOG_INFO, "Serial number: %d\n", infoPacket.serialNumber);
|
||||
log_printf(LOG_INFO, "Board revision: %d\n", infoPacket.boardVersion);
|
||||
log_printf(LOG_INFO, "Connector current limit: %u.%u A\n",
|
||||
(unsigned)(Board_GetConnectorCurrentLimit_0p1A() / 10u),
|
||||
(unsigned)(Board_GetConnectorCurrentLimit_0p1A() % 10u));
|
||||
log_printf(LOG_INFO, "FW version: %d.%d.%d\n", infoPacket.fw_version_major, infoPacket.fw_version_minor, infoPacket.fw_version_patch);
|
||||
CAN1_MinimalReInit();
|
||||
PSU_Init();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "power_setpoint_executor.h"
|
||||
|
||||
#include "board.h"
|
||||
#include "charger_config.h"
|
||||
#include "charger_control.h"
|
||||
#include "debug.h"
|
||||
@@ -39,6 +40,7 @@ void PowerSetpoint_Init(void)
|
||||
void PowerSetpoint_OnCommand(uint16_t voltage_V, uint16_t current_0p1A)
|
||||
{
|
||||
#if PSD_ENABLE
|
||||
current_0p1A = Board_ClampCurrent_0p1A(current_0p1A);
|
||||
pending.voltage_V = voltage_V;
|
||||
pending.current_0p1A = current_0p1A;
|
||||
setpoint_dirty = 1u;
|
||||
|
||||
+10
-4
@@ -379,9 +379,9 @@ void CCS_SerialLoop(void) {
|
||||
void CCS_Init(void){
|
||||
CP_Init();
|
||||
CP_SetDuty(100);
|
||||
CCS_MaxLoad.maxVoltage = PSU_MAX_VOLTAGE; // 1000V
|
||||
CCS_MaxLoad.maxVoltage = PSU_MAX_VOLTAGE; // 1000V
|
||||
CCS_MaxLoad.minVoltage = PSU_MIN_VOLTAGE; //150V
|
||||
CCS_MaxLoad.maxCurrent = PSU_MAX_CURRENT*10; //100A
|
||||
CCS_MaxLoad.maxCurrent = Board_GetConnectorCurrentLimit_0p1A();
|
||||
CCS_MaxLoad.minCurrent = PSU_MIN_CURRENT*10; //1A
|
||||
CCS_MaxLoad.maxPower = PSU_MAX_POWER; //30000W
|
||||
uart3_last_packet_tick = HAL_GetTick();
|
||||
@@ -391,6 +391,11 @@ void CCS_Init(void){
|
||||
log_printf(LOG_INFO, "CCS init\n");
|
||||
}
|
||||
|
||||
void CCS_UpdateMaxLoadFromInfoBlock(void)
|
||||
{
|
||||
CCS_MaxLoad.maxCurrent = Board_GetConnectorCurrentLimit_0p1A();
|
||||
}
|
||||
|
||||
ISR_FAST static uint16_t crc16_ibm(const uint8_t* data, uint16_t length) {
|
||||
uint16_t crc = 0xFFFFu;
|
||||
for (uint16_t i = 0; i < length; i++) {
|
||||
@@ -549,9 +554,10 @@ ISR_FAST static void apply_command(uint8_t cmd, const uint8_t* payload, uint16_t
|
||||
}
|
||||
case CMD_E2M_SET_OUTPUT_VOLTAGE: {
|
||||
const e2m_set_output_t* p = (const e2m_set_output_t*)payload;
|
||||
const uint16_t clamped_current = Board_ClampCurrent_0p1A(p->current_0p1A);
|
||||
CONN.RequestedVoltage = p->voltage_V;
|
||||
CONN.WantedCurrent = p->current_0p1A;
|
||||
PowerSetpoint_OnCommand(p->voltage_V, p->current_0p1A);
|
||||
CONN.WantedCurrent = clamped_current;
|
||||
PowerSetpoint_OnCommand(p->voltage_V, clamped_current);
|
||||
break;
|
||||
}
|
||||
case CMD_E2M_ISOLATION_CONTROL: {
|
||||
|
||||
@@ -76,6 +76,7 @@ void ReadVersion(){
|
||||
infoPacket.fw_version_major = FW_VERSION_MAJOR;
|
||||
infoPacket.fw_version_minor = FW_VERSION_MINOR;
|
||||
infoPacket.fw_version_patch = FW_VERSION_PATCH;
|
||||
Board_LoadInfoBlockLimits();
|
||||
}
|
||||
|
||||
// Внешняя функция обработки команд (определена в serial_handler.c)
|
||||
|
||||
Reference in New Issue
Block a user