Skip to content

Commit

Permalink
Component values overridable and voltage divider change compensation
Browse files Browse the repository at this point in the history
  • Loading branch information
vedderb committed Jan 22, 2015
1 parent d9dcbda commit 3b2703b
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 16 deletions.
10 changes: 10 additions & 0 deletions conf_general.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
#define AUTO_PRINT_FAULTS 0
#define SYSTEM_CORE_CLOCK 168000000

// Component parameters to override
//#define V_REG 3.3
#define VIN_R1 39000.0
//#define VIN_R2 2200.0
//#define CURRENT_AMP_GAIN 10.0
//#define CURRENT_SHUNT_RES 0.001

// Correction factor for computations that depend on the old resistor division factor
#define VDIV_CORR ((VIN_R2 / (VIN_R2 + VIN_R1)) / (2.2 / (2.2 + 33.0)))

/*
* Select only one hardware version
*/
Expand Down
14 changes: 12 additions & 2 deletions hwconf/hw_40.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,28 @@

// ADC macros and settings

// Component parameters
// Component parameters (can be overridden)
#ifndef V_REG
#define V_REG 3.3
#endif
#ifndef VIN_R1
#define VIN_R1 33000.0
#endif
#ifndef VIN_R2
#define VIN_R2 2200.0
#endif
#ifndef CURRENT_AMP_GAIN
#define CURRENT_AMP_GAIN 10.0
#endif
#ifndef CURRENT_SHUNT_RES
#define CURRENT_SHUNT_RES 0.001
#endif

// Input voltage
#define GET_INPUT_VOLTAGE() ((V_REG / 4095.0) * (float)ADC_Value[ADC_IND_VIN_SENS] * ((VIN_R1 + VIN_R2) / VIN_R2))

// Voltage on ADC channel
#define ADC_VOLTS(ch) ((float)ADC_Value[ch] / 4096.0 * V_REG)
#define ADC_VOLTS(ch) ((float)ADC_Value[ch] / 4095.0 * V_REG)

// NTC Termistors
#define NTC_RES(adc_val) (0.0)
Expand Down
14 changes: 12 additions & 2 deletions hwconf/hw_45.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,28 @@

// ADC macros and settings

// Component parameters
// Component parameters (can be overridden)
#ifndef V_REG
#define V_REG 3.3
#endif
#ifndef VIN_R1
#define VIN_R1 33000.0
#endif
#ifndef VIN_R2
#define VIN_R2 2200.0
#endif
#ifndef CURRENT_AMP_GAIN
#define CURRENT_AMP_GAIN 10.0
#endif
#ifndef CURRENT_SHUNT_RES
#define CURRENT_SHUNT_RES 0.001
#endif

// Input voltage
#define GET_INPUT_VOLTAGE() ((V_REG / 4095.0) * (float)ADC_Value[ADC_IND_VIN_SENS] * ((VIN_R1 + VIN_R2) / VIN_R2))

// Voltage on ADC channel
#define ADC_VOLTS(ch) ((float)ADC_Value[ch] / 4096.0 * V_REG)
#define ADC_VOLTS(ch) ((float)ADC_Value[ch] / 4095.0 * V_REG)

// NTC Termistors
#define NTC_RES(adc_val) (0.0)
Expand Down
14 changes: 12 additions & 2 deletions hwconf/hw_46.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,28 @@

// ADC macros and settings

// Component parameters
// Component parameters (can be overridden)
#ifndef V_REG
#define V_REG 3.3
#endif
#ifndef VIN_R1
#define VIN_R1 33000.0
#endif
#ifndef VIN_R2
#define VIN_R2 2200.0
#endif
#ifndef CURRENT_AMP_GAIN
#define CURRENT_AMP_GAIN 10.0
#endif
#ifndef CURRENT_SHUNT_RES
#define CURRENT_SHUNT_RES 0.001
#endif

// Input voltage
#define GET_INPUT_VOLTAGE() ((V_REG / 4095.0) * (float)ADC_Value[ADC_IND_VIN_SENS] * ((VIN_R1 + VIN_R2) / VIN_R2))

// Voltage on ADC channel
#define ADC_VOLTS(ch) ((float)ADC_Value[ch] / 4096.0 * V_REG)
#define ADC_VOLTS(ch) ((float)ADC_Value[ch] / 4095.0 * V_REG)

// NTC Termistors
//#define NTC_RES(adc_val) (10000.0 / ((4096.0 / (float)adc_val) - 1.0))
Expand Down
14 changes: 12 additions & 2 deletions hwconf/hw_bw.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,28 @@

// ADC macros and settings

// Component parameters
// Component parameters (can be overridden)
#ifndef V_REG
#define V_REG 3.3
#endif
#ifndef VIN_R1
#define VIN_R1 33000.0
#endif
#ifndef VIN_R2
#define VIN_R2 2200.0
#endif
#ifndef CURRENT_AMP_GAIN
#define CURRENT_AMP_GAIN 10.0
#endif
#ifndef CURRENT_SHUNT_RES
#define CURRENT_SHUNT_RES 0.010
#endif

// Input voltage
#define GET_INPUT_VOLTAGE() ((V_REG / 4095.0) * (float)ADC_Value[ADC_IND_VIN_SENS] * ((VIN_R1 + VIN_R2) / VIN_R2))

// Voltage on ADC channel
#define ADC_VOLTS(ch) ((float)ADC_Value[ch] / 4096.0 * V_REG)
#define ADC_VOLTS(ch) ((float)ADC_Value[ch] / 4095.0 * V_REG)

// NTC Termistors
#define NTC_RES(adc_val) (0.0)
Expand Down
14 changes: 12 additions & 2 deletions hwconf/hw_r2.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,28 @@

// ADC macros and settings

// Component parameters
// Component parameters (can be overridden)
#ifndef V_REG
#define V_REG 3.3
#endif
#ifndef VIN_R1
#define VIN_R1 33000.0
#endif
#ifndef VIN_R2
#define VIN_R2 2200.0
#endif
#ifndef CURRENT_AMP_GAIN
#define CURRENT_AMP_GAIN 10.0
#endif
#ifndef CURRENT_SHUNT_RES
#define CURRENT_SHUNT_RES 0.001
#endif

// Input voltage
#define GET_INPUT_VOLTAGE() ((V_REG / 4095.0) * (float)ADC_Value[ADC_IND_VIN_SENS] * ((VIN_R1 + VIN_R2) / VIN_R2))

// NTC Termistors
#define NTC_RES(adc_val) (10000.0 / ((4096.0 / (float)adc_val) - 1.0))
#define NTC_RES(adc_val) (10000.0 / ((4095.0 / (float)adc_val) - 1.0))
#define NTC_TEMP(adc_ind) (1.0 / ((logf(NTC_RES(ADC_Value[adc_ind]) / 10000.0) / 3434.0) + (1.0 / 298.15)) - 273.15)

// Voltage on ADC channel
Expand Down
14 changes: 12 additions & 2 deletions hwconf/hw_victor_r1a.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,28 @@

// ADC macros and settings

// Component parameters
// Component parameters (can be overridden)
#ifndef V_REG
#define V_REG 3.3
#endif
#ifndef VIN_R1
#define VIN_R1 33000.0
#endif
#ifndef VIN_R2
#define VIN_R2 2200.0
#endif
#ifndef CURRENT_AMP_GAIN
#define CURRENT_AMP_GAIN 10.0
#endif
#ifndef CURRENT_SHUNT_RES
#define CURRENT_SHUNT_RES 0.001
#endif

// Input voltage
#define GET_INPUT_VOLTAGE() ((V_REG / 4095.0) * (float)ADC_Value[ADC_IND_VIN_SENS] * ((VIN_R1 + VIN_R2) / VIN_R2))

// Voltage on ADC channel
#define ADC_VOLTS(ch) ((float)ADC_Value[ch] / 4096.0 * V_REG)
#define ADC_VOLTS(ch) ((float)ADC_Value[ch] / 4095.0 * V_REG)

// NTC Termistors
#define NTC_RES(adc_val) (0.0)
Expand Down
8 changes: 4 additions & 4 deletions mcpwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1702,12 +1702,12 @@ void mcpwm_adc_int_handler(void *p, uint32_t flags) {
if (conf.comm_mode == COMM_MODE_INTEGRATE) {
float limit;
if (has_commutated) {
limit = rpm_dep.cycle_int_limit_running * 0.0005;
limit = rpm_dep.cycle_int_limit_running * (0.0005 * VDIV_CORR);
} else {
limit = rpm_dep.cycle_int_limit * 0.0005;
limit = rpm_dep.cycle_int_limit * (0.0005 * VDIV_CORR);
}

if (cycle_integrator >= (rpm_dep.cycle_int_limit_max * 0.0005) ||
if (cycle_integrator >= (rpm_dep.cycle_int_limit_max * (0.0005 * VDIV_CORR)) ||
cycle_integrator >= limit) {
commutate(1);
cycle_integrator = 0.0;
Expand All @@ -1719,7 +1719,7 @@ void mcpwm_adc_int_handler(void *p, uint32_t flags) {

if (cycle_sum >= (rpm_dep.comm_time_sum / 2.0)) {
commutate(1);
cycle_integrator_sum += cycle_integrator * (1.0 / 0.0005);
cycle_integrator_sum += cycle_integrator * (1.0 / (0.0005 * VDIV_CORR));
cycle_integrator_iterations += 1.0;
cycle_integrator = 0.0;
cycle_sum = 0.0;
Expand Down

0 comments on commit 3b2703b

Please sign in to comment.