Skip to content

Commit d430d8d

Browse files
committed
Changed to integer arithemtics and right shift
1 parent 99060ef commit d430d8d

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

ACAcontrollerState.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ float flt_s_pid_gain_p = 0.5;
4141
float flt_s_pid_gain_i = 0.2;
4242
float flt_s_motor_constant = 1.5;
4343
float flt_torquesensorCalibration = 0.0;
44+
uint32_t uint32_torquesensorCalibration = 0;
4445
uint16_t ui16_s_ramp_end = 1500;
4546
uint16_t ui16_s_ramp_start = 7000;
4647
uint8_t ui8_s_motor_angle = 214;
@@ -184,6 +185,7 @@ void controllerstate_init(void) {
184185
ui8_current_cal_a = current_cal_a;
185186
ui8_correction_at_angle = CORRECTION_AT_ANGLE;
186187
flt_torquesensorCalibration = TQS_CALIB;
188+
uint32_torquesensorCalibration = (uint32_t)flt_torquesensorCalibration;
187189
ui8_gear_ratio = GEAR_RATIO;
188190

189191
// read in overrides from eeprom if they are > 0, assuming 0s are uninitialized
@@ -233,7 +235,9 @@ void controllerstate_init(void) {
233235
eepromVal = eeprom_read(OFFSET_PAS_TRESHOLD);
234236
if (eepromVal > 0) flt_s_pas_threshold = int2float(eepromVal, 4.0);
235237
eepromVal = eeprom_read(OFFSET_TQ_CALIB);
236-
if (eepromVal > 0) flt_torquesensorCalibration = int2float(eepromVal, 8000.0);
238+
if (eepromVal > 0){ flt_torquesensorCalibration = int2float(eepromVal, 8000.0);
239+
uint32_torquesensorCalibration = (uint32_t)flt_torquesensorCalibration;
240+
}
237241
eepromVal = eeprom_read(OFFSET_PID_GAIN_P);
238242
if (eepromVal > 0) flt_s_pid_gain_p = int2float(eepromVal, 2.0);
239243
eepromVal = eeprom_read(OFFSET_PID_GAIN_I);

ACAcontrollerState.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ extern uint8_t ui8_PAS_update_call_when_inactive_counter;
119119

120120

121121
extern float flt_torquesensorCalibration;
122+
extern uint32_t uint32_torquesensorCalibration;
122123
extern float flt_s_pas_threshold;
123124
extern float flt_s_pid_gain_p;
124125
extern float flt_s_pid_gain_i;

ACAsetPoint.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,23 +233,18 @@ uint16_t aca_setpoint(uint16_t ui16_time_ticks_between_pas_interrupt, uint16_t s
233233
}
234234
} else { // torque sensor mode
235235

236-
float_temp = (float) ui16_sum_torque;
237-
float_temp *= ((float) ui8_assist_percent_actual / 100.0);
238236

239-
if (flt_torquesensorCalibration != 0.0) {
240-
// flt_torquesensorCalibration is >fummelfactor * NUMBER_OF_PAS_MAGS * 64< (64 cause of <<6)
241-
float_temp *= flt_torquesensorCalibration / ((float) ui16_time_ticks_between_pas_interrupt_smoothed); // influence of cadence
242-
//printf("%lu, %u, %u, %u \r\n", uint32_current_target, ui16_sum_torque,(uint16_t) float_temp, ui16_time_ticks_between_pas_interrupt_smoothed );
237+
//erst mal alles aufmultiplizieren, damit beim Teilen was über 1 übrig bleibt. Bitte mal überschlagen, ob die int32 da nicht überlaufen kann...
238+
uint32_temp = ui16_sum_torque;
239+
uint32_temp *= ui8_assist_percent_actual;
240+
uint32_temp *= ui16_battery_current_max_value;
241+
uint32_temp *= uint32_torquesensorCalibration;
243242

244-
}
243+
uint32_temp /= ui16_time_ticks_between_pas_interrupt_smoothed; // hier lässt sich die geteilt-Operation nicht vermeiden :-(
245244

246-
//increase power linear with speed for convenient commuting :-)
247-
if ((ui16_aca_flags & SPEED_INFLUENCES_TORQUESENSOR) == SPEED_INFLUENCES_TORQUESENSOR) {
248-
float_temp *= (1.0 + ((float) ui16_virtual_erps_speed) / ((float) (ui16_speed_kph_to_erps_ratio * ((float) ui8_speedlimit_kph)) / 100.0)); // influence of current speed based on base speed limit
249-
}
250-
if(PAS_is_active)
251-
uint32_current_target = (uint32_t) (float_temp * (float) (ui16_battery_current_max_value) / 255.0 + (float) ui16_current_cal_b);
252-
else uint32_current_target =(uint32_t) ui16_current_cal_b;
245+
if(PAS_is_active)
246+
uint32_current_target = uint32_temp >>8 + ui16_current_cal_b; //right shift 15 fasst die Operationen /100 (annähernd >>7) aus der assist_percent und /255 ( >>8) aus dem battery_current max zusammen, ist nicht ganz korrekt, ggf. nur >>14 nehmen -->/(256*128) vs. /(256*64)
247+
else uint32_current_target =(uint32_t) ui16_current_cal_b;
253248

254249

255250
controll_state_temp += 4;

BOdisplay.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ void digestConfigRequest(uint8_t configAddress, uint8_t requestedCodeLowByte, ui
533533
break;
534534
case CODE_TQ_CALIB:
535535
flt_torquesensorCalibration = int2float(requestedValue, 8000.0);
536+
uint32_torquesensorCalibration = (uint32_t)flt_torquesensorCalibration;
536537
if (configAddress == EEPROM_ADDRESS) {
537538
eeprom_write(OFFSET_TQ_CALIB, requestedValue);
538539
}

0 commit comments

Comments
 (0)