• 方案介紹
  • 推薦器件
  • 相關(guān)推薦
申請入駐 產(chǎn)業(yè)圖譜

基于CAN總線設(shè)計的HMI車載外設(shè)控制器

2024/05/15
3609
加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點資訊討論

該項目為2023DigiKey汽車應(yīng)用創(chuàng)意挑戰(zhàn)賽 開發(fā)的電源管理模塊 該模塊具有上電自檢-過流保護-過功率保護等功能,還可以與主控通信

當(dāng)模塊離線時自動報警

首先附上項目完整全家福

藍(lán)色為本次大賽中使用的STM32顯示器件,用來顯示多種信息在屏幕上

綠色板子為電源模塊,用來統(tǒng)計電源消耗信息

黑色板子為從控,用來和顯示部分交互數(shù)據(jù)

電源管理模塊:

使用STM32F042作為主控,INA226作為測量元件

具有1電源輸入3可控電源輸出

同時一路電源還有功率測量功能,可以對該路上的電源負(fù)載做出統(tǒng)計,通過板載的CAN總線反饋到屏幕終端上,

同時該路電源還具有上電自檢和超功率保護的功能

上電自檢時發(fā)現(xiàn)三個輸出端口有輸出的情況下將會觸發(fā)報警程序

在超過額定功率輸出的情況下也會強制斷開三路電源 進入保護程序

保護邏輯并非為超過功率即保護 而是有60焦?fàn)柕木彌_能量,當(dāng)60焦耳的緩沖能量使用完之后才會斷開輸出

主控離線檢測代碼設(shè)計

void detect_task(void const *pvParameters)
{
static uint32_t system_time;
system_time = xTaskGetTickCount();
//init,初始化
detect_init(system_time);
//wait a time.空閑一段時間
vTaskDelay(DETECT_TASK_INIT_TIME);

while (1)
{
static uint8_t error_num_display = 0;
system_time = xTaskGetTickCount();

error_num_display = ERROR_LIST_LENGHT;
error_list[ERROR_LIST_LENGHT].is_lost = 0;
error_list[ERROR_LIST_LENGHT].error_exist = 0;

for (int i = 0; i < ERROR_LIST_LENGHT; i++)
{
//disable, continue
//未使能,跳過
if (error_list[i].enable == 0)
{
continue;
}

//judge offline.判斷掉線
if (system_time - error_list[i].new_time > error_list[i].set_offline_time)
{
if (error_list[i].error_exist == 0)
{
//record error and time
//記錄錯誤以及掉線時間
error_list[i].is_lost = 1;
error_list[i].error_exist = 1;
error_list[i].lost_time = system_time;
}
//judge the priority,save the highest priority ,
//判斷錯誤優(yōu)先級, 保存優(yōu)先級最高的錯誤碼
if (error_list[i].priority > error_list[error_num_display].priority)
{
error_num_display = i;
}
error_list[ERROR_LIST_LENGHT].is_lost = 1;
error_list[ERROR_LIST_LENGHT].error_exist = 1;
//if solve_lost_fun != NULL, run it
//如果提供解決函數(shù),運行解決函數(shù)
if (error_list[i].solve_lost_fun != NULL)
{
error_list[i].solve_lost_fun();
}
}
else if (system_time - error_list[i].work_time < error_list[i].set_online_time)
{
//just online, maybe unstable, only record
//剛剛上線,可能存在數(shù)據(jù)不穩(wěn)定,只記錄不丟失,
error_list[i].is_lost = 0;
error_list[i].error_exist = 1;
}
else
{
error_list[i].is_lost = 0;
//判斷是否存在數(shù)據(jù)錯誤
//judge if exist data error
if (error_list[i].data_is_error != NULL)
{
error_list[i].error_exist = 1;
}
else
{
error_list[i].error_exist = 0;
}
//calc frequency
//計算頻率
if (error_list[i].new_time > error_list[i].last_time)
{
error_list[i].frequency = configTICK_RATE_HZ / (fp32)(error_list[i].new_time - error_list[i].last_time);
}
}
}

vTaskDelay(DETECT_CONTROL_TIME);
#if INCLUDE_uxTaskGetStackHighWaterMark
detect_task_stack = uxTaskGetStackHighWaterMark(NULL);
#endif
}
}

void detect_hook(uint8_t toe)
{
error_list[toe].last_time = error_list[toe].new_time;
error_list[toe].new_time = xTaskGetTickCount();

if (error_list[toe].is_lost)
{
error_list[toe].is_lost = 0;
error_list[toe].work_time = error_list[toe].new_time;
}

if (error_list[toe].data_is_error_fun != NULL)
{
if (error_list[toe].data_is_error_fun())
{
error_list[toe].error_exist = 1;
error_list[toe].data_is_error = 1;

if (error_list[toe].solve_data_error_fun != NULL)
{
error_list[toe].solve_data_error_fun();
}
}
else
{
error_list[toe].data_is_error = 0;
}
}
else
{
error_list[toe].data_is_error = 0;
}
}

從極端運行FreeRTOS代碼,編寫一個detect任務(wù),用來檢測CAN總線上是否存在離線設(shè)備,通過建立臨時表存儲總線上設(shè)備運行時,在can回調(diào)函數(shù)中運行鉤子函數(shù)來更新detect任務(wù)中的任務(wù)在線時間來檢測是否有離線設(shè)備的存在,同時還會檢測設(shè)備數(shù)據(jù)是否有異常

代碼部分:

https://gitee.com/duandijun1/2024_-digi-code.git,項目gitee地址

項目演示視頻

【digikey】https://www.bilibili.com/video/BV17N4y1J74L/?share_source=copy_web&vd_source=f30c922e047da4be83d06ba1e7589a36

 

推薦器件

更多器件
器件型號 數(shù)量 器件廠商 器件描述 數(shù)據(jù)手冊 ECAD模型 風(fēng)險等級 參考價格 更多信息
ADG819BRTZ-500RL7 1 Analog Devices Inc 0.5 &Omega; CMOS 1.8 V to 5.5 V 2:1 Mux/SPDT Switch with BBM Switching Action

ECAD模型

下載ECAD模型
$2.83 查看
NC7SB3157P6X 1 Fairchild Semiconductor Corporation SPDT, 1 Func, 1 Channel, CMOS, PDSO6, 1.25 MM, EIAJ SC-88, SC-70, 6 PIN
$0.32 查看
VNH7070BASTR 1 STMicroelectronics Automotive fully integrated H-bridge motor driver

ECAD模型

下載ECAD模型
$3.23 查看

相關(guān)推薦