Skip to content

Commit

Permalink
show ntc temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
dukelec committed Sep 6, 2024
1 parent 79196f5 commit 750ced0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions mdrv_fw/usr/app_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ typedef struct {
float sen_speed_avg;
float sen_rpm_avg;
float bus_voltage;
float temperature;

} csa_t; // config status area

Expand Down
8 changes: 7 additions & 1 deletion mdrv_fw/usr/app_motor.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,11 +609,17 @@ void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc)
csa.loop_cnt++;

if (!LL_ADC_REG_IsConversionOngoing(hadc1.Instance)) {
int32_t adc_temperature = HAL_ADC_GetValue(&hadc1);
uint32_t adc_temperature = HAL_ADC_GetValue(&hadc1);
uint32_t adc_dc = HAL_ADC_GetValue(&hadc2);

float v_dc = (adc_dc / 4095.0f * 3.3f) / 4.7f * (4.7f + 75);
csa.bus_voltage += (v_dc - csa.bus_voltage) * 0.001f;

#define _B 3970
float r_ntc = (10000.0f * adc_temperature) / (4095 - adc_temperature);
// pull-up: 10K r_ntc = 100K -> @ 25°C
float temperature = (1.0f / ((1.0f / _B) * logf(r_ntc / 100000) + (1.0f / (25 + 273.15f))) - 273.15f);
csa.temperature += (temperature - csa.temperature) * 0.001f;

LL_ADC_REG_StartConversion(hadc1.Instance);
}
Expand Down
1 change: 1 addition & 0 deletions mdrv_fw/usr/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ void csa_list_show(void)
CSA_SHOW(0, sen_speed_avg, "");
CSA_SHOW(0, sen_rpm_avg, "");
CSA_SHOW(0, bus_voltage, "");
CSA_SHOW(0, temperature, "");
d_info("\n"); debug_flush(true);

d_info("\x1b[92mColor Test...\x1b[0m\n");
Expand Down

0 comments on commit 750ced0

Please sign in to comment.