Another Dumb Damien Software question

Introduction and miscellaneous that we haven't created categories for, yet
Post Reply
User avatar
Jack Bauer
Posts: 3563
Joined: Wed Dec 12, 2018 5:24 pm
Location: Ireland
Has thanked: 1 time
Been thanked: 87 times
Contact:

Another Dumb Damien Software question

Post 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:)
I'm going to need a hacksaw
arber333
Posts: 3265
Joined: Mon Dec 24, 2018 1:37 pm
Location: Slovenia
Has thanked: 80 times
Been thanked: 234 times
Contact:

Re: Another Dumb Damien Software question

Post 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;
}
}
User avatar
muehlpower
Posts: 575
Joined: Fri Oct 11, 2019 10:51 am
Location: Germany Fürstenfeldbruck
Has thanked: 12 times
Been thanked: 103 times

Re: Another Dumb Damien Software question

Post 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;
User avatar
mdrobnak
Posts: 692
Joined: Thu Mar 05, 2020 5:08 pm
Location: Colorado, United States
Has thanked: 1 time
Been thanked: 5 times

Re: Another Dumb Damien Software question

Post 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
User avatar
Jack Bauer
Posts: 3563
Joined: Wed Dec 12, 2018 5:24 pm
Location: Ireland
Has thanked: 1 time
Been thanked: 87 times
Contact:

Re: Another Dumb Damien Software question

Post by Jack Bauer »

Thanks guys:)
I'm going to need a hacksaw
tom91
Posts: 1308
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 103 times
Been thanked: 216 times

Re: Another Dumb Damien Software question

Post 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
Founder Volt Influx https://www.voltinflux.com/
Webstore: https://citini.com/
MattsAwesomeStuff
Posts: 898
Joined: Fri Apr 26, 2019 5:40 pm
Has thanked: 291 times
Been thanked: 177 times

Re: Another Dumb Damien Software question

Post 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.
Post Reply