Fixed initial condition bug

- the initial condition for the Battery and Board temperature was wrongly set
- the filter is fixdt(1,32,16), so the shift should be by 16 bits.
This commit is contained in:
EmanuelFeru 2020-06-22 20:21:18 +02:00
parent b8d9c8c8bc
commit ac90ed1b6b
3 changed files with 6 additions and 6 deletions

View File

@ -77,7 +77,7 @@ static int16_t offsetdcl = 2000;
static int16_t offsetdcr = 2000;
int16_t batVoltage = (400 * BAT_CELLS * BAT_CALIB_ADC) / BAT_CALIB_REAL_VOLTAGE;
static int32_t batVoltageFixdt = (400 * BAT_CELLS * BAT_CALIB_ADC) / BAT_CALIB_REAL_VOLTAGE << 20; // Fixed-point filter output initialized at 400 V*100/cell = 4 V/cell converted to fixed-point
static int32_t batVoltageFixdt = (400 * BAT_CELLS * BAT_CALIB_ADC) / BAT_CALIB_REAL_VOLTAGE << 16; // Fixed-point filter output initialized at 400 V*100/cell = 4 V/cell converted to fixed-point
// =================================
// DMA interrupt frequency =~ 16 kHz

View File

@ -192,7 +192,7 @@ int main(void) {
int16_t speedL = 0, speedR = 0;
int16_t lastSpeedL = 0, lastSpeedR = 0;
int32_t board_temp_adcFixdt = adc_buffer.temp << 20; // Fixed-point filter output initialized with current ADC converted to fixed-point
int32_t board_temp_adcFixdt = adc_buffer.temp << 16; // Fixed-point filter output initialized with current ADC converted to fixed-point
int16_t board_temp_adcFilt = adc_buffer.temp;
int16_t board_temp_deg_c;

View File

@ -1186,10 +1186,10 @@ void sideboardSensors(uint8_t sensors) {
/* =========================== Filtering Functions =========================== */
/* Low pass filter fixed-point 32 bits: fixdt(1,32,20)
* Max: 2047.9375
* Min: -2048
* Res: 0.0625
/* Low pass filter fixed-point 32 bits: fixdt(1,32,16)
* Max: 32767.99998474121
* Min: -32768
* Res: 1.52587890625e-05
*
* Inputs: u = int16 or int32
* Outputs: y = fixdt(1,32,16)