V1.11
This commit is contained in:
parent
aea84c620b
commit
7b4fc940d3
@ -17,6 +17,8 @@ void can_init(CAN_HandleTypeDef* hcan);
|
|||||||
|
|
||||||
void can_handle_send_status();
|
void can_handle_send_status();
|
||||||
|
|
||||||
|
void can_handle_dump();
|
||||||
|
|
||||||
void can_handle_recieve_command(const uint8_t *data);
|
void can_handle_recieve_command(const uint8_t *data);
|
||||||
|
|
||||||
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data);
|
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data);
|
||||||
|
@ -15,7 +15,7 @@ void eeprom_init(I2C_HandleTypeDef* hi2c);
|
|||||||
void eeprom_dump_status();
|
void eeprom_dump_status();
|
||||||
void eeprom_write_status();
|
void eeprom_write_status();
|
||||||
|
|
||||||
HAL_StatusTypeDef eeprom_read(uint8_t* data, uint16_t address);
|
HAL_StatusTypeDef eeprom_read(uint8_t* data, uint16_t data_length);
|
||||||
HAL_StatusTypeDef eeprom_write(uint8_t* data, uint16_t address);
|
HAL_StatusTypeDef eeprom_write(uint8_t* data, uint16_t data_length);
|
||||||
|
|
||||||
#endif // INC_EEPROM_H_
|
#endif // INC_EEPROM_H_
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "ADBMS_LL_Driver.h"
|
#include "ADBMS_LL_Driver.h"
|
||||||
#include <AMS_HighLevel.h>
|
#include <AMS_HighLevel.h>
|
||||||
|
#include <eeprom.h>
|
||||||
#include <errors.h>
|
#include <errors.h>
|
||||||
#include <PWM_control.h>
|
#include <PWM_control.h>
|
||||||
#include <status_LED.h>
|
#include <status_LED.h>
|
||||||
@ -64,6 +65,7 @@ void sm_precharge_discharge_manager();
|
|||||||
void sm_powerground_manager();
|
void sm_powerground_manager();
|
||||||
void sm_calibrate_powerground();
|
void sm_calibrate_powerground();
|
||||||
void sm_balancing();
|
void sm_balancing();
|
||||||
|
void sm_eeprom_write_status();
|
||||||
|
|
||||||
void sm_check_errors();
|
void sm_check_errors();
|
||||||
void sm_set_error_source();
|
void sm_set_error_source();
|
||||||
|
@ -7,11 +7,14 @@
|
|||||||
|
|
||||||
#include "can.h"
|
#include "can.h"
|
||||||
#include "PWM_control.h"
|
#include "PWM_control.h"
|
||||||
|
#include "can-halal.h"
|
||||||
|
#include "eeprom.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define CAN_ID_IN 0x501
|
#define CAN_ID_IN 0x501
|
||||||
#define CAN_ID_OUT 0x502
|
#define CAN_ID_OUT 0x502
|
||||||
#define CAN_STATUS_FREQ 100
|
#define CAN_STATUS_FREQ 100
|
||||||
|
#define CAN_DUMP_FREQ 10;
|
||||||
|
|
||||||
uint8_t last_message[8];
|
uint8_t last_message[8];
|
||||||
static uint32_t can_delay_manager = 0;
|
static uint32_t can_delay_manager = 0;
|
||||||
@ -86,43 +89,8 @@ void can_handle_send_status() {
|
|||||||
//data[7] = (module.cellVoltages[7]);
|
//data[7] = (module.cellVoltages[7]);
|
||||||
//data[7] = state.error_source;
|
//data[7] = state.error_source;
|
||||||
ftcan_transmit(CAN_ID_OUT, data, sizeof(data));
|
ftcan_transmit(CAN_ID_OUT, data, sizeof(data));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
int8_t id_lowest_temp = -1;
|
|
||||||
int16_t lowest_temp = INT16_MIN;
|
|
||||||
for (int i = 0; i < N_TEMP_SENSORS; i++) {
|
|
||||||
if (tmp1075_temps[i] < lowest_temp){
|
|
||||||
id_lowest_temp = i;
|
|
||||||
lowest_temp = tmp1075_temps[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int8_t id_lowest_volt = -1;
|
|
||||||
int16_t lowest_volt = INT16_MIN;
|
|
||||||
int8_t id_highest_volt = -1;
|
|
||||||
int16_t highest_volt = INT16_MIN;
|
|
||||||
|
|
||||||
for (int i = 0; i < module.sumOfCellMeasurements; i++) {
|
|
||||||
if (sm_return_cell_voltage(i) < lowest_temp){
|
|
||||||
id_lowest_volt = i;
|
|
||||||
lowest_volt = sm_return_cell_voltage(i);
|
|
||||||
}
|
|
||||||
if (sm_return_cell_voltage(i) > highest_temp){
|
|
||||||
id_highest_volt = i;
|
|
||||||
highest_volt = sm_return_cell_voltage(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data[0] = ((id_highest_temp & 0x0F) << 4 | (id_lowest_temp & 0x0F));
|
|
||||||
data[1] = ((lowest_temp) >> 8);
|
|
||||||
data[2] = ((lowest_temp & 0x00F0) | (id_lowest_volt & 0x0F));
|
|
||||||
data[3] = (lowest_volt >> 8);
|
|
||||||
data[4] = ((lowest_volt & 0x00F0) | (id_highest_volt & 0x0F));
|
|
||||||
data[5] = ((highest_volt >> 8));
|
|
||||||
data[6] = ((highest_volt & 0x00F0));
|
|
||||||
data[7] = 0;
|
|
||||||
|
|
||||||
ftcan_transmit(CAN_ID_OUT, data, sizeof(data));
|
|
||||||
|
|
||||||
021E 30
|
021E 30
|
||||||
0232 50
|
0232 50
|
||||||
0238 60
|
0238 60
|
||||||
@ -165,6 +133,21 @@ void can_handle_recieve_command(const uint8_t *data){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void can_handle_dump() {
|
||||||
|
while (1){
|
||||||
|
uint8_t* data;
|
||||||
|
if (can_delay_manager > HAL_GetTick())
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
can_delay_manager = HAL_GetTick() + CAN_STATUS_FREQ;
|
||||||
|
eeprom_read(data, 64);
|
||||||
|
for (int i = 0; i < 63; i += 8) {
|
||||||
|
ftcan_transmit(CAN_ID_OUT, data[i], 8);
|
||||||
|
}
|
||||||
|
ftcan_transmit(CAN_ID_OUT, 0, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
implements the _weak method ftcan_msg_recieved_cb() which throws an interrupt when a CAN message is recieved.
|
implements the _weak method ftcan_msg_recieved_cb() which throws an interrupt when a CAN message is recieved.
|
||||||
it only checks if the id is and datalen is correct thans hands data over to can_handle_recieve_command().
|
it only checks if the id is and datalen is correct thans hands data over to can_handle_recieve_command().
|
||||||
|
@ -5,23 +5,24 @@
|
|||||||
* Author: Hamza
|
* Author: Hamza
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "ADBMS_LL_Driver.h"
|
||||||
#include "TMP1075.h"
|
#include "TMP1075.h"
|
||||||
|
#include "stm32f3xx_hal_def.h"
|
||||||
#include <eeprom.h>
|
#include <eeprom.h>
|
||||||
|
|
||||||
// see Datasheet for these values
|
// see Datasheet for these values
|
||||||
#define EEPROM_I2C_ADDR 0xA0
|
#define EEPROM_I2C_ADDR 0xA4 // 0xA4 for the the first 2⁸ addresses and 0xA6 for the the last 2⁸ addresses
|
||||||
#define EEPROM_WRITE_FREQ_INACTIVE 1000
|
#define EERROM_MEMORY_ADDR_SIZE 2 // it is controlled by A17 in the address Byte, see datasheet
|
||||||
#define EEPROM_WRITE_FREQ_ACTIVE 100
|
#define EEPROM_MEMORY_SIZE 131072 // in bytes
|
||||||
#define EERROM_MEMORY_ADDR_SIZE 2
|
#define EEPROM_PAGE_SIZE 32 // in bytes
|
||||||
#define EEPROM_MEMORY_SIZE 1024000 // in bits
|
|
||||||
#define EEPROM_PAGE_SIZE 256 // in bits
|
|
||||||
|
|
||||||
static I2C_HandleTypeDef* hi2c;
|
static I2C_HandleTypeDef* hi2c;
|
||||||
uint32_t current_address;
|
uint32_t write_address, read_address;
|
||||||
|
|
||||||
void eeprom_init(I2C_HandleTypeDef* handle) {
|
void eeprom_init(I2C_HandleTypeDef* handle) {
|
||||||
hi2c = handle;
|
hi2c = handle;
|
||||||
current_address = 0;
|
write_address = 0;
|
||||||
|
read_address = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void eeprom_write_status(){
|
void eeprom_write_status(){
|
||||||
@ -40,39 +41,57 @@ void eeprom_write_status(){
|
|||||||
data[9] = (CURRENT_MEASUREMENT);
|
data[9] = (CURRENT_MEASUREMENT);
|
||||||
|
|
||||||
// data 10-35
|
// data 10-35
|
||||||
for (int i = 10; i < 36; i+=2) {
|
for (int i = 10; i < 36; i += 2) {
|
||||||
data[i] = ((int) module.auxVoltages[i]) >> 8;
|
data[i] = ((int) module.auxVoltages[i]) >> 8;
|
||||||
data[i+1] = ((int) module.auxVoltages[i]);
|
data[i+1] = ((int) module.auxVoltages[i+1]);
|
||||||
}
|
}
|
||||||
for (int i = 37; i < 50; i++) {
|
for (int i = 37; i < 63; i += 2) {
|
||||||
data[i] = tmp1075_temps[i];
|
data[i] = (tmp1075_temps[i]) >> 8;
|
||||||
|
data[i+1] = (tmp1075_temps[i+1]);
|
||||||
}
|
}
|
||||||
eeprom_write(data, current_address);
|
eeprom_write(data, 64);
|
||||||
current_address++;
|
write_address++;
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_StatusTypeDef eeprom_read(uint8_t* data, uint16_t address){
|
HAL_StatusTypeDef eeprom_read(uint8_t* data, uint16_t data_length){
|
||||||
HAL_StatusTypeDef status = HAL_I2C_Mem_Read(
|
|
||||||
hi2c, EEPROM_I2C_ADDR, address,
|
|
||||||
2, data, sizeof(data), 50);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
HAL_StatusTypeDef eeprom_write(uint8_t* data, uint16_t address){
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
HAL_GPIO_WritePin(EEPROM___WC__GPIO_Port, EEPROM___WC__Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(EEPROM___WC__GPIO_Port, EEPROM___WC__Pin, GPIO_PIN_RESET);
|
||||||
if (address < 65535){
|
for (size_t i = 0; i < data_length; i++) {
|
||||||
status = HAL_I2C_Mem_Write(
|
if (read_address <= 65535){
|
||||||
hi2c, EEPROM_I2C_ADDR,
|
|
||||||
current_address, EERROM_MEMORY_ADDR_SIZE,
|
|
||||||
data, sizeof(data), 50);
|
|
||||||
current_address += sizeof(data);
|
|
||||||
} else if (address > 65535) {
|
|
||||||
status = HAL_I2C_Mem_Write(
|
status = HAL_I2C_Mem_Write(
|
||||||
hi2c, EEPROM_I2C_ADDR,
|
hi2c, EEPROM_I2C_ADDR,
|
||||||
current_address, EERROM_MEMORY_ADDR_SIZE,
|
read_address, EERROM_MEMORY_ADDR_SIZE,
|
||||||
data, sizeof(data), 50);
|
&data[i], 1, 10);
|
||||||
current_address += sizeof(data);
|
|
||||||
|
} else if (read_address > 65535) {
|
||||||
|
status = HAL_I2C_Mem_Write(
|
||||||
|
hi2c, EEPROM_I2C_ADDR + 2,
|
||||||
|
read_address, EERROM_MEMORY_ADDR_SIZE,
|
||||||
|
&data[i], 1, 10);
|
||||||
|
}
|
||||||
|
read_address++;
|
||||||
|
}
|
||||||
|
HAL_GPIO_WritePin(EEPROM___WC__GPIO_Port, EEPROM___WC__Pin, GPIO_PIN_SET);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
HAL_StatusTypeDef eeprom_write(uint8_t* data, uint16_t data_length){
|
||||||
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
|
HAL_GPIO_WritePin(EEPROM___WC__GPIO_Port, EEPROM___WC__Pin, GPIO_PIN_RESET);
|
||||||
|
for (size_t i = 0; i < data_length; i++) {
|
||||||
|
if (write_address < 65535){
|
||||||
|
status = HAL_I2C_Mem_Write(
|
||||||
|
hi2c, EEPROM_I2C_ADDR,
|
||||||
|
write_address, EERROM_MEMORY_ADDR_SIZE,
|
||||||
|
&data[i], 1, 10);
|
||||||
|
|
||||||
|
} else if (write_address > 65535) {
|
||||||
|
status = HAL_I2C_Mem_Write(
|
||||||
|
hi2c, EEPROM_I2C_ADDR + 2,
|
||||||
|
write_address, EERROM_MEMORY_ADDR_SIZE,
|
||||||
|
&data[i], 1, 10);
|
||||||
|
}
|
||||||
|
write_address++;
|
||||||
}
|
}
|
||||||
HAL_GPIO_WritePin(EEPROM___WC__GPIO_Port, EEPROM___WC__Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(EEPROM___WC__GPIO_Port, EEPROM___WC__Pin, GPIO_PIN_SET);
|
||||||
return status;
|
return status;
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
#include "state_machine.h"
|
#include "state_machine.h"
|
||||||
#include "PWM_control.h"
|
#include "PWM_control.h"
|
||||||
|
#include "eeprom.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
// Time to wait after reaching 95% of battery voltage before exiting precharge
|
// Time to wait after reaching 95% of battery voltage before exiting precharge
|
||||||
// Set this to 1000 in scruti to demonstrate the voltage on the multimeter
|
// Set this to 1000 in scruti to demonstrate the voltage on the multimeter
|
||||||
@ -18,7 +21,10 @@
|
|||||||
// Time to wait between closing relays
|
// Time to wait between closing relays
|
||||||
#define RELAY_CLOSE_WAIT 10 // ms
|
#define RELAY_CLOSE_WAIT 10 // ms
|
||||||
// Max time to wait for CAN messages. If we reach it then we emergency shutdown.
|
// Max time to wait for CAN messages. If we reach it then we emergency shutdown.
|
||||||
#define CAN_TIMEOUT 100000
|
#define CAN_TIMEOUT 1000
|
||||||
|
// waiting time between to eeprom writes
|
||||||
|
#define EEPROM_WRITE_FREQ_INACTIVE 10000
|
||||||
|
#define EEPROM_WRITE_FREQ_ACTIVE 1000
|
||||||
|
|
||||||
StateHandle state;
|
StateHandle state;
|
||||||
int32_t RELAY_BAT_SIDE_VOLTAGE;
|
int32_t RELAY_BAT_SIDE_VOLTAGE;
|
||||||
@ -30,6 +36,7 @@ float base_offset = 0;
|
|||||||
uint32_t precharge_timer;
|
uint32_t precharge_timer;
|
||||||
uint32_t discharge_timer;
|
uint32_t discharge_timer;
|
||||||
uint32_t CAN_timer;
|
uint32_t CAN_timer;
|
||||||
|
uint32_t EEPROM_timer;
|
||||||
|
|
||||||
uint32_t powerground_softstart_timer;
|
uint32_t powerground_softstart_timer;
|
||||||
uint32_t powerground_calibration_timer;
|
uint32_t powerground_calibration_timer;
|
||||||
@ -54,8 +61,8 @@ void sm_update(){
|
|||||||
sm_precharge_discharge_manager();
|
sm_precharge_discharge_manager();
|
||||||
sm_calibrate_powerground();
|
sm_calibrate_powerground();
|
||||||
sm_powerground_manager();
|
sm_powerground_manager();
|
||||||
//if (CAN_timer < HAL_GetTick())
|
if (CAN_timer < HAL_GetTick())
|
||||||
// state.current_state = state.target_state = STATE_ERROR;
|
state.current_state = state.target_state = STATE_ERROR;
|
||||||
|
|
||||||
if (state.current_state == STATE_INACTIVE || state.current_state == STATE_ERROR){
|
if (state.current_state == STATE_INACTIVE || state.current_state == STATE_ERROR){
|
||||||
CURRENT_MEASUREMENT = (module.auxVoltages[0] > 2494) ? (module.auxVoltages[0] - (2494.0)) * (300.0) : 0;
|
CURRENT_MEASUREMENT = (module.auxVoltages[0] > 2494) ? (module.auxVoltages[0] - (2494.0)) * (300.0) : 0;
|
||||||
@ -214,6 +221,21 @@ void sm_calibrate_powerground(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sm_program_powerground(){
|
||||||
|
powerground_calibration_timer = HAL_GetTick() + 5000;
|
||||||
|
while (powerground_calibration_timer > HAL_GetTick()){}
|
||||||
|
state.current_state = STATE_PRECHARGE;
|
||||||
|
sm_update();
|
||||||
|
|
||||||
|
powerground_calibration_timer = HAL_GetTick() + PRECHARGE_DURATION + 1000;
|
||||||
|
PWM_powerground_control(100);
|
||||||
|
while (powerground_calibration_timer > HAL_GetTick()){}
|
||||||
|
sm_update();
|
||||||
|
while (1) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void sm_balancing(){
|
void sm_balancing(){
|
||||||
for (int i = 0; i < 13; i++) {
|
for (int i = 0; i < 13; i++) {
|
||||||
amsConfigBalancing((1 << i), 0xF);
|
amsConfigBalancing((1 << i), 0xF);
|
||||||
@ -221,6 +243,14 @@ void sm_balancing(){
|
|||||||
amsStartBalancing(0);
|
amsStartBalancing(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sm_eeprom_write_status(){
|
||||||
|
if (EEPROM_timer < HAL_GetTick()){
|
||||||
|
eeprom_write_status();
|
||||||
|
EEPROM_timer = HAL_GetTick() + EEPROM_WRITE_FREQ_INACTIVE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#warning TODO: add error checking for everything here
|
#warning TODO: add error checking for everything here
|
||||||
void sm_check_errors(){
|
void sm_check_errors(){
|
||||||
state.error_type.temperature_error = (error_data.error_sources & (1 << 0) || error_data.error_sources & (1 << 1) || error_data.error_sources & (1 << 4)) ? 1 : 0;
|
state.error_type.temperature_error = (error_data.error_sources & (1 << 0) || error_data.error_sources & (1 << 1) || error_data.error_sources & (1 << 4)) ? 1 : 0;
|
||||||
|
BIN
Documentation/AT 115A 14S.jpg
Normal file
BIN
Documentation/AT 115A 14S.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 MiB |
3220
Documentation/AT 195A 14S.pdf
Normal file
3220
Documentation/AT 195A 14S.pdf
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user