Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
DRV.h
00001 #ifndef DRV_H 00002 #define DRV_H 00003 00004 /// Registers /// 00005 #define FSR1 0x0 /// Fault Status Register 1 00006 #define FSR2 0x1 /// Fault Status Register 2 00007 #define DCR 0x2 /// Drive Control Register 00008 #define HSR 0x3 /// Gate Drive HS Register 00009 #define LSR 0x4 /// Gate Drive LS Register 00010 #define OCPCR 0x5 /// OCP Control Register 00011 #define CSACR 0x6 /// CSA Control Register 00012 00013 /// Drive Control Fields /// 00014 #define DIS_CPUV_EN 0x0 /// Charge pump UVLO fault 00015 #define DIS_CPUV_DIS 0x1 00016 #define DIS_GDF_EN 0x0 /// Gate drive fauilt 00017 #define DIS_GDF_DIS 0x1 00018 #define OTW_REP_EN 0x1 /// Over temp warning reported on nFAULT/FAULT bit 00019 #define OTW_REP_DIS 0x0 00020 #define PWM_MODE_6X 0x0 /// PWM Input Modes 00021 #define PWM_MODE_3X 0x1 00022 #define PWM_MODE_1X 0x2 00023 #define PWM_MODE_IND 0x3 00024 #define PWM_1X_COM_SYNC 0x0 /// 1x PWM Mode synchronou rectification 00025 #define PWM_1X_COM_ASYNC 0x1 00026 #define PWM_1X_DIR_0 0x0 /// In 1x PWM mode this bit is ORed with the INHC (DIR) input 00027 #define PWM_1X_DIR_1 0x1 00028 00029 /// Gate Drive HS Fields /// 00030 #define LOCK_ON 0x6 00031 #define LOCK_OFF 0x3 00032 #define IDRIVEP_HS_10MA 0x0 /// Gate drive high side turn on current 00033 #define IDRIVEP_HS_30MA 0x1 00034 #define IDRIVEP_HS_60MA 0x2 00035 #define IDRIVEP_HS_80MA 0x3 00036 #define IDRIVEP_HS_120MA 0x4 00037 #define IDRIVEP_HS_140MA 0x5 00038 #define IDRIVEP_HS_170MA 0x6 00039 #define IDRIVEP_HS_190MA 0x7 00040 #define IDRIVEP_HS_260MA 0x8 00041 #define IDRIVEP_HS_330MA 0x9 00042 #define IDRIVEP_HS_370MA 0xA 00043 #define IDRIVEP_HS_440MA 0xB 00044 #define IDRIVEP_HS_570MA 0xC 00045 #define IDRIVEP_HS_680MA 0xD 00046 #define IDRIVEP_HS_820MA 0xE 00047 #define IDRIVEP_HS_1000MA 0xF 00048 #define IDRIVEN_HS_20MA 0x0 /// High side turn off current 00049 #define IDRIVEN_HS_60MA 0x1 00050 #define IDRIVEN_HS_120MA 0x2 00051 #define IDRIVEN_HS_160MA 0x3 00052 #define IDRIVEN_HS_240MA 0x4 00053 #define IDRIVEN_HS_280MA 0x5 00054 #define IDRIVEN_HS_340MA 0x6 00055 #define IDRIVEN_HS_380MA 0x7 00056 #define IDRIVEN_HS_520MA 0x8 00057 #define IDRIVEN_HS_660MA 0x9 00058 #define IDRIVEN_HS_740MA 0xA 00059 #define IDRIVEN_HS_880MA 0xB 00060 #define IDRIVEN_HS_1140MA 0xC 00061 #define IDRIVEN_HS_1360MA 0xD 00062 #define IDRIVEN_HS_1640MA 0xE 00063 #define IDRIVEN_HS_2000MA 0xF 00064 00065 /// Gate Drive LS Fields /// 00066 #define TDRIVE_500NS 0x0 /// Peak gate-current drive time 00067 #define TDRIVE_1000NS 0x1 00068 #define TDRIVE_2000NS 0x2 00069 #define TDRIVE_4000NS 0x3 00070 #define IDRIVEP_LS_10MA 0x0 /// Gate drive high side turn on current 00071 #define IDRIVEP_LS_30MA 0x1 00072 #define IDRIVEP_LS_60MA 0x2 00073 #define IDRIVEP_LS_80MA 0x3 00074 #define IDRIVEP_LS_120MA 0x4 00075 #define IDRIVEP_LS_140MA 0x5 00076 #define IDRIVEP_LS_170MA 0x6 00077 #define IDRIVEP_LS_190MA 0x7 00078 #define IDRIVEP_LS_260MA 0x8 00079 #define IDRIVEP_LS_330MA 0x9 00080 #define IDRIVEP_LS_370MA 0xA 00081 #define IDRIVEP_LS_440MA 0xB 00082 #define IDRIVEP_LS_570MA 0xC 00083 #define IDRIVEP_LS_680MA 0xD 00084 #define IDRIVEP_LS_820MA 0xE 00085 #define IDRIVEP_LS_1000MA 0xF 00086 #define IDRIVEN_LS_20MA 0x0 /// High side turn off current 00087 #define IDRIVEN_LS_60MA 0x1 00088 #define IDRIVEN_LS_120MA 0x2 00089 #define IDRIVEN_LS_160MA 0x3 00090 #define IDRIVEN_LS_240MA 0x4 00091 #define IDRIVEN_LS_280MA 0x5 00092 #define IDRIVEN_LS_340MA 0x6 00093 #define IDRIVEN_LS_380MA 0x7 00094 #define IDRIVEN_LS_520MA 0x8 00095 #define IDRIVEN_LS_660MA 0x9 00096 #define IDRIVEN_LS_740MA 0xA 00097 #define IDRIVEN_LS_880MA 0xB 00098 #define IDRIVEN_LS_1140MA 0xC 00099 #define IDRIVEN_LS_1360MA 0xD 00100 #define IDRIVEN_LS_1640MA 0xE 00101 #define IDRIVEN_LS_2000MA 0xF 00102 00103 /// OCP Control Fields /// 00104 #define TRETRY_4MS 0x0 /// VDS OCP and SEN OCP retry time 00105 #define TRETRY_50US 0x1 00106 #define DEADTIME_50NS 0x0 /// Deadtime 00107 #define DEADTIME_100NS 0x1 00108 #define DEADTIME_200NS 0x2 00109 #define DEADTIME_400NS 0x3 00110 #define OCP_LATCH 0x0 /// OCP Mode 00111 #define OCP_RETRY 0x1 00112 #define OCP_REPORT 0x2 00113 #define OCP_NONE 0x3 00114 #define OCP_DEG_2US 0x0 /// OCP Deglitch Time 00115 #define OCP_DEG_4US 0x1 00116 #define OCP_DEG_6US 0x2 00117 #define OCP_DEG_8US 0x3 00118 #define VDS_LVL_0_06 0x0 00119 #define VDS_LVL_0_13 0x1 00120 #define VDS_LVL_0_2 0x2 00121 #define VDS_LVL_0_26 0x3 00122 #define VDS_LVL_0_31 0x4 00123 #define VDS_LVL_0_45 0x5 00124 #define VDS_LVL_0_53 0x6 00125 #define VDS_LVL_0_6 0x7 00126 #define VDS_LVL_0_68 0x8 00127 #define VDS_LVL_0_75 0x9 00128 #define VDS_LVL_0_94 0xA 00129 #define VDS_LVL_1_13 0xB 00130 #define VDS_LVL_1_3 0xC 00131 #define VDS_LVL_1_5 0xD 00132 #define VDS_LVL_1_7 0xE 00133 #define VDS_LVL_1_88 0xF 00134 00135 /// CSA Control Fields /// 00136 #define CSA_FET_SP 0x0 /// Current sense amplifier positive input 00137 #define CSA_FET_SH 0x1 00138 #define VREF_DIV_1 0x0 /// Amplifier reference voltage is VREV/1 00139 #define VREF_DIV_2 0x1 /// Amplifier reference voltage is VREV/2 00140 #define CSA_GAIN_5 0x0 /// Current sensor gain 00141 #define CSA_GAIN_10 0x1 00142 #define CSA_GAIN_20 0x2 00143 #define CSA_GAIN_40 0x3 00144 #define DIS_SEN_EN 0x0 /// Overcurrent Fault 00145 #define DIS_SEN_DIS 0x1 00146 #define SEN_LVL_0_25 0x0 /// Sense OCP voltage level 00147 #define SEN_LVL_0_5 0x1 00148 #define SEN_LVL_0_75 0x2 00149 #define SEN_LVL_1_0 0x3 00150 00151 class DRV832x { 00152 public: 00153 DRV832x(SPI *spi, DigitalOut *cs); 00154 int read_FSR1(); 00155 int read_FSR2(); 00156 int read_register(int reg); 00157 void write_register(int reg, int val); 00158 void write_DCR(int DIS_CPUV, int DIS_GDF, int OTW_REP, int PWM_MODE, int PWM_COM, int PWM_DIR, int COAST, int BRAKE, int CLR_FLT); 00159 void write_HSR(int LOCK, int IDRIVEP_HS, int IDRIVEN_HS); 00160 void write_LSR(int CBC, int TDRIVE, int IDRIVEP_LS, int IDRIVEN_LS); 00161 void write_OCPCR(int TRETRY, int DEAD_TIME, int OCP_MODE, int OCP_DEG, int VDS_LVL); 00162 void write_CSACR(int CSA_FET, int VREF_DIV, int LS_REF, int CSA_GAIN, int DIS_SEN, int CSA_CAL_A, int CSA_CAL_B, int CSA_CAL_C, int SEN_LVL); 00163 void enable_gd(void); 00164 void disable_gd(void); 00165 void calibrate(void); 00166 void print_faults(); 00167 00168 private: 00169 SPI *_spi; 00170 DigitalOut *_cs; 00171 uint16_t spi_write(uint16_t val); 00172 }; 00173 00174 #endif
Generated on Thu Jun 15 2023 06:56:48 by
