Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major feature implementation: Charging, balancing, precharge, RTCC
- Loading branch information
1 parent
2ed99f0
commit 4e98857
Showing
32 changed files
with
1,000 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# STM32F3 STDPERIPH files. | ||
STM32SRC = ${CHIBIOS}/ext/stdperiph_stm32f3/src/stm32f30x_flash.c \ | ||
${CHIBIOS}/ext/stdperiph_stm32f3/src/stm32f30x_tim.c \ | ||
${CHIBIOS}/ext/stdperiph_stm32f3/src/stm32f30x_rcc.c | ||
${CHIBIOS}/ext/stdperiph_stm32f3/src/stm32f30x_rcc.c \ | ||
${CHIBIOS}/ext/stdperiph_stm32f3/src/stm32f30x_dma.c | ||
|
||
STM32INC = ${CHIBIOS}/ext/stdperiph_stm32f3/inc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include "analog.h" | ||
#include "hal.h" | ||
#include "hw_conf.h" | ||
#include "faults.h" | ||
#include <math.h> | ||
|
||
static const ADCConversionGroup adc3 = { | ||
FALSE, | ||
2, | ||
NULL, | ||
NULL, | ||
0, /* CFGR */ | ||
ADC_TR(0, 4095), /* TR1 */ | ||
{ /* SMPR[2] */ | ||
0, | ||
0 | ||
}, | ||
{ /* SQR[4] */ | ||
ADC_SQR1_SQ1_N(CHG_SENSE_CHANNEL) | ADC_SQR1_SQ2_N(DSG_SENSE_CHANNEL), | ||
0, | ||
0, | ||
0 | ||
} | ||
}; | ||
|
||
static const ADCConversionGroup adc4 = { | ||
FALSE, | ||
1, | ||
NULL, | ||
NULL, | ||
0, /* CFGR */ | ||
ADC_TR(0, 4095), /* TR1 */ | ||
{ /* SMPR[2] */ | ||
0, | ||
0 | ||
}, | ||
{ /* SQR[4] */ | ||
ADC_SQR1_SQ1_N(TEMP_SENSE_CHANNEL), | ||
0, | ||
0, | ||
0 | ||
} | ||
}; | ||
|
||
static volatile uint16_t charger_input_voltage; | ||
static volatile uint16_t thermistor; | ||
static volatile uint16_t discharge_voltage; | ||
|
||
void analog_init(void) | ||
{ | ||
adcStart(&ADCD3, NULL); | ||
adcStart(&ADCD4, NULL); | ||
adcsample_t samples[2]; | ||
adcConvert(&ADCD3, &adc3, samples, 1); | ||
charger_input_voltage = samples[0]; | ||
discharge_voltage = samples[1]; | ||
} | ||
|
||
void analog_update(void) | ||
{ | ||
adcsample_t samples3[2]; | ||
adcConvert(&ADCD3, &adc3, samples3, 1); | ||
charger_input_voltage = samples3[0]; | ||
discharge_voltage = samples3[1]; | ||
adcsample_t samples4[1]; | ||
adcConvert(&ADCD4, &adc4, samples4, 1); | ||
thermistor = samples4[0]; | ||
if (analog_temperature() > 100) | ||
faults_set_fault(FAULT_BOARD_TEMP); | ||
} | ||
|
||
float analog_charger_input_voltage(void) | ||
{ | ||
return charger_input_voltage / 4095.0 * 3.3 * (39000.0 + 18000.0 + 4700.0) / 4700.0; | ||
} | ||
|
||
float analog_temperature(void) | ||
{ | ||
return (1.0 / ((logf(((4095.0 * 10000.0) / thermistor - 10000.0) / 10000.0) / 3434.0) + (1.0 / 298.15)) - 273.15); | ||
} | ||
|
||
float analog_discharge_voltage(void) | ||
{ | ||
return discharge_voltage * (3.3 / 4095.0) * (200000.0 + 100 + 2500 + 10000.0) / 10000.0; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef _ANALOG_H_ | ||
#define _ANALOG_H_ | ||
|
||
#include "ch.h" | ||
|
||
void analog_init(void); | ||
void analog_update(void); | ||
float analog_charger_input_voltage(void); | ||
float analog_temperature(void); | ||
float analog_discharge_voltage(void); | ||
|
||
#endif /* _ANALOG_H_ */ |
Oops, something went wrong.