generated from hulk/gd32e23x_template_cmake_vscode
fix H-file
This commit is contained in:
@@ -137,10 +137,10 @@ ldc1612_status_t ldc1612_config_single_channel(uint8_t channel) {
|
||||
delay_ms(5);
|
||||
|
||||
/* 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: 配置转换时间 - 影响测量速度和精度 */
|
||||
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: 配置转换偏移 */
|
||||
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: 配置多路复用器 - 设置通道选择和滤波 */
|
||||
// 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: 配置错误输出 */
|
||||
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};
|
||||
|
||||
/* 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;
|
||||
|
||||
/* 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]);
|
||||
|
||||
|
||||
uint32_t calibration_value = raw_value & 0x0FFFFFFF;
|
||||
if (calibration_value == 0x0FFFFFFF) {
|
||||
return 0xF0000000; /* No coil */
|
||||
}
|
||||
uint8_t error_code = (uint8_t)(raw_value >> 24);
|
||||
if (error_code & 0x80) return 0x80000000; /* Under range */
|
||||
if (error_code & 0x40) return 0x40000000; /* Over range */
|
||||
if (error_code & 0x20) return 0x20000000; /* Watchdog */
|
||||
if (error_code & 0x10) return 0x10000000; /* Amplitude error */
|
||||
if (LDC1612_ERROR_CONFIG & 0xF800) {
|
||||
uint8_t error_code = (uint8_t)(raw_value >> 24);
|
||||
if (error_code & 0x80) return 0x80000000; /* Under range */
|
||||
if (error_code & 0x40) return 0x40000000; /* Over range */
|
||||
if (error_code & 0x20) return 0x20000000; /* Watchdog */
|
||||
if (error_code & 0x10) return 0x10000000; /* Amplitude error */
|
||||
}
|
||||
|
||||
return raw_value;
|
||||
}
|
||||
|
||||
|
||||
// void ldc1612_drvie_current_detect(uint8_t channel) {
|
||||
// uint8_t data[2] = {0};
|
||||
// uint16_t init_value = 0 , drive_current = 0;
|
||||
void ldc1612_drvie_current_detect(uint8_t channel) {
|
||||
uint8_t data[2] = {0};
|
||||
uint16_t init_value = 0 , drive_current = 0;
|
||||
|
||||
// ldc1612_set_sensor_config(LDC1612_SLEEP_MODE);
|
||||
// ldc1612_configure_frequency(channel);
|
||||
// LDC1612_IIC_READ_16BITS(LDC1612_ADDR, SENSOR_CONFIG_REG, data);
|
||||
// ldc1612_set_sensor_config(LDC1612_SLEEP_MODE);
|
||||
// ldc1612_set_sensor_config(LDC1612_SENSOR_CONFIG_CH0); //0x1A --0x1601
|
||||
// delay_ms(10);
|
||||
// LDC1612_IIC_READ_16BITS(LDC1612_ADDR, SET_DRIVER_CURRENT_REG, data);
|
||||
ldc1612_write_register(SENSOR_CONFIG_REG, LDC1612_SLEEP_MODE);
|
||||
delay_ms(10);
|
||||
|
||||
uint16_t freq_divider = ldc1612_calculate_freq_divider(channel);
|
||||
ldc1612_write_register(SET_FREQ_REG_START + channel, freq_divider);
|
||||
delay_ms(5);
|
||||
|
||||
// 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);
|
||||
// }
|
||||
LDC1612_IIC_READ_16BITS(LDC1612_ADDR, SENSOR_CONFIG_REG, data);
|
||||
// ldc1612_set_sensor_config(LDC1612_SLEEP_MODE);
|
||||
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
|
||||
@return Status register value
|
||||
|
17
Src/main.c
17
Src/main.c
@@ -80,10 +80,27 @@ int main(void)
|
||||
ldc1612_init();
|
||||
ldc1612_config_single_channel(CHANNEL_0);
|
||||
|
||||
#ifdef EDDY_DRIVE_CURRENT_DETECTION
|
||||
ldc1612_drvie_current_detect(CHANNEL_0);
|
||||
#endif
|
||||
|
||||
while(1){
|
||||
#ifndef EDDY_DRIVE_CURRENT_DETECTION
|
||||
command_process();
|
||||
delay_ms(10);
|
||||
if (g_sensor_report_enabled)
|
||||
eddy_current_report();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#else
|
||||
ldc1612_drvie_current_detect(CHANNEL_0);
|
||||
delay_ms(1000);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user