From 5734323bbadc51e0d8e678e901c256b280384438 Mon Sep 17 00:00:00 2001 From: Dylan Donahue Date: Wed, 10 Apr 2024 11:03:40 -0400 Subject: [PATCH] verified adc --- Core/Inc/bmsConfig.h | 6 +++--- Core/Src/compute.c | 27 +++++++++++++++------------ Core/Src/main.c | 8 ++++++-- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/Core/Inc/bmsConfig.h b/Core/Inc/bmsConfig.h index 5cf69df..b070d58 100644 --- a/Core/Inc/bmsConfig.h +++ b/Core/Inc/bmsConfig.h @@ -2,9 +2,9 @@ #define BMS_CONFIG_H // Hardware definition -#define NUM_SEGMENTS 4 -#define NUM_CHIPS NUM_SEGMENTS*2 -#define NUM_CELLS_PER_CHIP 9 +#define NUM_SEGMENTS 6 +#define NUM_CHIPS NUM_SEGMENTS* 2 +#define NUM_CELLS_PER_CHIP 10 #define NUM_THERMS_PER_CHIP 32 #define NUM_RELEVANT_THERMS 5 diff --git a/Core/Src/compute.c b/Core/Src/compute.c index fff3d8e..8cda8a7 100644 --- a/Core/Src/compute.c +++ b/Core/Src/compute.c @@ -69,7 +69,8 @@ uint8_t compute_init() HAL_TIM_PWM_Start(&htim8, fan_channels[FAN5]); HAL_TIM_PWM_Start(&htim8, fan_channels[FAN6]); - HAL_ADC_Start_DMA(&hadc1, adc_values, 2); + //HAL_ADC_Start(&hadc1); + //HAL_ADC_Start_DMA(&hadc1, adc_values, 2); return 0; @@ -165,25 +166,27 @@ int16_t compute_get_pack_current() /* starting equation : Vout = Vref + Voffset + (Gain * Ip) */ - float ref_voltage = -1; - float vout = -1; + //float ref_voltage = -1; + //float vout = -1; - if (!HAL_DMA_PollForTransfer(&hdma_adc1, HAL_DMA_FULL_TRANSFER, HAL_MAX_DELAY)) - { - ref_voltage = adc_values[1] * 2.5 / MAX_ADC_RESOLUTION; - vout = adc_values[0] * 3.3 / MAX_ADC_RESOLUTION; - } + // if (!HAL_DMA_PollForTransfer(&hdma_adc1, HAL_DMA_FULL_TRANSFER, HAL_MAX_DELAY)) + // { + // ref_voltage = 2.5;//adc_values[1] * 2.5 / MAX_ADC_RESOLUTION; + // vout = adc_values[0] * 3.3 / MAX_ADC_RESOLUTION; + // } + // remove once DMA verified working, along with functions themselves - // float ref_voltage = read_ref_voltage(); - // float vout = read_current(); + float ref_voltage = read_ref_voltage(); + float vout = read_vout(); + vout *= 1000; // convert to mV - if (ref_voltage == -1 || vout == -1) return -1; + //if (ref_voltage == -1 || vout == -1) return -1; int16_t current = (vout - ref_voltage - OFFSET) / (GAIN / 1000); // convert to V - return -current; + return vout; /* TEMP keep last years math until above is verified */ diff --git a/Core/Src/main.c b/Core/Src/main.c index 94cf6f6..f2f2b68 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -267,7 +267,11 @@ int main(void) * Not state specific */ segment_retrieve_data(acc_data->chip_data); - acc_data->pack_current = compute_get_pack_current(); + acc_data->pack_current = (int16_t)compute_get_pack_current(); + //volatile float temp = compute_get_pack_current(); + printf("Pack Current: %d\r\n", acc_data->pack_current); + + /* Perform calculations on the data in the frame */ analyzer_push(acc_data); @@ -282,7 +286,7 @@ int main(void) HAL_GPIO_WritePin(Watchdog_Out_GPIO_Port, Watchdog_Out_Pin, GPIO_PIN_RESET); #ifdef DEBUG_STATS - print_bms_stats(acc_data); + //print_bms_stats(acc_data); #endif // TODO - possibly optimize timing, every loop might be excessive