加入星計(jì)劃,您可以享受以下權(quán)益:

  • 創(chuàng)作內(nèi)容快速變現(xiàn)
  • 行業(yè)影響力擴(kuò)散
  • 作品版權(quán)保護(hù)
  • 300W+ 專業(yè)用戶
  • 1.5W+ 優(yōu)質(zhì)創(chuàng)作者
  • 5000+ 長(zhǎng)期合作伙伴
立即加入

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

05/15 09:20
2528
服務(wù)支持:
技術(shù)交流群

完成交易后在“購(gòu)買成功”頁(yè)面掃碼入群,即可與技術(shù)大咖們分享疑惑和經(jīng)驗(yàn)、收獲成長(zhǎng)和認(rèn)同、領(lǐng)取優(yōu)惠和紅包等。

虛擬商品不可退

當(dāng)前內(nèi)容為數(shù)字版權(quán)作品,購(gòu)買后不支持退換且無(wú)法轉(zhuǎn)移使用。

加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點(diǎn)資訊討論
放大
電路板圖(3)
相關(guān)方案
  • 方案介紹
  • 推薦器件
  • 相關(guān)推薦
  • 電子產(chǎn)業(yè)圖譜
申請(qǐng)入駐 產(chǎn)業(yè)圖譜

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

當(dāng)模塊離線時(shí)自動(dòng)報(bào)警

首先附上項(xiàng)目完整全家福

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

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

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

電源管理模塊:

使用STM32F042作為主控,INA226作為測(cè)量元件

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

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

同時(shí)該路電源還具有上電自檢和超功率保護(hù)的功能

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

在超過(guò)額定功率輸出的情況下也會(huì)強(qiáng)制斷開三路電源 進(jìn)入保護(hù)程序

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

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

void detect_task(void const *pvParameters)
{
static uint32_t system_time;
system_time = xTaskGetTickCount();
//init,初始化
detect_init(system_time);
//wait a time.空閑一段時(shí)間
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
//未使能,跳過(guò)
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
//記錄錯(cuò)誤以及掉線時(shí)間
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 ,
//判斷錯(cuò)誤優(yōu)先級(jí), 保存優(yōu)先級(jí)最高的錯(cuò)誤碼
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ù),運(yùn)行解決函數(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ù)錯(cuò)誤
//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
//計(jì)算頻率
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;
}
}

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

代碼部分:

https://gitee.com/duandijun1/2024_-digi-code.git,項(xiàng)目gitee地址

項(xiàng)目演示視頻

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

 

推薦器件

更多器件
器件型號(hào) 數(shù)量 器件廠商 器件描述 數(shù)據(jù)手冊(cè) ECAD模型 風(fēng)險(xiǎn)等級(jí) 參考價(jià)格 更多信息
A3987SLPTR-T 1 Allegro MicroSystems LLC Stepper Motor Controller, 1.5A, NMOS, PDSO24, MO-153ADT, TSSOP-24

ECAD模型

下載ECAD模型
$5.27 查看
FNB41560B2 1 onsemi Motion SPM&reg; 45 Series Longer Pins, 72-TUBE
$13.86 查看
CD4051BM96 1 Texas Instruments 20-V, 8:1, 1-channel analog multiplexer with logic-level conversion 16-SOIC -55 to 125

ECAD模型

下載ECAD模型
$0.42 查看

相關(guān)推薦

電子產(chǎn)業(yè)圖譜