Skip to content

Commit

Permalink
0.14
Browse files Browse the repository at this point in the history
-Added a new parameter canRxRefreshActive, which allows to extend the activeTimer up to a point by received CAN-frames
-Fixed a bug that would terminate the start of charging prematurely and cause the state machine to bounce between starting charging and ending charging
-Internal change to how runtimePars.activeTick and runtimePars.storageTick were incremented and monitored
  • Loading branch information
SimosMCmuffin committed Nov 26, 2020
1 parent b6fe459 commit a8632de
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
1 change: 1 addition & 0 deletions Inc/USB_comms_handler_MD.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ typedef enum
canID,

duringActive5vOn,
canRxRefreshActive,

numberOfElements
}_parameter_ID;
Expand Down
2 changes: 1 addition & 1 deletion Inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define HW_NAME "FlexiBMSlite"

#define FW_VERSION_MAJOR 0
#define FW_VERSION_MINOR 13
#define FW_VERSION_MINOR 14

#define STM32_UUID_8 ((uint8_t*)0x1FFF7590)

Expand Down
3 changes: 2 additions & 1 deletion Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ typedef struct _generalParameters {
uint16_t timeToStorageDischarge; //h (hours), how long to wait after active state to start discharging cells to storage voltage

uint8_t canActivityTick; //1 or 0, ticks the status led in magenta when can packets are received
uint8_t canID; //canID that the BMS uses to recognize as itself
uint8_t canID; //canID that the BMS uses to recognize as itself
uint16_t canRxRefreshActive; //h (hours),Receiving CAN messages refresh activeTimer up to this length, 0 to disable
} generalParameters;

typedef struct _nonVolParameters {
Expand Down
17 changes: 8 additions & 9 deletions Src/AuxFunctions.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void initNonVolatiles(nonVolParameters* nonVols, uint8_t loadDefaults){
nonVols->chgParas.refreshWaitTime = 30;
nonVols->genParas.canActivityTick = 0;
nonVols->genParas.canID = CAN_ID;
nonVols->genParas.canRxRefreshActive = 0;

}

Expand Down Expand Up @@ -94,8 +95,8 @@ void initRuntimeParameters(runtimeParameters* runtimePars){
runtimePars->storageDischarged = 1;
runtimePars->storageTimerState = 1;

runtimePars->activeTick = HAL_GetTick();
runtimePars->storageTick = HAL_GetTick();
runtimePars->activeTick = HAL_GetTick() + ( nonVolPars.genParas.stayActiveTime * __TIME_HOUR_TICKS ) ;
runtimePars->storageTick = HAL_GetTick() + ( nonVolPars.genParas.timeToStorageDischarge * __TIME_HOUR_TICKS );
}

uint8_t countCells(void){ //Count how many cells are above
Expand Down Expand Up @@ -175,7 +176,7 @@ void chargeControl(void){
chargeTick = HAL_GetTick() + 250;
}
}
else{
else if( runtimePars.chargerConnected == 0 && runtimePars.chargingState != charging ){
runtimePars.chargingState = notCharging;
runtimePars.buck5vRequest &= ~(1 << charging5vRequest);
}
Expand Down Expand Up @@ -590,11 +591,10 @@ void updateActiveTimer(void){

if( runtimePars.usbConnected == 1 || runtimePars.charging == 1 || runtimePars.balancing == 1 ||
runtimePars.optoActive == 1 || runtimePars.chargerConnected == 1 ){
runtimePars.activeTick = HAL_GetTick() + 500;
runtimePars.activeTick = HAL_GetTick() + ( nonVolPars.genParas.stayActiveTime * __TIME_HOUR_TICKS ) + 500;
}

if( (runtimePars.activeTick + ( nonVolPars.genParas.stayActiveTime * __TIME_HOUR_TICKS )) <= HAL_GetTick() &&
runtimePars.storageDischarged == 1 ){
if( runtimePars.activeTick <= HAL_GetTick() && runtimePars.storageDischarged == 1 ){
runtimePars.activeTimerState = 0; //active time window passed

if( nonVolPars.genParas.duringActive5vOn == 1 ){ //if duringActive5vOn enabled, clear 5V request
Expand All @@ -613,11 +613,10 @@ void updateActiveTimer(void){
void updateStorageTimer(void){

if( runtimePars.chargerConnected == 1 ){
runtimePars.storageTick = HAL_GetTick();
runtimePars.storageTick = HAL_GetTick() + ( nonVolPars.genParas.timeToStorageDischarge * __TIME_HOUR_TICKS );
}

if( ((runtimePars.storageTick + ( nonVolPars.genParas.timeToStorageDischarge * __TIME_HOUR_TICKS )) <= HAL_GetTick()) &&
nonVolPars.genParas.timeToStorageDischarge != 0 ){
if( runtimePars.storageTick <= HAL_GetTick() && nonVolPars.genParas.timeToStorageDischarge != 0 ){
if( runtimePars.storageTimerState == 1 ){
runtimePars.storageTimerState = 0; //storage time window passed
runtimePars.storageDischarged = 0; //clear storageDischarge state when starting storagedischarging
Expand Down
12 changes: 10 additions & 2 deletions Src/CAN_LL.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static uint8_t queueIndex = 0, txIndex = 0, ISR_running = 0;
static unsigned int rx_buffer_last_id;

extern nonVolParameters nonVolPars;
extern runtimeParameters runtimePars;

void CAN1_init(){

Expand Down Expand Up @@ -69,9 +70,9 @@ void CAN1_init(){

void CAN1_deInit(){

if( CAN_initialized == 1){ //check that CAN is initialized
if( CAN_initialized == 1 ){ //check that CAN is initialized
CAN1->MCR |= (1 << 1); //request to enter sleep mode
while( !!(CAN1->MSR & (1 << 1)) == 0 ); //wait for bus activity to finish/stop and enter sleep mode
while( !!(CAN1->MSR & (1 << 1)) == 0 || ISR_running == 1 ); //wait for bus activity to finish/stop and enter sleep mode
RCC->APB1ENR1 &= ~(1 << 25); //Disable CAN1 bus clock

GPIOB->MODER &= ~( (3 << 16) | (3 << 18) ); //Configure pins PB8 and PB9 to analog state for low-power usage
Expand Down Expand Up @@ -460,6 +461,13 @@ void CAN1_RX0_IRQHandler(void){
if( !!(CAN1->RF0R & (3 << 0)) == 1 ){ //RX mailbox 0 not empty

CAN1_process_message();

//CAN RX activeTimer refresh
if( nonVolPars.genParas.canRxRefreshActive != 0 ){ //check if parameter is enabled, before going into a bigger if-statement
if( (runtimePars.activeTick - (nonVolPars.genParas.canRxRefreshActive * __TIME_HOUR_TICKS)) <= HAL_GetTick() ){
runtimePars.activeTick = HAL_GetTick() + (nonVolPars.genParas.canRxRefreshActive * __TIME_HOUR_TICKS);
}
}
}

}
8 changes: 8 additions & 0 deletions Src/USB_comms_handler_MD.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ void set_parameter(float* value, _parameter_ID parameterID){
case duringActive5vOn:
nonVolPars.genParas.duringActive5vOn = (uint8_t)*value;
break;
case canRxRefreshActive:
nonVolPars.genParas.canRxRefreshActive = (uint16_t)*value;
break;
default:
report_error(error_invalidMessageID);
break;
Expand Down Expand Up @@ -720,6 +723,11 @@ void appendParameter(uint8_t* text, uint16_t indexNo, uint16_t* pos){
static const uint8_t description39[] = {" (0/1, if set to 1, keeps 5V regulator on even if USB, charger or Opto not active, Boolean)\r\n"};
appendString(text, description39, pos);
break;
case canRxRefreshActive:
appendUint16(text, nonVolPars.genParas.canRxRefreshActive, pos);
static const uint8_t description40[] = {" (h (Hours), up to how many hours a CAN-frame reception can extend activeTimer, set to 0 to disable, uint16_t)\r\n"};
appendString(text, description40, pos);
break;
default:;
static const uint8_t description33[] = {" (parameter error)\r\n"};
appendString(text, description33, pos);
Expand Down
2 changes: 1 addition & 1 deletion Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main(void)
trimOscillator();

uint64_t systemTick = HAL_GetTick(), LTC6803tick = HAL_GetTick();
runtimePars.activeTick = HAL_GetTick() + 5000;
runtimePars.activeTick = HAL_GetTick() + ( nonVolPars.genParas.stayActiveTime * __TIME_HOUR_TICKS ) + 5000;


while (1)
Expand Down

0 comments on commit a8632de

Please sign in to comment.