CSA部分:
内部CSA可以配置为单向,或者双向,一共有两个CSA,内部CSA的GAIN可以配置,挡位有10,20,40,80四种增益选项。
也可以直接关闭内部CSA,CSA的过流保护值和过流保护滤波时间都可以单独设置。
相关寄存器:
DR7808_GENCTRL1
DR7808_HBIDIAG
DR7808_GENCTRL2
DR7808_CSA_OC_SH
寄存器相关描述:
相关头文件如下:
/* Analogysemi xutong 2023/10/10 */ #ifndef __DR7808_H #define __DR7808_H #include "bsp_lpspi.h" /* DR7808 SPI每个帧是24bit数据组成 */ #define DR7808_GENCTRL1 0x00 #define DR7808_GENCTRL2 0x01 #define DR7808_VDS1 0x02 #define DR7808_VDS2 0x03 #define DR7808_CCP_BLK1 0x04 #define DR7808_CCP_BLK2_ACT 0x05 #define DR7808_CCP_BLK2_FW 0x05 #define DR7808_HBMODE 0x06 #define DR7808_PWMSET 0x07 #define DR7808_TPRECHG 0x08 #define DR7808_HBIDIAG 0x09 #define DR7808_ST_ICHG 0x0A #define DR7808_PWM_PCHG_INIT 0x0A #define DR7808_PWM_ICHG_ACT 0x0B #define DR7808_PWM_ICHG_FW 0x0B #define DR7808_PWM_IDCHG_ACT 0x0C #define DR7808_PWM_PDCHG_INIT 0x0C #define DR7808_PWM_ICHGMAX_CCP_BLK3_ACT 0x0D #define DR7808_PWM_ICHGMAX_CCP_BLK3_FW 0x0D #define DR7808_TDON_OFF1 0x0E #define DR7808_TDON_OFF2 0x0F #define DR7808_TDON_OFF3 0x10 #define DR7808_GENSTAT 0x11 #define DR7808_DSOV 0x12 #define DR7808_HBVOUT_PWMERR 0x13 #define DR7808_EFF_TDON_OFF1 0x14 #define DR7808_EFF_TDON_OFF2 0x15 #define DR7808_EFF_TDON_OFF3 0x16 #define DR7808_TRISE_FALL1 0x17 #define DR7808_TRISE_FALL2 0x18 #define DR7808_TRISE_FALL3 0x19 #define DR7808_DEVID 0x1F #define DR7808_DRV_LPWR_EN 0x1C #define DR7808_CSA_OC_SH 0x1D #define DR7808_MISC 0x1E #define DR7808_GENSTAT 0x11 #define DR7808_DSOV 0x12 #define DR7808_HBVOUT_PWMERR 0x13 #define DR7808_EFF_TDON_OFF1 0x14 #define DR7808_EFF_TDON_OFF2 0x15 #define DR7808_EFF_TDON_OFF3 0x16 #define DR7808_TRISE_FALL 0x17 #define DR7808_TRISE_FALL2 0x18 #define DR7808_TRISE_FALL3 0x19 #define DR7808_GDF 0x1A #define DR7808_DEVID 0x1F //注意 DR7808 不同寄存器有不同Bank //Note DR7808 has different banks for different registers // DR7808 half bridge config // DR7808 半桥配置 enum DR7808_HB_Mode{HighImpedance=0,LSn_ON=1,HSn_ON=2}; typedef struct{ uint8_t HB8_Mode; uint8_t HB7_Mode; uint8_t HB6_Mode; uint8_t HB5_Mode; uint8_t HB4_Mode; uint8_t HB3_Mode; uint8_t HB2_Mode; uint8_t HB1_Mode; }HBMODE_InitTypeDef; // DR7808 PWM Setting // DR7808 PWM 设置 enum DR7808_PWM_HB{HB1=0,HB2=1,HB3=2,HB4=3,HB5=4,HB6=5,HB7=6,HB8=7}; typedef struct{ uint8_t PWM1_HB; uint8_t PWM2_HB; uint8_t PWM3_HB; uint8_t PWM1_EN; uint8_t PWM2_EN; uint8_t PWM3_EN; //Drain-Source monitoring in bridge passive mode //漏源监控在桥被动模式 uint8_t PASS_VDS; //Settings for bridge driver passive mode //00B: LS1-4 are always off. //Note: Changing PASS_MOD from //00B: to any other value requires to clear DSOV1) first before writing PASS_MOD, //01B: LS1-4 are always on (static brake). //10B: LS1-4 are activated if passive VM OV is detected (overvoltage brake) (default). //11B: LS1-4 are activated if passive VM OV is detected and PWM1 = High (overvoltage brake conditioned by PWM1). uint8_t PASS_Mode; }PWMSET_InitTypeDef; // half bridge Vds threshold Setting // 半桥Vds阈值设定 /* 000B: 0.15V 001B: 0.20V (default) 010B: 0.25V 011B: 0.30V 100B: 0.40V 101B: 0.50V 110B: 0.60V 111B: 2.0V */ enum DR7808_HB_VDSTh{Vdsth_15=0,Vdsth_20=1,Vdsth_25=2,Vdsth_30=2, Vdsth_40=2,Vdsth_50=2,Vdsth_60=2,Vdsth2_0=2}; typedef struct{ uint8_t HB8_VDSTh; uint8_t HB7_VDSTh; uint8_t HB6_VDSTh; uint8_t HB5_VDSTh; uint8_t HB4_VDSTh; uint8_t HB3_VDSTh; uint8_t HB2_VDSTh; uint8_t HB1_VDSTh; }VDS_Vth_InitTypeDef; // CSA 相关配置 enum DR7808_CSA_Config{Gain10=0,Gain20=1,Gain40=2,Gain80=3, CSA_Unidirectional=0,CSA_Bidirectional=1,OCThLevel1=0,OCThLevel2=1, OCThLevel3=2,OCThLevel4=3}; typedef struct{ //配置CSA方向 CSA_Bidirectional 或者 CSA_Unidirectional //配置双向或者单向 uint8_t CSA1_Direction; uint8_t CSA2_Direction; // 配置 CSA Gain的大小 10,20,40,80 uint8_t CSA1_Gain; uint8_t CSA2_Gain; // 配置OCP是否开启 uint8_t OverCurrentProtect; //配置CSA 在高边或者底边 //Configure CSA on the high-side or the low-side uint8_t CSA1_Level; uint8_t CSA2_Level; //配置过流滤波时间 //Overcurrent filter time uint8_t OC1FILT; uint8_t OC2FILT; //关闭CSA //Disenable CSA uint8_t CSA1_OFF; uint8_t CSA2_OFF; // Overcurrent detection threshold // 过流检测阈值设置 uint8_t OCTH1; uint8_t OCTH2; // Overcurrent detection threshold of SO1 with CSD1 = 0 //00B: VSO1 > VDD / 2 (default) //01B: VSO1 > VDD / 2 + VDD / 10 //10B: VSO1 > VDD / 2 + 2 x VDD / 10 //11B: VSO1 > VDD / 2 + 3x VDD / 10 //Overcurrent detection threshold of SO1 with CSD1 = 1 //00B: VSO1 > VDD / 2+2 x VDD / 20 or VCSOx < VDD / 2 – 2 × VDD / 20 (default) //01B: VSO1 > VDD / 2+ 4x VDD / 20 or VCSOx < VDD / 2 – 4 × VDD / 20 //10B: VSO1 > VDD / 2+ 5 x VDD / 20 or VCSOx < VDD / 2 ? 5 × VDD / 20 //11B: VSO1 > VDD / 2+ 6x VDD / 20 or VCSOx < VDD / 2 – 6 × VDD / 20 }CSA_InitTypeDef; // 获取寄存器信息 void DR7808_Read_Reg(uint8_t Reg,uint8_t *RData); // 读取并且清除寄存器 void DR7808_Read_Clear_Reg(uint8_t Reg,uint8_t *RData); // 写入寄存器信息 void DR7808_Write_Reg(uint8_t Reg,uint16_t WData,uint8_t *RData); // 退出FS Mode void DR7808_Quit_FS(void); // 禁用看门狗 void DR7808_Dis_WD(void); // DR7808 延时 void DR7808_delay(uint32_t count); // 桥壁设置 void DR7808_Half_Bridge_Mode(HBMODE_InitTypeDef* config,uint8_t *RData); // PWM设置通道和DS监控被动模式配置 void DR7808_PWMSET_Channel(PWMSET_InitTypeDef* config,uint8_t *RData); // HB VDS 监控阈值设定 // HB VDS monitoring threshold Setting // 设置 VDS1 和 VDS2 寄存器 void DR7808_VDS_Monitoring(VDS_Vth_InitTypeDef* config,uint8_t *RData); // 内部CSA配置 void DR7808_CSA_Conifg(CSA_InitTypeDef* config,uint8_t *RData); // DR7808 喂狗 void DR7808_Feed_Dog(uint8_t *RData); // 获取DR7808 ID uint8_t DR7808_GetChipID(void); #endif
#include "DR7808.h" void DR7808_delay(uint32_t count) { volatile uint32_t i = 0; for (i = 0; i < count; ++i) { __asm("NOP"); /* 调用nop空指令 */ __asm("NOP"); /* 调用nop空指令 */ __asm("NOP"); /* 调用nop空指令 */ __asm("NOP"); /* 调用nop空指令 */ __asm("NOP"); /* 调用nop空指令 */ } } //获取寄存器信息 void DR7808_Read_Reg(uint8_t Reg,uint8_t *RData) { uint8_t TxData[3]={0X00,0X00,0X00}; //读取寄存器 TxData[0]=(Reg<<1)|0xC0; Lpspi_Read(3,TxData,RData); } //读取与清除寄存器信息 void DR7808_Read_Clear_Reg(uint8_t Reg,uint8_t *RData) { uint8_t TxData[3]={0X00,0X00,0X00}; //读取寄存器 TxData[0]=(Reg<<1)|0xC1; Lpspi_Read(3,TxData,RData); } //写寄存器信息 void DR7808_Write_Reg(uint8_t Reg,uint16_t WData,uint8_t *RData) { uint8_t TxData[3]={0X00,0X00,0X00}; //读取寄存器&写入寄存器 TxData[0]=(Reg<<1)|0xC1; TxData[1]=WData>>8; TxData[2]=WData&0x00FF; Lpspi_Read(3,TxData,RData); } // dr7808 退出FS Mode void DR7808_Quit_FS(void) { uint8_t Data[3]={0X00,0X00,0X00}; //读取并且清除Gensata DR7808_Read_Clear_Reg(DR7808_GENSTAT,Data); DR7808_delay(2000); //看门狗位置1 DR7808_Write_Reg(DR7808_GENCTRL1,0x0027,Data); DR7808_delay(2000); //看门狗位置0 DR7808_Write_Reg(DR7808_GENCTRL1,0x0000,Data); DR7808_delay(2000); } // dr7808 禁用看门狗 void DR7808_Dis_WD(void) { uint8_t Data[3]; DR7808_delay(2000); //看门狗Unlock 置1 DR7808_Write_Reg(DR7808_GENCTRL1,0x00A7,Data); DR7808_delay(2000); //禁用看门狗 DR7808_Write_Reg(DR7808_GENCTRL2,0x4380,Data); } // dr7808桥壁配置 void DR7808_Half_Bridge_Mode(HBMODE_InitTypeDef* config,uint8_t *RData) { uint16_t WData=0; WData|=(config->HB8_Mode)<<14; WData|=(config->HB7_Mode)<<12; WData|=(config->HB6_Mode)<<10; WData|=(config->HB5_Mode)<<8; WData|=(config->HB4_Mode)<<6; WData|=(config->HB3_Mode)<<4; WData|=(config->HB2_Mode)<<2; WData|=(config->HB1_Mode); DR7808_Write_Reg(DR7808_HBMODE,WData,RData); } // 未测试 // dr7808 PWM 通道配置 void DR7808_PWMSET_Channel(PWMSET_InitTypeDef* config,uint8_t *RData) { uint16_t WData=0; WData|=(config->PWM1_HB)<<1; WData|=(config->PWM2_HB)<<5; WData|=(config->PWM3_HB)<<9; WData|=(config->PWM1_EN); WData|=(config->PWM2_EN)<<4; WData|=(config->PWM3_EN)<<8; WData|=(config->PASS_VDS)<<14; WData|=(config->PASS_Mode)<<12; DR7808_Write_Reg(DR7808_PWMSET,WData,RData); } //未测试 //VDS Monitor threshold setting HB1~HB4 void DR7808_VDS_Monitoring_1_4(VDS_Vth_InitTypeDef* config,uint8_t *RData) { uint16_t WData=0; WData|=(config->HB1_VDSTh); WData|=(config->HB2_VDSTh)<<3; WData|=(config->HB3_VDSTh)<<6; WData|=(config->HB4_VDSTh)<<9; DR7808_Write_Reg(DR7808_VDS1,WData,RData); } //未测试 //VDS Monitor threshold setting HB5~HB8 void DR7808_VDS_Monitoring_5_8(VDS_Vth_InitTypeDef* config,uint8_t *RData) { uint16_t WData=0; WData|=(config->HB5_VDSTh); WData|=(config->HB6_VDSTh)<<3; WData|=(config->HB7_VDSTh)<<6; WData|=(config->HB8_VDSTh)<<9; DR7808_Write_Reg(DR7808_VDS2,WData,RData); } // dr7808喂狗操作 void DR7808_Feed_Dog(uint8_t *RData) { uint16_t WData=0; uint8_t Data[3]; //读取看门狗位 DR7808_Read_Reg(DR7808_GENCTRL1,Data); DR7808_delay(20); //如果看门狗位为1 if((Data[2]&0x01)==1) { //看门狗位置0并写入 Data[2]&=0XFE; WData|=Data[1]<<8; WData|=Data[2]; DR7808_Write_Reg(DR7808_GENCTRL1,WData,RData); } else { //看门狗位置1并写入 Data[2]|=0X01; WData|=Data[1]<<8; WData|=Data[2]; DR7808_Write_Reg(DR7808_GENCTRL1,WData,RData); } } // dr7808 csa相关配置 void DR7808_CSA_Conifg(CSA_InitTypeDef* config,uint8_t *RData) { uint16_t WData=0; uint8_t Data[3]; //读取GENCTRL1配置 DR7808_Read_Reg(DR7808_GENCTRL1,Data); WData|=(config->CSA2_Direction)<<15; WData|=(config->CSA2_Gain)<<13; WData|=(config->CSA1_Direction)<<12; WData|=(config->CSA1_Gain)<<10; //接收值后十位不变 WData|=(Data[1]&0x03)<<8; WData|=Data[2]; DR7808_Write_Reg(DR7808_GENCTRL1,WData,RData); //清空WData WData=0; DR7808_delay(20); DR7808_Read_Reg(DR7808_HBIDIAG,Data); WData|=Data[2]; WData|=(config->CSA2_Level)<<15; WData|=(config->CSA1_Level)<<14; WData|=(config->OC2FILT)<<12; WData|=(config->OC1FILT)<<10; WData|=(config->CSA2_OFF)<<9; WData|=(config->CSA1_OFF)<<8; DR7808_Write_Reg(DR7808_HBIDIAG,WData,RData); //清空WData WData=0; DR7808_delay(20); //读取GENCTRL2配置 DR7808_Read_Reg(DR7808_GENCTRL2,Data); //清空后四位 Data[2]&=0XF0; //高8位不变 WData|=Data[1]<<8; WData|=Data[2]; WData|=(config->OCTH2)<<2; WData|=(config->OCTH1); } // dr7808 ID获取 uint8_t DR7808_GetChipID(void) { uint8_t Data[3]; DR7808_Read_Reg(DR7808_DEVID,Data); return Data[2]; }
DR7808退出Fail Safe:
// dr7808 退出FS Mode 经过验证 void DR7808_Quit_FS(void) { uint8_t Data[3]={0X00,0X00,0X00}; //读取并且清除Gensata DR7808_Read_Clear_Reg(DR7808_GENSTAT,Data); DR7808_delay(2000); //看门狗位置1 DR7808_Write_Reg(DR7808_GENCTRL1,0x0027,Data); DR7808_delay(2000); //看门狗位置0 DR7808_Write_Reg(DR7808_GENCTRL1,0x0000,Data); DR7808_delay(2000); }
DR7808关闭看门狗:
// dr7808 禁用看门狗 经过验证 void DR7808_Dis_WD(void) { uint8_t Data[3]; DR7808_delay(2000); //看门狗Unlock 置1 DR7808_Write_Reg(DR7808_GENCTRL1,0x00A7,Data); DR7808_delay(2000); //禁用看门狗 DR7808_Write_Reg(DR7808_GENCTRL2,0x4380,Data); }
需要注意的是,在故障安全模式下,控制寄存器被冻结为其默认值,WDTRIG、PASS_VDS、PASS_MOD、CSA1L、CSA2L除外。在此模式下,任何写命令(WDTRIG 位除外)或清除命令(GENSTAT除外)都将被丢弃并设置SPIE位(全局状态字节)。
在故障安全模式下对GENSTAT的清除命令不会重置该状态寄存器报告的任何故障标志。在退出序列开始之前,可以在此模式下读取控制和状态寄存器,而不会设置SPIE位。通常Fail Safe和 关闭看门狗可以一起使用
注意:以上有些代码未经过验证
标签:void,配置,CSA,uint8,笔记,Mode,DR7808,define From: https://www.cnblogs.com/xuyuntong/p/17759437.html