software almost finished, changed documents
This commit is contained in:
@ -29,5 +29,6 @@ typedef struct {
|
||||
void can_init(CAN_HandleTypeDef* hcan);
|
||||
void can_rxupdateFrame();
|
||||
void can_sendloop();
|
||||
void can_error_report();
|
||||
|
||||
#endif /* INC_CAN_COMMUNICATION_H_ */
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
#include "stm32f3xx_hal.h"
|
||||
|
||||
// convert ADC quants to V
|
||||
#define ADC_V_FACTOR (3.3f / 4095) // 3.3V / 12bit
|
||||
#define ADC_V_FACTOR ((3.3f / 4095) * (3.3f / 3.14f)) // 3.3V / 12bit
|
||||
// scale to LV by divider to mV
|
||||
#define LV_SENSE_FACTOR (1e3 * (ADC_V_FACTOR * ((12.f + 1.8f) / 1.8f))) // scaled with voltage divider
|
||||
|
||||
|
||||
@ -12,6 +12,42 @@
|
||||
#include "channel_control.h"
|
||||
#include "can_communication.h"
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t sdc_open : 1;
|
||||
uint8_t noload_acc_cooling : 1;
|
||||
uint8_t noload_ts_cooling : 1;
|
||||
uint8_t noload_drs : 1;
|
||||
uint8_t noload_acu : 1;
|
||||
uint8_t noload_epsc : 1;
|
||||
uint8_t noload_inverter : 1;
|
||||
uint8_t noload_lidar : 1;
|
||||
};
|
||||
uint8_t group1;
|
||||
} err_group1;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t noload_misc : 1;
|
||||
uint8_t noload_alwayson : 1;
|
||||
uint8_t noload_sdc : 1;
|
||||
uint8_t noload_ebs1 : 1;
|
||||
uint8_t noload_ebs2 : 1;
|
||||
uint8_t noload_ebs3 : 1;
|
||||
uint8_t power_critcal : 1;
|
||||
uint8_t power_limit : 1;
|
||||
};
|
||||
uint8_t group2;
|
||||
} err_group2;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
err_group1 group1;
|
||||
err_group2 group2;
|
||||
};
|
||||
uint16_t err_bitmask;
|
||||
} err_states;
|
||||
|
||||
void check_plausibility();
|
||||
|
||||
#endif /* INC_PLAUSIBILITY_CHECK_H_ */
|
||||
|
||||
@ -14,7 +14,7 @@ rx_status_frame rxstate = {};
|
||||
volatile uint8_t canmsg_received = 0;
|
||||
extern enable_gpios update_ports;
|
||||
extern current_measurements current_measurements_adc_val;
|
||||
extern uint8_t error_data[16];
|
||||
extern err_states error;
|
||||
|
||||
|
||||
extern uint32_t lastheartbeat;
|
||||
@ -93,39 +93,10 @@ void can_sendloop(){
|
||||
}
|
||||
|
||||
void can_error_report(){
|
||||
|
||||
static int error_loop = 0;
|
||||
uint8_t data[8];
|
||||
|
||||
switch (error_loop){
|
||||
case 0: // 1 = error 0 = no error
|
||||
data[0] = error_data[0]; // SDC-Status
|
||||
data[1] = error_data[1]; // power draw critical (550W)
|
||||
data[2] = error_data[2]; // power limit (> 600W)
|
||||
data[3] = error_data[3]; // acc-cooling false OFF
|
||||
data[4] = error_data[4]; // ts-cooling false OFF
|
||||
data[5] = error_data[5]; // drs false OFF
|
||||
data[6] = error_data[6]; // acu false OFF
|
||||
data[7] = error_data[7]; // epsc false OFF
|
||||
ftcan_transmit(ERROR_ID, data, 8);
|
||||
break;
|
||||
|
||||
case 1: // 3 = error 2 = no error
|
||||
data[8] = error_data[8]; // inverter false OFF
|
||||
data[9] = error_data[9]; // lidar false OFF
|
||||
data[10] = error_data[10]; // misc false OFF
|
||||
data[11] = error_data[11]; // always on false OFF
|
||||
data[12] = error_data[12]; // sdc false OFF
|
||||
data[13] = error_data[13]; // ebs1 false OFF
|
||||
data[14] = error_data[14]; // ebs2 false OFF
|
||||
data[15] = error_data[15]; // ebs3 false OFF
|
||||
ftcan_transmit(ERROR_ID, data, 8);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
error_loop = (error_loop + 1) % 2;
|
||||
uint8_t error_data[2];
|
||||
error_data[0] = error.group1.group1;
|
||||
error_data[1] = error.group2.group2;
|
||||
ftcan_transmit(ERROR_ID, error_data, 2);
|
||||
}
|
||||
|
||||
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t* data){
|
||||
|
||||
@ -25,7 +25,7 @@ void ChannelControl_init(){
|
||||
|
||||
|
||||
void ChannelControl_UpdateGPIOs(enable_gpios UpdatePorts){
|
||||
UpdatePorts.portb.alwayson = 1;
|
||||
UpdatePorts.portb.alwayson = 1; // ensure always on stays always on
|
||||
if (inhibit_SDC == 1){
|
||||
UpdatePorts.portb.sdc = 0;
|
||||
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, 1);
|
||||
@ -37,11 +37,9 @@ void ChannelControl_UpdateGPIOs(enable_gpios UpdatePorts){
|
||||
|
||||
if (prev_epsc_state == 0 && UpdatePorts.porta.epsc == 1){
|
||||
HAL_GPIO_WritePin(PC_EN_GPIO_Port, PC_EN_Pin, 1); // enable precharge
|
||||
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, 1);
|
||||
if (current_measurements_adc_val.epsc_precharge >= (0.95f * current_measurements_adc_val.asms_v)) { // precharge complete
|
||||
HAL_GPIO_WritePin(IN5_GPIO_Port, IN5_Pin, (GPIO_PinState)UpdatePorts.porta.epsc); // switch PROFET
|
||||
if (current_measurements_adc_val.epsc_precharge >= (0.95f * current_measurements_adc_val.asms_v)) { // check if precharge is complete (no while loop needed, this function is called by the main while-loop)
|
||||
HAL_GPIO_WritePin(IN5_GPIO_Port, IN5_Pin, (GPIO_PinState)UpdatePorts.porta.epsc); // switch on PROFET
|
||||
HAL_GPIO_WritePin(PC_EN_GPIO_Port, PC_EN_Pin, 0); // disengage precharge
|
||||
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, 0);
|
||||
prev_epsc_state = UpdatePorts.porta.epsc;
|
||||
}
|
||||
}
|
||||
@ -54,8 +52,8 @@ void ChannelControl_UpdateGPIOs(enable_gpios UpdatePorts){
|
||||
HAL_GPIO_WritePin(IN6_GPIO_Port, IN6_Pin, (GPIO_PinState)UpdatePorts.porta.inverter); // inverter
|
||||
HAL_GPIO_WritePin(IN7_GPIO_Port, IN7_Pin, (GPIO_PinState)UpdatePorts.porta.lidar); // lidar
|
||||
HAL_GPIO_WritePin(IN8_GPIO_Port, IN8_Pin, (GPIO_PinState)UpdatePorts.porta.misc); // MISC
|
||||
HAL_GPIO_WritePin(IN9_GPIO_Port, IN9_Pin, (GPIO_PinState)UpdatePorts.portb.alwayson); // always on -> standardmäßig auf HIGH forcen
|
||||
HAL_GPIO_WritePin(IN10_GPIO_Port, IN10_Pin, (GPIO_PinState)UpdatePorts.portb.sdc); // SDC -> muss anders controlled werden
|
||||
HAL_GPIO_WritePin(IN9_GPIO_Port, IN9_Pin, (GPIO_PinState)UpdatePorts.portb.alwayson); // always on
|
||||
HAL_GPIO_WritePin(IN10_GPIO_Port, IN10_Pin, (GPIO_PinState)UpdatePorts.portb.sdc); // SDC
|
||||
HAL_GPIO_WritePin(IN11_GPIO_Port, IN11_Pin, (GPIO_PinState)UpdatePorts.portb.ebs1); // EBS 1
|
||||
HAL_GPIO_WritePin(IN12_GPIO_Port, IN12_Pin, (GPIO_PinState)UpdatePorts.portb.ebs2); // EBS 2
|
||||
HAL_GPIO_WritePin(IN13_GPIO_Port, IN13_Pin, (GPIO_PinState)UpdatePorts.portb.ebs3); // EBS 3
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "can_communication.h"
|
||||
#include "channel_control.h"
|
||||
//#include "plausibility_check.h"
|
||||
#include "plausibility_check.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@ -119,6 +119,7 @@ int main(void)
|
||||
MX_UART4_Init();
|
||||
MX_TIM6_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
// begin start-up animation
|
||||
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET);
|
||||
HAL_Delay(100);
|
||||
@ -142,6 +143,7 @@ int main(void)
|
||||
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(LED4_GPIO_Port, LED4_Pin, GPIO_PIN_RESET);
|
||||
// end start-up animation
|
||||
|
||||
HAL_GPIO_WritePin(LED4_GPIO_Port, LED4_Pin, GPIO_PIN_SET); // indicates running STM
|
||||
|
||||
ChannelControl_init();
|
||||
@ -167,8 +169,9 @@ int main(void)
|
||||
}
|
||||
if ((HAL_GetTick() - lasttick) > 100u){
|
||||
lasttick = HAL_GetTick();
|
||||
check_plausibility();
|
||||
can_sendloop();
|
||||
//can_error_report();
|
||||
can_error_report();
|
||||
}
|
||||
if (((HAL_GetTick() - lastheartbeat) > 200U) && (HAL_GetTick() > 1000U)) {
|
||||
inhibit_SDC = 1;
|
||||
@ -176,12 +179,10 @@ int main(void)
|
||||
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, (GPIO_PinState)!update_ports.portb.sdc); // indicates open SDC
|
||||
|
||||
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, (GPIO_PinState)inhibit_SDC); // indicates watchdog-status
|
||||
// overcurrent check (wenn funktioniert, LED schalten)
|
||||
|
||||
ChannelControl_UpdateGPIOs(update_ports);
|
||||
|
||||
current_monitor_checklimits(); // currently not implemented
|
||||
|
||||
//check_plausibility();
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
@ -8,102 +8,103 @@
|
||||
|
||||
extern enable_gpios update_ports;
|
||||
extern current_measurements current_measurements_adc_val;
|
||||
volatile uint8_t error_data[16];
|
||||
volatile err_states error;
|
||||
extern int inhibit_SDC;
|
||||
|
||||
void check_plausibility() {
|
||||
if (!update_ports.portb.sdc) {error_data[0] = 1;}
|
||||
else {error_data[0] = 0;}
|
||||
if (!update_ports.portb.sdc || inhibit_SDC == 1) {error.group1.sdc_open = 1;}
|
||||
else {error.group1.sdc_open = 0;}
|
||||
|
||||
if (update_ports.porta.acc_cooling == 1 && current_measurements_adc_val.acc_cooling == 0) {
|
||||
error_data[3] = 1;
|
||||
error.group1.noload_acc_cooling = 1;
|
||||
}
|
||||
else {
|
||||
error_data[3] = 0;
|
||||
error.group1.noload_acc_cooling = 0;
|
||||
}
|
||||
|
||||
if (update_ports.porta.ts_cooling == 1 && current_measurements_adc_val.ts_cooling == 0) {
|
||||
error_data[4] = 1;
|
||||
}
|
||||
else {
|
||||
error_data[4] = 0;
|
||||
}
|
||||
error.group1.noload_ts_cooling = 1;
|
||||
}
|
||||
else {
|
||||
error.group1.noload_ts_cooling = 0;
|
||||
}
|
||||
|
||||
if (update_ports.porta.drs == 1 && current_measurements_adc_val.drs == 0) {
|
||||
error_data[5] = 1;
|
||||
}
|
||||
else {
|
||||
error_data[5] = 0;
|
||||
}
|
||||
error.group1.noload_drs = 1;
|
||||
}
|
||||
else {
|
||||
error.group1.noload_drs = 0;
|
||||
}
|
||||
|
||||
if (update_ports.porta.acu == 1 && current_measurements_adc_val.acu == 0) {
|
||||
error_data[6] = 1;
|
||||
}
|
||||
else {
|
||||
error_data[6] = 0;
|
||||
}
|
||||
error.group1.noload_acu = 1;
|
||||
}
|
||||
else {
|
||||
error.group1.noload_acu = 0;
|
||||
}
|
||||
|
||||
if (update_ports.porta.epsc == 1 && current_measurements_adc_val.epsc == 0) {
|
||||
error_data[7] = 1;
|
||||
}
|
||||
else {
|
||||
error_data[7] = 0;
|
||||
}
|
||||
error.group1.noload_epsc = 1;
|
||||
}
|
||||
else {
|
||||
error.group1.noload_epsc = 0;
|
||||
}
|
||||
|
||||
if (update_ports.porta.inverter == 1 && current_measurements_adc_val.inverter == 0) {
|
||||
error_data[8] = 3;
|
||||
}
|
||||
else {
|
||||
error_data[8] = 2;
|
||||
}
|
||||
error.group1.noload_inverter = 1;
|
||||
}
|
||||
else {
|
||||
error.group1.noload_inverter = 0;
|
||||
}
|
||||
|
||||
if (update_ports.porta.lidar == 1 && current_measurements_adc_val.lidar == 0) {
|
||||
error_data[9] = 3;
|
||||
}
|
||||
else {
|
||||
error_data[9] = 2;
|
||||
}
|
||||
error.group1.noload_lidar = 1;
|
||||
}
|
||||
else {
|
||||
error.group1.noload_lidar = 0;
|
||||
}
|
||||
|
||||
if (update_ports.porta.misc == 1 && current_measurements_adc_val.misc == 0) {
|
||||
error_data[10] = 3;
|
||||
}
|
||||
else {
|
||||
error_data[10] = 2;
|
||||
}
|
||||
error.group2.noload_misc = 1;
|
||||
}
|
||||
else {
|
||||
error.group2.noload_misc = 0;
|
||||
}
|
||||
|
||||
if (update_ports.portb.alwayson == 1 && current_measurements_adc_val.alwayson == 0) {
|
||||
error_data[11] = 3;
|
||||
}
|
||||
else {
|
||||
error_data[11] = 2;
|
||||
}
|
||||
error.group2.noload_alwayson = 1;
|
||||
}
|
||||
else {
|
||||
error.group2.noload_alwayson = 0;
|
||||
}
|
||||
|
||||
if (update_ports.portb.sdc == 1 && current_measurements_adc_val.sdc == 0) {
|
||||
error_data[12] = 3;
|
||||
}
|
||||
else {
|
||||
error_data[12] = 2;
|
||||
}
|
||||
error.group2.noload_sdc = 1;
|
||||
}
|
||||
else {
|
||||
error.group2.noload_sdc = 0;
|
||||
}
|
||||
|
||||
if (update_ports.portb.ebs1 == 1 && current_measurements_adc_val.ebs1 == 0) {
|
||||
error_data[13] = 3;
|
||||
}
|
||||
else {
|
||||
error_data[13] = 2;
|
||||
}
|
||||
error.group2.noload_ebs1 = 1;
|
||||
}
|
||||
else {
|
||||
error.group2.noload_ebs1 = 0;
|
||||
}
|
||||
|
||||
if (update_ports.portb.ebs2 == 1 && current_measurements_adc_val.ebs2 == 0) {
|
||||
error_data[14] = 3;
|
||||
}
|
||||
else {
|
||||
error_data[14] = 2;
|
||||
}
|
||||
error.group2.noload_ebs2 = 1;
|
||||
}
|
||||
else {
|
||||
error.group2.noload_ebs2 = 0;
|
||||
}
|
||||
|
||||
if (update_ports.portb.ebs3 == 1 && current_measurements_adc_val.ebs3 == 0) {
|
||||
error_data[15] = 3;
|
||||
}
|
||||
else {
|
||||
error_data[15] = 2;
|
||||
}
|
||||
error.group2.noload_ebs3 = 1;
|
||||
}
|
||||
else {
|
||||
error.group2.noload_ebs3 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user