diff --git a/src/main/sensors/current.c b/src/main/sensors/current.c index 10ab77acf..d77303ef0 100644 --- a/src/main/sensors/current.c +++ b/src/main/sensors/current.c @@ -45,6 +45,10 @@ static biquadFilter_t adciBatFilter; #define CURRENT_METER_SCALE_DEFAULT 400 // for Allegro ACS758LCB-100U (40mV/A) #endif +#ifndef CURRENT_METER_OFFSET_DEFAULT +#define CURRENT_METER_OFFSET_DEFAULT 0 +#endif + PG_REGISTER_ARRAY_WITH_RESET_FN(currentMeterADCOrVirtualConfig_t, MAX_ADC_OR_VIRTUAL_CURRENT_METERS, currentMeterADCOrVirtualConfig, PG_CURRENT_SENSOR_ADC_OR_VIRTUAL_CONFIG, 0); void pgResetFn_currentMeterADCOrVirtualConfig(currentMeterADCOrVirtualConfig_t *instance) @@ -53,6 +57,7 @@ void pgResetFn_currentMeterADCOrVirtualConfig(currentMeterADCOrVirtualConfig_t * if (i == CURRENT_METER_ADC) { RESET_CONFIG(currentMeterADCOrVirtualConfig_t, &instance[i], .scale = CURRENT_METER_SCALE_DEFAULT, + .offset = CURRENT_METER_OFFSET_DEFAULT, ); } } diff --git a/src/main/target/ALIENFLIGHTF4/config.c b/src/main/target/ALIENFLIGHTF4/config.c index 1e4e45a2b..cc2697c5a 100644 --- a/src/main/target/ALIENFLIGHTF4/config.c +++ b/src/main/target/ALIENFLIGHTF4/config.c @@ -44,9 +44,6 @@ #include "hardware_revision.h" -#define CURRENTOFFSET 2500 // ACS712/714-30A - 0A = 2.5V -#define CURRENTSCALE -667 // ACS712/714-30A - 66.666 mV/A inverted mode - #ifdef BRUSHED_MOTORS_PWM_RATE #undef BRUSHED_MOTORS_PWM_RATE #endif @@ -56,8 +53,6 @@ // alternative defaults settings for AlienFlight targets void targetConfiguration(void) { - currentMeterADCOrVirtualConfigMutable(CURRENT_SENSOR_ADC)->offset = CURRENTOFFSET; - currentMeterADCOrVirtualConfigMutable(CURRENT_SENSOR_ADC)->scale = CURRENTSCALE; compassConfigMutable()->mag_hardware = MAG_NONE; // disabled by default if (hardwareMotorType == MOTOR_BRUSHED) { diff --git a/src/main/target/ALIENFLIGHTF4/target.h b/src/main/target/ALIENFLIGHTF4/target.h index 48b074f4e..54fc5ed8a 100644 --- a/src/main/target/ALIENFLIGHTF4/target.h +++ b/src/main/target/ALIENFLIGHTF4/target.h @@ -145,11 +145,15 @@ #define USE_ADC //#define BOARD_HAS_VOLTAGE_DIVIDER +//#define BOARD_HAS_CURRENT_SENSOR #define VBAT_ADC_PIN PC0 #define CURRENT_METER_ADC_PIN PC1 #define RSSI_ADC_PIN PC4 #define EXTERNAL1_ADC_GPIO_PIN PC5 +#define CURRENT_METER_OFFSET_DEFAULT 2500 // ACS712/714-30A - 0A = 2.5V +#define CURRENT_METER_SCALE_DEFAULT -667 // ACS712/714-30A - 66.666 mV/A inverted mode + #define SPEKTRUM_BIND_PIN UART2_RX_PIN #define BINDPLUG_PIN PB2 diff --git a/src/main/target/ALIENFLIGHTNGF7/config.c b/src/main/target/ALIENFLIGHTNGF7/config.c index 02141331e..cab4efe13 100644 --- a/src/main/target/ALIENFLIGHTNGF7/config.c +++ b/src/main/target/ALIENFLIGHTNGF7/config.c @@ -43,9 +43,6 @@ #include "hardware_revision.h" -#define CURRENTOFFSET 2500 // ACS712/714-30A - 0A = 2.5V -#define CURRENTSCALE -667 // ACS712/714-30A - 66.666 mV/A inverted mode - #ifdef BRUSHED_MOTORS_PWM_RATE #undef BRUSHED_MOTORS_PWM_RATE #endif @@ -55,8 +52,6 @@ // alternative defaults settings for AlienFlight targets void targetConfiguration(void) { - currentMeterADCOrVirtualConfigMutable(CURRENT_SENSOR_ADC)->offset = CURRENTOFFSET; - currentMeterADCOrVirtualConfigMutable(CURRENT_SENSOR_ADC)->scale = CURRENTSCALE; compassConfigMutable()->mag_hardware = MAG_NONE; // disabled by default if (hardwareMotorType == MOTOR_BRUSHED) { diff --git a/src/main/target/ALIENFLIGHTNGF7/target.h b/src/main/target/ALIENFLIGHTNGF7/target.h index 5c377ba4c..7d840db12 100644 --- a/src/main/target/ALIENFLIGHTNGF7/target.h +++ b/src/main/target/ALIENFLIGHTNGF7/target.h @@ -156,10 +156,14 @@ #define USE_ADC #define BOARD_HAS_VOLTAGE_DIVIDER +#define BOARD_HAS_CURRENT_SENSOR #define VBAT_ADC_PIN PC0 #define CURRENT_METER_ADC_PIN PC1 #define RSSI_ADC_PIN PC4 +#define CURRENT_METER_OFFSET_DEFAULT 2500 // ACS712/714-30A - 0A = 2.5V +#define CURRENT_METER_SCALE_DEFAULT -667 // ACS712/714-30A - 66.666 mV/A inverted mode + // LED strip configuration. #define LED_STRIP diff --git a/src/main/target/KROOZX/config.c b/src/main/target/KROOZX/config.c index 971d624c3..05a009b06 100755 --- a/src/main/target/KROOZX/config.c +++ b/src/main/target/KROOZX/config.c @@ -29,8 +29,6 @@ #include "io/osd.h" #define VBAT_SCALE 113 -#define CURRENTSCALE 1000 -#define CURRENTOFFSET 0 #define OSD_POS(x,y) (x | (y << 5)) @@ -38,8 +36,6 @@ void targetConfiguration(void) { voltageSensorADCConfigMutable(VOLTAGE_SENSOR_ADC_VBAT)->vbatscale = VBAT_SCALE; - currentMeterADCOrVirtualConfigMutable(CURRENT_SENSOR_ADC)->offset = CURRENTOFFSET; - currentMeterADCOrVirtualConfigMutable(CURRENT_SENSOR_ADC)->scale = CURRENTSCALE; barometerConfigMutable()->baro_hardware = 0; compassConfigMutable()->mag_hardware = 0; osdConfigMutable()->item_pos[OSD_MAIN_BATT_VOLTAGE] = OSD_POS(12, 1) | VISIBLE_FLAG; diff --git a/src/main/target/KROOZX/target.h b/src/main/target/KROOZX/target.h index d3a1f5b2d..c743697e4 100755 --- a/src/main/target/KROOZX/target.h +++ b/src/main/target/KROOZX/target.h @@ -93,6 +93,9 @@ #define CURRENT_METER_ADC_PIN PC2 #define RSSI_ADC_PIN PC0 +#define CURRENT_METER_SCALE_DEFAULT 1000 +#define CURRENT_METER_OFFSET_DEFAULT 0 + #define USE_VCP //#define VBUS_SENSING_PIN PA9 diff --git a/src/main/target/TINYFISH/config.c b/src/main/target/TINYFISH/config.c index b7ecbc941..8a6a0c5bf 100644 --- a/src/main/target/TINYFISH/config.c +++ b/src/main/target/TINYFISH/config.c @@ -36,21 +36,9 @@ #include "telemetry/telemetry.h" -#define TARGET_CPU_VOLTAGE 3.0 - -#define CURRENTOFFSET 0 -// board uses an ina139, RL=0.005, Rs=30000 -// V/A = (0.005 * 0.001 * 30000) * I -// rescale to 1/10th mV / A -> * 1000 * 10 -// use 3.0V as cpu and adc voltage -> rescale by 3.0/3.3 -#define CURRENTSCALE (0.005 * 0.001 * 30000) * 1000 * 10 * (TARGET_CPU_VOLTAGE / 3.3) - // set default settings to match our target void targetConfiguration(void) { - currentMeterADCOrVirtualConfigMutable(CURRENT_SENSOR_ADC)->offset = CURRENTOFFSET; - currentMeterADCOrVirtualConfigMutable(CURRENT_SENSOR_ADC)->scale = CURRENTSCALE; - // use the same uart for frsky telemetry and SBUS, both non inverted const int index = findSerialPortIndexByIdentifier(SBUS_TELEMETRY_UART); serialConfigMutable()->portConfigs[index].functionMask = FUNCTION_TELEMETRY_FRSKY | FUNCTION_RX_SERIAL; diff --git a/src/main/target/TINYFISH/target.h b/src/main/target/TINYFISH/target.h index 99f107502..8d5544513 100644 --- a/src/main/target/TINYFISH/target.h +++ b/src/main/target/TINYFISH/target.h @@ -100,6 +100,15 @@ #define ADC_INSTANCE ADC3 #define VBAT_SCALE_DEFAULT 100 +#define CURRENT_TARGET_CPU_VOLTAGE 3.0 + +// board uses an ina139, RL=0.005, Rs=30000 +// V/A = (0.005 * 0.001 * 30000) * I +// rescale to 1/10th mV / A -> * 1000 * 10 +// use 3.0V as cpu and adc voltage -> rescale by 3.0/3.3 +#define CURRENT_METER_SCALE_DEFAULT (0.005 * 0.001 * 30000) * 1000 * 10 * (CURRENT_TARGET_CPU_VOLTAGE / 3.3) +#define CURRENT_METER_OFFSET_DEFAULT 0 + #define WS2811_PIN PA8 #define WS2811_TIMER TIM1 #define WS2811_DMA_CHANNEL DMA1_Channel2