fix H-file

This commit is contained in:
2025-08-17 18:01:01 +08:00
parent b60cfbee97
commit 443e9bf8f2
7 changed files with 169 additions and 44 deletions

View File

@@ -16,6 +16,11 @@
// #define DEBUG_VERBOSE // Debug Assertions Status : Debug Verbose Information // #define DEBUG_VERBOSE // Debug Assertions Status : Debug Verbose Information
#undef DEBUG_VERBOSE // Debug Assertions Status : No Debug Verbose Information #undef DEBUG_VERBOSE // Debug Assertions Status : No Debug Verbose Information
/* >>>>>>>>>>>>>>>>>>>>[EDDY DRIVE CURRENT DETECTION]<<<<<<<<<<<<<<<<<<<< */
// #define EDDY_DRIVE_CURRENT_DETECTION // Eddy Drive Current Detection : Enable
#undef EDDY_DRIVE_CURRENT_DETECTION // Eddy Drive Current Detection : Disable
/******************************************************************************/ /******************************************************************************/
#define RCU_GPIO_I2C RCU_GPIOF #define RCU_GPIO_I2C RCU_GPIOF

View File

@@ -34,58 +34,151 @@
#define LDC1612_ADDR 0x2B #define LDC1612_ADDR 0x2B
/*Register Rddr*/ /************************Register Addr***************************************/
/***************************************************************************/
#define CONVERTION_RESULT_REG_START 0X00 #define CONVERTION_RESULT_REG_START 0X00
#define SET_CONVERSION_TIME_REG_START 0X08 #define SET_CONVERSION_TIME_REG_START 0X08
#define SET_CONVERSION_OFFSET_REG_START 0X0C #define SET_CONVERSION_OFFSET_REG_START 0X0C
#define SET_LC_STABILIZE_REG_START 0X10 #define SET_SETTLECOUNT_REG_START 0X10
#define SET_FREQ_REG_START 0X14 #define SET_FREQ_REG_START 0X14
#define SENSOR_STATUS_REG 0X18 #define SENSOR_STATUS_REG 0X18
#define ERROR_CONFIG_REG 0X19 #define ERROR_CONFIG_REG 0X19
#define SENSOR_CONFIG_REG 0X1A #define SENSOR_CONFIG_REG 0X1A
#define MUL_CONFIG_REG 0X1B #define MUX_CONFIG_REG 0X1B
#define SENSOR_RESET_REG 0X1C #define SENSOR_RESET_REG 0X1C
#define SET_DRIVER_CURRENT_REG 0X1E #define SET_DRIVER_CURRENT_REG 0X1E
#define READ_MANUFACTURER_ID 0X7E #define READ_MANUFACTURER_ID 0X7E
#define READ_DEVICE_ID 0X7F #define READ_DEVICE_ID 0X7F
/******************************************************************************/ /**********************Sensor Channel****************************************/
#define CHANNEL_0 0 #define CHANNEL_0 0
#define CHANNEL_1 1 #define CHANNEL_1 1
/*************************MUX_CONFIG********************************************/ /*************************MUX_CONFIG********************************************
#define LDC1612_MUX_CONFIG 0x0200 * 0x0209 AutoScanEN: 0 / RR_SEQ: 00 / RESERVED: 0 0010 0000 1 / Deglitch: 001( 1MHz)
* 0x020C AutoScanEN: 0 / RR_SEQ: 00 / RESERVED: 0 0010 0000 1 / Deglitch: 100(3.3MHz)
* 0x020D AutoScanEN: 0 / RR_SEQ: 00 / RESERVED: 0 0010 0000 1 / Deglitch: 100( 10MHz)
* 0x020F AutoScanEN: 0 / RR_SEQ: 00 / RESERVED: 0 0010 0000 1 / Deglitch: 100( 33MHz)
*/
#define LDC1612_MUX_CONFIG 0x020C
/***********************SENSOR_CONFIG********************************************/ /***********************SENSOR_CONFIG********************************************
* 0x1601 Active CH0: 00 / SLEEP: 0 / OVERDRIVE: 1 / LowPowerMode: 0 / AutoAmpDis 1 / CLK(ext): 1 / RESERVED: 0 / INTB_Dis : 0 / HighCurrent: 0 / RESERVED: 00 0001
* 0x1201 Active CH0: 00 / SLEEP: 0 / OVERDRIVE: 1 / LowPowerMode: 0 / AutoAmpDis 0 / CLK(ext): 1 / RESERVED: 0 / INTB_Dis : 0 / HighCurrent: 0 / RESERVED: 00 0001
* 0x1641 Active CH0: 00 / SLEEP: 0 / OVERDRIVE: 1 / LowPowerMode: 0 / AutoAmpDis 1 / CLK(ext): 1 / RESERVED: 0 / INTB_Dis : 0 / HighCurrent: 1 / RESERVED: 00 0001
* 0x1241 Active CH0: 00 / SLEEP: 0 / OVERDRIVE: 1 / LowPowerMode: 0 / AutoAmpDis 0 / CLK(ext): 1 / RESERVED: 0 / INTB_Dis : 0 / HighCurrent: 1 / RESERVED: 00 0001
*/
#define LDC1612_SENSOR_CONFIG_CH0 0x1601 // #ifdef EDDY_DRIVE_CURRENT_DETECTION
#define LDC1612_SENSOR_CONFIG_CH0 0x1241
#else
#define LDC1612_SENSOR_CONFIG_CH0 0x1641
#endif
#define LDC1612_SLEEP_MODE 0x2801
/****************************CONVERSION_TIME************************************/ /****************************CONVERSION_TIME************************************
#define LDC1612_CONVERSION_TIME_CH0 0x1000 // 0x1000=4096个时钟周期 * Freq_ref = 40MHz / CHx_FREF_DIVIDER
#define LC_STABILIZE_TIME_CH0 0x0020 // 0x0020=32个时钟周期 * ******RCOUNT_CHx*******
* Reference Count Conversion Interval Time
* 0x0005 ~ 0xFFFF
* default: 0x0080
* RCOUNT_CHx * 16 / Freq_ref = Conversion Interval Time
*
* ******SETTLECOUNT_CHx*******
* Conversion Settling Time
* 0x0000 ~ 0xFFFF
* default: 0x0000
* SETTLECOUNT_CHx * 16 / Freq_ref = Conversion Settling Time
* 0x1000 4096*16个时钟周期
* 0x0100 256*16个时钟周期
* 0x0000/0x0001 32*16个时钟周期
*
* ******RCOUNT_CHx*******
*/
#define LDC1612_RCOUNT_TIME_CH0 0x1000 // 0x1000=4096个时钟周期
#define LDC1612_SETTLECOUNT_CH0 0x0100
/**************************DRIVE_CURRENT****************************************/ /**************************DRIVE_CURRENT****************************************
#define LDC1612_DRIVE_CURRENT 0x9000 //A000 * 0xA000 CH_IDRIVE: 1010 0 / CH_INIT_IDRIVE: 000 00 / RESERVED: 00 0000
* 0x9000 CH_IDRIVE: 1001 0 / CH_INIT_IDRIVE: 000 00 / RESERVED: 00 0000
* CH_INIT_IDRIVE will update when every conversion systick ==>AutoAmpDis is 0
* CH_INIT_IDRIVE will store init drive current calculated ==> AutoAmpDis is 1
*/
#define LDC1612_DRIVE_CURRENT 0x9000
/**************************SENSOR_CONFIG***************************************/ /**************************SENSOR_CONFIG***************************************/
#define LDC1612_SLEEP_MODE 0x2801
/**************************OTHER_CONFIG*****************************************/
/**************************ERROR_CONFIG****************************************
* [15] Under-Range ERR to OUT (DATA_CHx.CHx_ERR_UR)
* [14] Over-Range ERR to OUT (DATA_CHx.CHx_ERR_OR)
* [13] Watchdog-Timeout ERR to OUT (DATA_CHx.CHx_ERR_WD)
* [12] Amplitude-High-Error ERR to OUT (DATA_CHx.CHx_ERR_AE)
* [11] Amplitude-Low-Error ERR to OUT (DATA_CHx.CHx_ERR_AE)
* [10] RESERVED
* [ 9] RESERVED
* [ 8] RESERVED
* [ 7] Under-Range ERR to INTB (STATUS.ERR_UR)
* [ 6] Over-Range ERR to INTB (STATUS.ERR_OR)
* [ 5] Watchdog-Timeout ERR to INTB (STATUS.ERR_WD)
* [ 4] Amplitude-High-Error ERR to INTB (STATUS.ERR_AHE)
* [ 3] Amplitude-Low-Error ERR to INTB (STATUS.ERR_ALE)
* [ 2] Zero_Count_Error ERR to INTB (STATUS.ERR_ZC)
* [ 1] RESERVED
* [ 0] Data_Ready_Flag to INTB (STATUS.DRDY)
*
* 0x0000 No ERR to OUT or INTB
*/
#define LDC1612_ERROR_CONFIG 0x0000 #define LDC1612_ERROR_CONFIG 0x0000
/**************************STATUS****************************************
* [15]
* [14] Error Channel 0b00: CH0 / 0b01: CH1 / 0b10: CH2 / 0b11: CH3
* [13] Conversion Under-Range Error 0b0: No / 0b1: Yes
* [12] Conversion Over-Range Error 0b0: No / 0b1: Yes
* [11] Watchdog Timeout Error 0b0: No / 0b1: Yes
* [10] Amplitude High Error 0b0: No / 0b1: Yes
* [ 9] Amplitude Low Error 0b0: No / 0b1: Yes
* [ 8] Zero Count Error 0b0: No / 0b1: Yes
* [ 7] RESERVED
* [ 6] Ddata Ready Flag 0b0: No new results / 0b1: New results available
* [ 5] RESERVED
* [ 4] RESERVED
* [ 3] CH0 Unread Conversion Result 0b0: No / 0b1: Yes(DATA_CH0)
* [ 2] CH1 Unread Conversion Result 0b0: No / 0b1: Yes(DATA_CH1)
* [ 1] CH2 Unread Conversion Result 0b0: No / 0b1: Yes(DATA_CH2)
* [ 0] CH3 Unread Conversion Result 0b0: No / 0b1: Yes(DATA_CH3)
*
* 0x0000 No ERR to OUT or INTB
*/
/*****************CONVERSION_OFFSET_CONFIG****************************************/
#define SET_CONVERSION_OFFSET_CH0 0x0000 #define SET_CONVERSION_OFFSET_CH0 0x0000
/***********************RESET DEVICE********************************************
0x8000 RESET_DEV: 1 / RESERVED: 000 0000 0000 0000
*/
#define LDC1612_RESET_DEV 0x8000 //[15:0] 0b1000 0000 0000 0000 #define LDC1612_RESET_DEV 0x8000 //[15:0] 0b1000 0000 0000 0000
/***********************IDs****************************************************/
#define LDC1612_MANUFACTURER_ID 0x5449
#define LDC1612_DEVICE_ID 0x3055
/******************************************************************************/ /******************************************************************************/
#define COIL_RP_KOM 7.2 #define COIL_RP_KOM 7.2
#define COIL_L_UH 33 #define COIL_L_UH 11.22
#define COIL_C_PF 150 #define COIL_C_PF 150
#define COIL_Q_FACTOR 35.97 #define COIL_Q_FACTOR 31.09
#define COIL_FREQ_HZ 2262000 #define COIL_FREQ_HZ 5323770
/******************************************************************************/ /******************************************************************************/
@@ -112,7 +205,7 @@ uint16_t ldc1612_get_deveice_id(void);
uint32_t ldc1612_get_raw_channel_result(uint8_t channel); uint32_t ldc1612_get_raw_channel_result(uint8_t channel);
uint32_t ldc1612_parse_raw_result(uint32_t raw_result); void ldc1612_drvie_current_detect(uint8_t channel);
uint16_t ldc1612_get_sensor_status(void); uint16_t ldc1612_get_sensor_status(void);

View File

@@ -137,10 +137,10 @@ ldc1612_status_t ldc1612_config_single_channel(uint8_t channel) {
delay_ms(5); delay_ms(5);
/* Step 3: 配置LC稳定时间 - 影响测量精度 */ /* Step 3: 配置LC稳定时间 - 影响测量精度 */
ldc1612_write_register(SET_LC_STABILIZE_REG_START + channel, LC_STABILIZE_TIME_CH0); ldc1612_write_register(SET_SETTLECOUNT_REG_START + channel, LDC1612_SETTLECOUNT_CH0);
/* Step 4: 配置转换时间 - 影响测量速度和精度 */ /* Step 4: 配置转换时间 - 影响测量速度和精度 */
ldc1612_write_register(SET_CONVERSION_TIME_REG_START + channel, LDC1612_CONVERSION_TIME_CH0); ldc1612_write_register(SET_CONVERSION_TIME_REG_START + channel, LDC1612_RCOUNT_TIME_CH0);
/* Step 5: 配置转换偏移 */ /* Step 5: 配置转换偏移 */
ldc1612_write_register(SET_CONVERSION_OFFSET_REG_START + channel, SET_CONVERSION_OFFSET_CH0); ldc1612_write_register(SET_CONVERSION_OFFSET_REG_START + channel, SET_CONVERSION_OFFSET_CH0);
@@ -150,7 +150,7 @@ ldc1612_status_t ldc1612_config_single_channel(uint8_t channel) {
/* Step 7: 配置多路复用器 - 设置通道选择和滤波 */ /* Step 7: 配置多路复用器 - 设置通道选择和滤波 */
// ldc1612_configure_mux_register(LDC1612_MUX_AUTOSCAN_DISABLE, LDC1612_MUX_RR_SEQUENCE_0, LDC1612_MUX_FILTER_ALL_LOW, LDC1612_MUX_FILTER_NONE); // ldc1612_configure_mux_register(LDC1612_MUX_AUTOSCAN_DISABLE, LDC1612_MUX_RR_SEQUENCE_0, LDC1612_MUX_FILTER_ALL_LOW, LDC1612_MUX_FILTER_NONE);
ldc1612_write_register(MUL_CONFIG_REG, LDC1612_MUX_CONFIG); ldc1612_write_register(MUX_CONFIG_REG, LDC1612_MUX_CONFIG);
/* Step 8: 配置错误输出 */ /* Step 8: 配置错误输出 */
ldc1612_write_register(ERROR_CONFIG_REG, LDC1612_ERROR_CONFIG); ldc1612_write_register(ERROR_CONFIG_REG, LDC1612_ERROR_CONFIG);
@@ -174,43 +174,53 @@ uint32_t ldc1612_get_raw_channel_result(uint8_t channel) {
uint8_t value[2] = {0}; uint8_t value[2] = {0};
/* Read MSW */ /* Read MSW */
LDC1612_IIC_READ_16BITS(LDC1612_ADDR, CONVERTION_RESULT_REG_START + channel, value); LDC1612_IIC_READ_16BITS(LDC1612_ADDR, CONVERTION_RESULT_REG_START + (channel * 2), value);
raw_value |= (uint32_t)(((uint16_t)value[0] << 8) | value[1]) << 16; raw_value |= (uint32_t)(((uint16_t)value[0] << 8) | value[1]) << 16;
/* Read LSW */ /* Read LSW */
LDC1612_IIC_READ_16BITS(LDC1612_ADDR, CONVERTION_RESULT_REG_START + channel + 1, value); LDC1612_IIC_READ_16BITS(LDC1612_ADDR, CONVERTION_RESULT_REG_START + 1 + (channel * 2), value);
raw_value |= (uint32_t)(((uint16_t)value[0] << 8) | value[1]); raw_value |= (uint32_t)(((uint16_t)value[0] << 8) | value[1]);
uint32_t calibration_value = raw_value & 0x0FFFFFFF; uint32_t calibration_value = raw_value & 0x0FFFFFFF;
if (calibration_value == 0x0FFFFFFF) { if (calibration_value == 0x0FFFFFFF) {
return 0xF0000000; /* No coil */ return 0xF0000000; /* No coil */
} }
uint8_t error_code = (uint8_t)(raw_value >> 24); if (LDC1612_ERROR_CONFIG & 0xF800) {
if (error_code & 0x80) return 0x80000000; /* Under range */ uint8_t error_code = (uint8_t)(raw_value >> 24);
if (error_code & 0x40) return 0x40000000; /* Over range */ if (error_code & 0x80) return 0x80000000; /* Under range */
if (error_code & 0x20) return 0x20000000; /* Watchdog */ if (error_code & 0x40) return 0x40000000; /* Over range */
if (error_code & 0x10) return 0x10000000; /* Amplitude error */ if (error_code & 0x20) return 0x20000000; /* Watchdog */
if (error_code & 0x10) return 0x10000000; /* Amplitude error */
}
return raw_value; return raw_value;
} }
// void ldc1612_drvie_current_detect(uint8_t channel) { void ldc1612_drvie_current_detect(uint8_t channel) {
// uint8_t data[2] = {0}; uint8_t data[2] = {0};
// uint16_t init_value = 0 , drive_current = 0; uint16_t init_value = 0 , drive_current = 0;
// ldc1612_set_sensor_config(LDC1612_SLEEP_MODE); ldc1612_write_register(SENSOR_CONFIG_REG, LDC1612_SLEEP_MODE);
// ldc1612_configure_frequency(channel); delay_ms(10);
// LDC1612_IIC_READ_16BITS(LDC1612_ADDR, SENSOR_CONFIG_REG, data);
// ldc1612_set_sensor_config(LDC1612_SLEEP_MODE); uint16_t freq_divider = ldc1612_calculate_freq_divider(channel);
// ldc1612_set_sensor_config(LDC1612_SENSOR_CONFIG_CH0); //0x1A --0x1601 ldc1612_write_register(SET_FREQ_REG_START + channel, freq_divider);
// delay_ms(10); delay_ms(5);
// LDC1612_IIC_READ_16BITS(LDC1612_ADDR, SET_DRIVER_CURRENT_REG, data);
// init_value = (((data[0] << 8) | data[1]) >> 6) & 0x1F; LDC1612_IIC_READ_16BITS(LDC1612_ADDR, SENSOR_CONFIG_REG, data);
// drive_current = (init_value << 11) | 0x0000; // ldc1612_set_sensor_config(LDC1612_SLEEP_MODE);
// printf("init value: 0x%x\tdrive current: 0x%x\n", init_value, drive_current); ldc1612_write_register(SENSOR_CONFIG_REG, LDC1612_SLEEP_MODE);
// } delay_ms(10);
ldc1612_write_register(SENSOR_CONFIG_REG, LDC1612_SENSOR_CONFIG_CH0);
delay_ms(10);
LDC1612_IIC_READ_16BITS(LDC1612_ADDR, SET_DRIVER_CURRENT_REG, data);
init_value = (((data[0] << 8) | data[1]) >> 6) & 0x1F;
drive_current = (init_value << 11) | 0x0000;
printf("init value: 0x%x\tdrive current: 0x%x\n", init_value, drive_current);
}
/** @brief Get sensor status register /** @brief Get sensor status register
@return Status register value @return Status register value

View File

@@ -80,10 +80,27 @@ int main(void)
ldc1612_init(); ldc1612_init();
ldc1612_config_single_channel(CHANNEL_0); ldc1612_config_single_channel(CHANNEL_0);
#ifdef EDDY_DRIVE_CURRENT_DETECTION
ldc1612_drvie_current_detect(CHANNEL_0);
#endif
while(1){ while(1){
#ifndef EDDY_DRIVE_CURRENT_DETECTION
command_process(); command_process();
delay_ms(10); delay_ms(10);
if (g_sensor_report_enabled) if (g_sensor_report_enabled)
eddy_current_report(); eddy_current_report();
#else
ldc1612_drvie_current_detect(CHANNEL_0);
delay_ms(1000);
#endif
} }
} }

Binary file not shown.