Skip to content

Commit 69c5abb

Browse files
author
Bjoern Schmidt
committed
reworked config sync request, new app version needed
added battery voltage calibration
1 parent f04701b commit 69c5abb

File tree

12 files changed

+90
-36
lines changed

12 files changed

+90
-36
lines changed

ACAcontrollerState.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ uint8_t ui8_s_hall_angle3_180 = 127;
4646
uint8_t ui8_s_hall_angle1_240 = 170;
4747
uint8_t ui8_s_hall_angle5_300 = 212;
4848

49+
uint8_t ui8_s_battery_voltage_calibration;
50+
4951
// internal
5052
uint32_t uint32_icc_signals = 0;
5153

@@ -75,7 +77,7 @@ uint32_t ui32_erps_filtered = 0; //filtered value of erps
7577
uint16_t ui16_virtual_erps_speed = 0;
7678
uint16_t ui16_BatteryCurrent = 0; //Battery Current read from ADC8
7779
uint8_t ui8_position_correction_value = 127; // in 360/256 degrees
78-
uint8_t ui8_correction_at_angle = 127; // advance angle testing
80+
uint8_t ui8_correction_at_angle = 85; // 85 is correct, cause of weird angle definition
7981
uint16_t ui16_ADC_iq_current = 0;
8082
uint16_t ui16_ADC_iq_current_filtered = 0;
8183
uint8_t ui8_control_state = 0;
@@ -123,6 +125,7 @@ void controllerstate_init(void) {
123125

124126
// convert static defines to volatile vars
125127
ui16_aca_flags = ACA;
128+
ui8_s_battery_voltage_calibration = ADC_BATTERY_VOLTAGE_K;
126129
ui8_speedlimit_kph = limit;
127130
ui8_speedlimit_without_pas_kph = limit_without_pas;
128131
ui8_speedlimit_with_throttle_override_kph = limit_with_throttle_override;
@@ -202,6 +205,9 @@ void controllerstate_init(void) {
202205
if (eepromVal > 0) ui8_s_hall_angle1_240 = eepromVal;
203206
eepromVal = eeprom_read(OFFSET_HALL_ANGLE_5_300);
204207
if (eepromVal > 0) ui8_s_hall_angle5_300 = eepromVal;
208+
209+
eepromVal = eeprom_read(OFFSET_BATTERY_VOLTAGE_CALIB);
210+
if (eepromVal > 0) ui8_s_battery_voltage_calibration = eepromVal;
205211

206212
for (di = 0; di < 6; di++) {
207213
uint8_t_hall_order[di] = 0;

ACAcontrollerState.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ extern uint8_t ui8_s_hall_angle3_180;
115115
extern uint8_t ui8_s_hall_angle1_240;
116116
extern uint8_t ui8_s_hall_angle5_300;
117117

118+
extern uint8_t ui8_s_battery_voltage_calibration;
118119

119120
void controllerstate_init(void);
120121

ACAeeprom.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ typedef enum {
5757
OFFSET_HALL_ANGLE_2_120 = ((uint8_t) 0x18),
5858
OFFSET_HALL_ANGLE_3_180 = ((uint8_t) 0x19),
5959
OFFSET_HALL_ANGLE_1_240 = ((uint8_t) 0x1A),
60-
OFFSET_HALL_ANGLE_5_300 = ((uint8_t) 0x1B)
60+
OFFSET_HALL_ANGLE_5_300 = ((uint8_t) 0x1B),
61+
62+
OFFSET_BATTERY_VOLTAGE_CALIB = ((uint8_t) 0x1C)
6163

6264
} BO_EEPROM_OFFSETS;
6365

BOdisplay.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void signPackage(void) {
111111
ui8_tx_buffer_counter++;
112112
}
113113

114-
void addConfigStateInfos(void) {
114+
void addConfigStateInfosA(void) {
115115

116116
// float casts might be costly but they are only requested once every 10 seconds
117117
addPayload(CODE_ERPS_FACTOR, (uint16_t) (((float) wheel_circumference) / ((float) GEAR_RATIO)));
@@ -137,14 +137,22 @@ void addConfigStateInfos(void) {
137137
addPayload(CODE_MAX_BAT_CURRENT, ui16_battery_current_max_value);
138138
addPayload(CODE_CORRECTION_AT_ANGLE, ui8_correction_at_angle);
139139

140+
// 7 more elements left/avail (max30)
141+
142+
}
143+
144+
void addConfigStateInfosB(void) {
145+
140146
addPayload(CODE_HALL_ANGLE_4_0, ui8_s_hall_angle4_0);
141147
addPayload(CODE_HALL_ANGLE_6_60, ui8_s_hall_angle6_60);
142148
addPayload(CODE_HALL_ANGLE_2_120, ui8_s_hall_angle2_120);
143149
addPayload(CODE_HALL_ANGLE_3_180, ui8_s_hall_angle3_180);
144150
addPayload(CODE_HALL_ANGLE_1_240, ui8_s_hall_angle1_240);
145151
addPayload(CODE_HALL_ANGLE_5_300, ui8_s_hall_angle5_300);
146-
// 1 more elements left/avail (max30)
147152

153+
addPayload(CODE_ADC_BATTERY_VOLTAGE_CALIB, ui8_s_battery_voltage_calibration);
154+
155+
// 23 more elements left/avail (max30)
148156
}
149157

150158
void addHallStateInfos(void) {
@@ -238,7 +246,11 @@ void gatherDynamicPayload(uint8_t function) {
238246

239247
void gatherStaticPayload(uint8_t function) {
240248
switch (function) {
241-
case FUN_CONFIG_INFOS:addConfigStateInfos();
249+
case FUN_CONFIG_INFOS_A:
250+
addConfigStateInfosA();
251+
break;
252+
case FUN_CONFIG_INFOS_B:
253+
addConfigStateInfosB();
242254
break;
243255
default:
244256
addPayload(CODE_ERROR, CODE_ERROR);
@@ -285,6 +297,13 @@ void digestConfigRequest(uint8_t configAddress, uint8_t requestedCodeLowByte, ui
285297
}
286298
addPayload(requestedCodeLowByte, ui8_current_cal_a);
287299
break;
300+
case CODE_ADC_BATTERY_VOLTAGE_CALIB:
301+
ui8_s_battery_voltage_calibration = requestedValue;
302+
if (configAddress == EEPROM_ADDRESS) {
303+
eeprom_write(OFFSET_BATTERY_VOLTAGE_CALIB, requestedValue);
304+
}
305+
addPayload(requestedCodeLowByte, ui8_s_battery_voltage_calibration);
306+
break;
288307
case CODE_ASSIST_LEVEL:
289308
ui8_assistlevel_global = requestedValue;
290309
if (configAddress == EEPROM_ADDRESS) {

BOdisplay.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ typedef enum {
2424
FUN_ERROR = ((uint8_t) 0x66),
2525
FUN_DETAIL_INFOS = ((uint8_t) 0x40),
2626
FUN_BASIC_INFOS = ((uint8_t) 0x41),
27-
FUN_CONFIG_INFOS = ((uint8_t) 0x42),
27+
FUN_CONFIG_INFOS_A = ((uint8_t) 0x42),
2828
FUN_HALL_INFOS = ((uint8_t) 0x43),
29-
FUN_SET_CONFIG = ((uint8_t) 0x44)
29+
FUN_SET_CONFIG = ((uint8_t) 0x44),
30+
FUN_CONFIG_INFOS_B = ((uint8_t) 0x45),
31+
FUN_NOOP = ((uint8_t) 0x46)
3032
} BO_FUN_CODES;
3133

3234
typedef enum {
@@ -71,6 +73,8 @@ typedef enum {
7173

7274
CODE_ER_SPEED_HIGH_BYTE = ((uint8_t) 0xCA),
7375
CODE_ER_SPEED = ((uint8_t) 0xCB),
76+
77+
CODE_ADC_BATTERY_VOLTAGE_CALIB = ((uint8_t) 0xCC),
7478

7579
CODE_SUM_TORQUE = ((uint8_t) 0xD0),
7680
CODE_SETPOINT = ((uint8_t) 0xD1),

OSEC Parameter Configurator.jar

178 Bytes
Binary file not shown.

config.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define BATTERY_CURRENT_MAX_VALUE 150L
2020
#define PHASE_CURRENT_MAX_VALUE 300L
2121
#define REGEN_CURRENT_MAX_VALUE 50L
22-
#define MOTOR_ROTOR_DELTA_PHASE_ANGLE_RIGHT 198
22+
#define MOTOR_ROTOR_DELTA_PHASE_ANGLE_RIGHT 197
2323
#define current_cal_a 46
2424
#define TEMP_CAL_A 1.6
2525
#define TEMP_CAL_B -110.4
@@ -39,19 +39,20 @@
3939
#define PAS_THRESHOLD 1.9
4040
#define RAMP_START 64000
4141
#define limit_with_throttle_override 35
42-
#define CORRECTION_AT_ANGLE 90
42+
#define CORRECTION_AT_ANGLE 85
4343
#define PWM_CYCLES_SECOND 15625L
4444
#define SPEEDSENSOR_INTERNAL
45-
#define ANGLE_4_0 0
46-
#define ANGLE_6_60 42
47-
#define ANGLE_2_120 85
48-
#define ANGLE_3_180 127
45+
#define ANGLE_4_0 1
46+
#define ANGLE_6_60 38
47+
#define ANGLE_2_120 82
48+
#define ANGLE_3_180 128
4949
#define BLUOSEC
50-
#define ANGLE_1_240 170
51-
#define ANGLE_5_300 212
50+
#define ANGLE_1_240 166
51+
#define ANGLE_5_300 210
5252
#define TQS_CALIB 0.0
5353
#define ACA 4766
5454
#define EEPROM_NOINIT // eeprom will not be cleared
55-
#define EEPROM_INIT_MAGIC_BYTE 53 // makes sure (chance of fail 1/255) eeprom is invalidated after flashing new config
55+
#define EEPROM_INIT_MAGIC_BYTE 131 // makes sure (chance of fail 1/255) eeprom is invalidated after flashing new config
56+
#define ADC_BATTERY_VOLTAGE_K 68
5657

5758
#endif /* CONFIG_H_ */

display.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void send_message() {
8888
#endif
8989

9090
// calc battery pack state of charge (SOC)
91-
ui16_battery_volts = ((uint16_t) ui8_adc_read_battery_voltage()) * ((uint16_t) ADC_BATTERY_VOLTAGE_K);
91+
ui16_battery_volts = ((uint16_t) ui8_adc_read_battery_voltage()) * ((uint16_t) ui8_s_battery_voltage_calibration);
9292
if (ui16_battery_volts > ((uint16_t) BATTERY_PACK_VOLTS_80)) {
9393
ui8_battery_soc = 16;
9494
}// 4 bars | full

experimental settings/20181014-135511MESZ.ini renamed to experimental settings/20181015-232442MESZ.ini

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
150
1010
300
1111
50
12-
198
12+
197
1313
46
1414
1.6
1515
-110.4
@@ -30,21 +30,22 @@
3030
false
3131
64000
3232
35
33-
90
33+
85
3434
false
3535
true
3636
false
3737
false
3838
true
3939
false
4040
false
41-
0
42-
42
43-
85
44-
127
41+
1
42+
38
43+
82
44+
128
4545
true
4646
false
47-
170
48-
212
47+
166
48+
210
4949
0.0
5050
4766
51+
68

main.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@
3939
#define LI_ION_CELL_VOLTS_0 3.27
4040
#define LI_ION_CELL_VOLTS_MIN 3.10
4141

42-
#define BATTERY_PACK_VOLTS_100 (LI_ION_CELL_VOLTS_100 * BATTERY_LI_ION_CELLS_NUMBER) * 256
43-
#define BATTERY_PACK_VOLTS_80 (LI_ION_CELL_VOLTS_80 * BATTERY_LI_ION_CELLS_NUMBER) * 256
44-
#define BATTERY_PACK_VOLTS_60 (LI_ION_CELL_VOLTS_60 * BATTERY_LI_ION_CELLS_NUMBER) * 256
45-
#define BATTERY_PACK_VOLTS_40 (LI_ION_CELL_VOLTS_40 * BATTERY_LI_ION_CELLS_NUMBER) * 256
46-
#define BATTERY_PACK_VOLTS_20 (LI_ION_CELL_VOLTS_20 * BATTERY_LI_ION_CELLS_NUMBER) * 256
47-
#define BATTERY_PACK_VOLTS_0 (LI_ION_CELL_VOLTS_0 * BATTERY_LI_ION_CELLS_NUMBER) * 256
48-
49-
#define ADC_BATTERY_VOLTAGE_K 73 // 0.272 << 8
42+
#define BATTERY_PACK_VOLTS_100 (LI_ION_CELL_VOLTS_100 * BATTERY_LI_ION_CELLS_NUMBER) * 255
43+
#define BATTERY_PACK_VOLTS_80 (LI_ION_CELL_VOLTS_80 * BATTERY_LI_ION_CELLS_NUMBER) * 255
44+
#define BATTERY_PACK_VOLTS_60 (LI_ION_CELL_VOLTS_60 * BATTERY_LI_ION_CELLS_NUMBER) * 255
45+
#define BATTERY_PACK_VOLTS_40 (LI_ION_CELL_VOLTS_40 * BATTERY_LI_ION_CELLS_NUMBER) * 255
46+
#define BATTERY_PACK_VOLTS_20 (LI_ION_CELL_VOLTS_20 * BATTERY_LI_ION_CELLS_NUMBER) * 255
47+
#define BATTERY_PACK_VOLTS_0 (LI_ION_CELL_VOLTS_0 * BATTERY_LI_ION_CELLS_NUMBER) * 255
5048

5149
// Phase current: max of +-15.5 amps
5250
// 512 --> 15.5 amps

0 commit comments

Comments
 (0)