Skip to content

Commit

Permalink
Merge pull request #30 from dalathegreat/bugfix/ze0-startup-gids
Browse files Browse the repository at this point in the history
Bugfix: Incorrect scaling of instrumentation cluster on ZE0
  • Loading branch information
dalathegreat authored Jun 6, 2024
2 parents 0da07ae + c7d0402 commit 93b2d94
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 8 deletions.
41 changes: 36 additions & 5 deletions Software/CANBRIDGE-2port/source/Src/can-bridge-firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static volatile uint8_t skip_5bc = 1; // for 2011 battery swap, skip
static volatile uint8_t alternate_5bc = 0; // for 2011 battery swap
static volatile uint8_t seen_1da = 0; // for 2011 battery swap
static volatile uint8_t seconds_without_1f2 = 0; // bugfix: 0x603/69C/etc. isn't sent upon charge start on the gen1 Leaf, so we need to trigger our reset on a simple absence of messages

static volatile uint16_t startup_counter_1DB = 0;
// bits 10 10 4 8 7 1 3 (2 space) 1 5 13
static Leaf_2011_5BC_message swap_5bc_remaining = {.LB_CAPR = 0x12C, .LB_FULLCAP = 0x32, .LB_CAPSEG = 0, .LB_AVET = 50, .LB_SOH = 99, .LB_CAPSW = 0, .LB_RLIMIT = 0, .LB_CAPBALCOMP = 1, .LB_RCHGTCON = 0x09, .LB_RCHGTIM = 0};
static Leaf_2011_5BC_message swap_5bc_full = {.LB_CAPR = 0x12C, .LB_FULLCAP = 0x32, .LB_CAPSEG = 12, .LB_AVET = 50, .LB_SOH = 99, .LB_CAPSW = 1, .LB_RLIMIT = 0, .LB_CAPBALCOMP = 1, .LB_RCHGTCON = 0x09, .LB_RCHGTIM = 0};
Expand Down Expand Up @@ -253,9 +253,17 @@ void can_handler(uint8_t can_bus, CAN_FRAME *frame)
if (VCM_WakeUpSleepCommand == 3)
{ // VCM command: wakeup
frame->data[3] = (frame->data[3] & 0xD7) | 0x28; // FRLYON=1, INTERLOCK=1
}

}
}
if (startup_counter_1DB >= 100 && startup_counter_1DB <= 300) // Between 1s and 3s after poweron
{
frame->data[3] = (frame->data[3] | 0x10); // Set the full charge flag to ON during startup
} // This is to avoid instrumentation cluster scaling bars incorrectly
if(startup_counter_1DB < 1000)
{
startup_counter_1DB++;
}

}

if( My_Leaf == MY_LEAF_2014 )
{
Expand Down Expand Up @@ -416,6 +424,29 @@ void can_handler(uint8_t can_bus, CAN_FRAME *frame)
swap_5bc_remaining.LB_RCHGTIM = 0;
swap_5bc_remaining.LB_RCHGTCON = 0;
}

if(startup_counter_1DB < 600) // During the first 6s of bootup, write GIDS to the max value for the pack
{
switch (My_Battery)
{
case MY_BATTERY_24KWH:
swap_5bc_remaining.LB_CAPR = 220;
swap_5bc_full.LB_CAPR = 220;
break;
case MY_BATTERY_30KWH:
swap_5bc_remaining.LB_CAPR = 310;
swap_5bc_full.LB_CAPR = 310;
break;
case MY_BATTERY_40KWH:
swap_5bc_remaining.LB_CAPR = 420;
swap_5bc_full.LB_CAPR = 420;
break;
case MY_BATTERY_62KWH:
swap_5bc_remaining.LB_CAPR = 630;
swap_5bc_full.LB_CAPR = 630;
break;
}
}

skip_5bc--;

Expand Down Expand Up @@ -704,7 +735,7 @@ void can_handler(uint8_t can_bus, CAN_FRAME *frame)
case 0x68C:
case 0x603:
reset_state(); // Reset all states, vehicle is starting up

startup_counter_1DB = 0;
PushCan(battery_can_bus, CAN_TX, &swap_605_message); // Send these ZE1 messages towards battery
PushCan(battery_can_bus, CAN_TX, &swap_607_message);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ volatile uint8_t seen_1da = 0; //for 2011 battery swap
volatile uint8_t seconds_without_1f2 = 0; //bugfix: 0x603/69C/etc. isn't sent upon charge start on the gen1 Leaf, so we need to trigger our reset on a simple absence of messages
volatile uint8_t main_battery_temp = 0;
volatile uint8_t battery_can_bus = 2; //keeps track on which CAN bus the battery talks.

volatile uint16_t startup_counter_1DB = 0;
//timer variables
volatile uint16_t sec_timer = 1; //actually the same as ms_timer but counts down from 1000

Expand Down Expand Up @@ -348,7 +348,14 @@ void can_handler(uint8_t can_bus){
{ // VCM command: wakeup
frame.data[3] = (frame.data[3] & 0xD7) | 0x28; // FRLYON=1, INTERLOCK=1
}

if (startup_counter_1DB >= 100 && startup_counter_1DB <= 300) // Between 1s and 3s after poweron
{
frame.data[3] = (frame.data[3] | 0x10); // Set the full charge flag to ON during startup
} // This is to avoid instrumentation cluster scaling bars incorrectly
if(startup_counter_1DB < 1000)
{
startup_counter_1DB++;
}
}

if( My_Leaf == MY_LEAF_2014 )
Expand Down Expand Up @@ -523,6 +530,29 @@ void can_handler(uint8_t can_bus){
swap_5bc_remaining.LB_RCHGTIM = 0;
swap_5bc_remaining.LB_RCHGTCON = 0;
}

if(startup_counter_1DB < 600) // During the first 6s of bootup, write GIDS to the max value for the pack
{
switch (My_Battery)
{
case MY_BATTERY_24KWH:
swap_5bc_remaining.LB_CAPR = 220;
swap_5bc_full.LB_CAPR = 220;
break;
case MY_BATTERY_30KWH:
swap_5bc_remaining.LB_CAPR = 310;
swap_5bc_full.LB_CAPR = 310;
break;
case MY_BATTERY_40KWH:
swap_5bc_remaining.LB_CAPR = 420;
swap_5bc_full.LB_CAPR = 420;
break;
case MY_BATTERY_62KWH:
swap_5bc_remaining.LB_CAPR = 630;
swap_5bc_full.LB_CAPR = 630;
break;
}
}

skip_5bc--;
if(!skip_5bc){
Expand Down Expand Up @@ -752,7 +782,7 @@ void can_handler(uint8_t can_bus){
case 0x68C:
case 0x603:
reset_state(); // Reset all states, vehicle is starting up

startup_counter_1DB = 0;
send_can(battery_can_bus, swap_605_message); // Send these ZE1 messages towards battery
send_can(battery_can_bus, swap_607_message);
break;
Expand Down

0 comments on commit 93b2d94

Please sign in to comment.