Skip to content

Commit

Permalink
verified adc
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Donahue committed Apr 10, 2024
1 parent d5ad534 commit 5734323
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
6 changes: 3 additions & 3 deletions Core/Inc/bmsConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 15 additions & 12 deletions Core/Src/compute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 */

Expand Down
8 changes: 6 additions & 2 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 5734323

Please sign in to comment.