Skip to content

Commit

Permalink
csa add bus_voltage and nominal_voltage
Browse files Browse the repository at this point in the history
  • Loading branch information
dukelec committed Jul 18, 2024
1 parent 98079b7 commit 7578911
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
4 changes: 3 additions & 1 deletion mdrv_fw/usr/app_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ typedef struct {
bool anticogging_en;
float anticogging_max_val[2];

uint8_t _reserved[28];
float nominal_voltage;
uint8_t _reserved[24];

// end of flash
#define _end_save state
Expand Down Expand Up @@ -157,6 +158,7 @@ typedef struct {
uint8_t _reserved2[8];
float sen_speed_avg;
float sen_rpm_avg;
float bus_voltage;

} csa_t; // config status area

Expand Down
19 changes: 4 additions & 15 deletions mdrv_fw/usr/app_motor.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ void app_motor_init(void)
pid_f_init(&csa.pid_speed, true);
pid_i_init(&csa.pid_pos, true);
cdn_sock_bind(&sock_raw_dbg);
csa.bus_voltage = csa.nominal_voltage;
}

void app_motor_routine(void)
Expand Down Expand Up @@ -584,27 +585,15 @@ void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc)
raw_dbg(0);
csa.loop_cnt++;

#if 1
if (!LL_ADC_REG_IsConversionOngoing(hadc1.Instance)) {

//HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
int32_t adc_temperature = HAL_ADC_GetValue(&hadc1);
uint32_t adc_dc = HAL_ADC_GetValue(&hadc2);

//HAL_ADC_PollForConversion(&hadc2, HAL_MAX_DELAY);
int32_t adc_dc = HAL_ADC_GetValue(&hadc2);

#if 0
static uint32_t t_last = 0;
if (get_systick() - t_last > 1000) {
t_last = get_systick();
d_info("temperature: %d, dc: %d\n", adc_temperature, adc_dc);
}
#endif
float v_dc = (adc_dc / 4095.0f * 3.3f) / 4.7f * (4.7f + 75);
csa.bus_voltage += (v_dc - csa.bus_voltage) * 0.001f;

LL_ADC_REG_StartConversion(hadc1.Instance);
//delay_systick(10);
}
#endif

uint16_t enc_check = encoder_read();
if (enc_check != csa.ori_encoder)
Expand Down
4 changes: 4 additions & 0 deletions mdrv_fw/usr/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ const csa_t csa_dft = {
.cali_current = 200,
//.cali_angle_step = 0.003179136f // @ ic-MU3 25KHz spi
//.cali_angle_step = 0

.nominal_voltage = 12.0f
};

csa_t csa;
Expand Down Expand Up @@ -327,6 +329,7 @@ void csa_list_show(void)
CSA_SHOW(0, cali_encoder_en, "");
CSA_SHOW(0, anticogging_en, "");
CSA_SHOW(0, anticogging_max_val, "");
CSA_SHOW(0, nominal_voltage, "");
d_info("\n"); debug_flush(true);

CSA_SHOW(0, state, "0: stop, 1: calibrate, 2: cur loop, 3: speed loop, 4: pos loop, 5: t_curve");
Expand Down Expand Up @@ -374,6 +377,7 @@ void csa_list_show(void)
CSA_SHOW(0, cal_v_sq_avg, "");
CSA_SHOW(0, sen_speed_avg, "");
CSA_SHOW(0, sen_rpm_avg, "");
CSA_SHOW(0, bus_voltage, "");
d_info("\n"); debug_flush(true);

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

0 comments on commit 7578911

Please sign in to comment.