Page 1 of 1
Another Dumb Damien Software question
Posted: Tue Nov 03, 2020 6:23 pm
by Jack Bauer
So, I've been exploring using the STM32 Arduino core and have managed to create and populate an array of 96 cell voltages (yay me!). Now, what I need to do is extract the highest and lowest cell voltages and calculate the delta between the two. Any pointers much appreciated:)
Re: Another Dumb Damien Software question
Posted: Tue Nov 03, 2020 6:51 pm
by arber333
Jack Bauer wrote: ↑Tue Nov 03, 2020 6:23 pm
So, I've been exploring using the STM32 Arduino core and have managed to create and populate an array of 96 cell voltages (yay me!). Now, what I need to do is extract the highest and lowest cell voltages and calculate the delta between the two. Any pointers much appreciated:)
I dont know if thiss will help you, but it was done in 2013 by Neville H. from NZ. I used his code in my BMS for quite some years.
Code was written for Pic16F. Please mind the negative logic

.
You can see my complete BMS here:
viewtopic.php?f=13&t=61
First you code the value of your ADC to value of single byte, less than FF. Then you send it across twisted wire to your daisy chain master and decode it back to put it into an array. Next you find cell that is higher than the rest and the one lower than the rest and superimpose them into two variables. The same for temp value. You still need to declare those values in your setup.
/* find max and min values of volts and temp - also cell numbers
Note that V_Min, V_Max, HiCell and LoCell all refer to the array values
not the actual cell voltages ie everything is upside down!*/
BattVolts=0; //initialise each time through
i=0;
while(Volts
!=0xFF){
if(Volts>V_Max){
V_Max=Volts;
HiCell=i;
}
if(Volts<V_Min){
V_Min=Volts;
LoCell=i;
}
BattVolts=BattVolts+Convert_Volts(Volts); // calculate total battery volts
if(Temp>T_Max)
T_Max=Temp;
if(Temp<T_Min)
T_Min=Temp;
i++;
}
Number_of_Cells=i;
if(CommsTmr){
output_high(CHRG_OFF); //Charger off if comms are off
delay_ms(150);
lcdPutC("\fNo comms!");
output_high(ALARM_LED);
delay_ms(150);
}
else{
v=Convert_Volts(V_Min);
MyItoA(v,LCDBuf);
Fmt2Point(LCDBuf);//format it with 2 decimal places-round down
lcdPutC("\fVh ");
DisplayIt(LCDBuf);
v=Convert_Volts(V_Max);
MyItoA(v,LCDBuf);
Fmt2Point(LCDBuf);
lcdPutC(" Vl ");
DisplayIt(LCDBuf);
lcdPutC("\n");
switch(DisplayMode){
case 0: v=Convert_Temp(T_Min);
MyItoA(v,LCDBuf);
lcdPutC("Th ");
DisplayIt(LCDBuf);
v=Convert_Temp(T_Max);
MyItoA(v,LCDBuf);
lcdPutC(" Tl ");
DisplayIt(LCDBuf);
break;
case 1: v=BattVolts/100;
MyItoA(v,LCDBuf);
Fmt1Point(LCDBuf);//format it with 1 decimal place-round down
lcdPutC("Vt ");
DisplayIt(LCDBuf);
MyItoA(LoCell,LCDBuf);
lcdPutC(" h");
DisplayIt(LCDBuf);
MyItoA(HiCell,LCDBuf);
lcdPutC(" l");
DisplayIt(LCDBuf);
break;
case 2: lcdPutC("Balancing: ");
MyItoA(CellsOn,LCDBuf);
DisplayIt(LCDBuf);
break;
default: lcdPutC("Error 1");break;
}
}
Re: Another Dumb Damien Software question
Posted: Tue Nov 03, 2020 7:01 pm
by muehlpower
uint16_t Max = 0;
uint16_t Min = 10000;
uint16_t MaxIndex = 0;
uint16_t MinIndex= 0;
for (int c = 0; c < 96; c++) //cell
{
if (Max < Cell[c])
{
Max = Cell[c];
MaxIndex = c;
}
if (Min > Cell[c])
{
Min = Cell[c];
MinIndex = c;
}
}
delta = Max -Min;
Re: Another Dumb Damien Software question
Posted: Tue Nov 03, 2020 7:09 pm
by mdrobnak
muehlpower wrote: ↑Tue Nov 03, 2020 7:01 pm
Code: Select all
uint16_t Max = 0;
uint16_t Min = 10000;
uint16_t MaxIndex = 0;
uint16_t MinIndex= 0;
for (int c = 0; c < 96; c++) //cell
{
if (Max < Cell[c])
{
Max = Cell[c];
MaxIndex = c;
}
if (Min > Cell[c])
{
Min = Cell[c];
MinIndex = c;
}
}
delta = Max -Min;
Exactly this.
However, I'd make it more generic:
Code: Select all
const uint16_t MAX_CELL_COUNT = 96;
for... c < MAX_CELL_COUNT...
-Matt
Re: Another Dumb Damien Software question
Posted: Tue Nov 03, 2020 7:30 pm
by Jack Bauer
Thanks guys:)
Re: Another Dumb Damien Software question
Posted: Tue Nov 03, 2020 8:38 pm
by tom91
You could have just dug in the SimpBMS coding.
What happens is;
Each slave is a seperate array/variable set.
This way there is a min/max for Voltage and Temperatures
For each "debug line", cyclically called, it generates the same as it calls the info up anyway, this then generates min max values for voltage and temperature per slave and then looks if it is the highest or lowest.
Same time this is happening you can run more numbers.

Got to love running numbers, since I run it on a Teensy overhead is no problem. This way you get voltage roll up and averages for voltage and temperatures.
Most of this code is in here :
https://github.com/tomdebree/TeslaBMSV2 ... anager.cpp
Re: Another Dumb Damien Software question
Posted: Tue Nov 03, 2020 9:19 pm
by MattsAwesomeStuff
Jack Bauer wrote: ↑Tue Nov 03, 2020 6:23 pmhave managed to create and populate an array of 96 cell voltages
This is the least-secret secret-project ever :p
I for one welcome it with enthusiasm.