Beginners Guide to Processing 18650 Cells | Cell Database


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pseudocode and BMS
#1
No, it's not something out of Fifty Shades of Ghastly, a  long time ago when I learned to code I was taught to write pseudocode first. I'll refer to Wiki..

https://en.wikipedia.org/wiki/Pseudocode


Quote:Pseudocode[1] is an informal high-level description of the operating principle of a computer program or other algorithm.
It uses the structural conventions of a normal programming language, but is intended for human reading rather than machine reading. Pseudocode typically omits details that are essential for machine understanding of the algorithm, such as variable declarations, system-specific code and some subroutines. The programming language is augmented with natural language description details, where convenient, or with compact mathematical notation. The purpose of using pseudocode is that it is easier for people to understand than conventional programming language code, and that it is an efficient and environment-independent description of the key principles of an algorithm. It is commonly used in textbooks and scientific publications that are documenting various algorithms, and also in planning of computer program development, for sketching out the structure of the program before the actual coding takes place.
No standard for pseudocode syntax exists, as a program in pseudocode is not an executable program. Pseudocode resembles, but should not be confused with skeleton programs which can be compiled without errors. Flowcharts, drakon-charts and Unified Modeling Language (UML) charts can be thought of as a graphical alternative to pseudocode, but are more spacious on paper. Languages such as HAGGIS bridge the gap between pseudocode and code written on programming languages. Its main use is to introduce students to high level languages through use of this hybrid language.

I'm interested in what the or perhaps a pseudocode for a BMS would look like, it's been my experience that once once you have the pseudocode for an operation nailed down nicely writing the actual code usually is fairly straightforward. If you know where  you are going when you start it's a lot easier to get there.

I've been doing some experiments with flying capacitor balancing and have come to realize that, logically enough (insert smack head smiley here) the charge and discharge times can be different depending on the internal resistance of the cells or parallel packs you are trying to discharge or charge. I think that with a proper capacitor a nice balancing system can be set up that is almost 100% energy efficient. My next step is to eliminate as much stray resistance from the circuit as I can, I may parallel the relays to lessen resistance, we shall see.

My pseudocode extremely rough outline for balancing with a flying capacitor is.. Every so often turn off all the balancing and after a pause for things to settle check the actual voltages across the cells, take the highest cell, siphon energy from it into a capacitor until the voltage curve starts to peak, turn off both legs of that cell, then turn on both legs of the lowest cell and discharge the capacitor into it until the voltage curve starts to bottom out, then it's turn off the lowest cell and back to the charge cell again, turn on both legs until capacitor voltage nearly peaks then turn them off and turn on both legs of the low cell until near bottom. Do this until you have a new low or high cell in the periodic scan and then do it to those cells and so on..

You can and indeed have to expand and add all kinds of other things, actually reading the cell voltages, sophisticated noise filtering, making absolutely positively darn sure that the wrong relays don't get turned on at the wrong time, talking to the overall charge controller overlord part of the program which of course needs its own pseudocode that would necessarily interface the PC of the balancing function as they are known in the Arduino world. Read the system timer and call subs you need for measurement and actions as the situation requires. BMS is actually a pretty easy microcontroller chore compared to say MPPT which turns into quite the juggling act quickly. At least you don't have to write your own ADC code in assembler, taking care to add nops so that all decision trees come out the same number of cycles so the speed is always the same.  It was a day of wooden computers and iron men.

What would you like to see in a pseudocode outline for a BMS?
Reply


#2
A capacitive balancer, aka a charge pump, note that these are normally only used at very low currents (less than 50mA on average when time constants are added in)

However as it is a BMS, what occurs in such an arrangement when all cells are equal, but at an over voltage or under voltage condition? (A limitation of some active balancers with no other features)

As for how to match your charge and discharge thresholds, a comparator should be all you need, when capacitor voltage >= 99% of battery voltage, it signals to your controller that it is ready to switch, this will equally give you an almost direct way to measure cell ESR for back end monitoring, by measuring the time between starting and the comparator switching, (subject to the tolerance of your components)

As your dealing with relays that will generally burn through some power, I would have a strong hysteresis on your system, "If cell is greater than Over voltage limit, balance immediately, otherwise balance only while charging and cell is greater than 0.02V to another cell. OR, If at undervoltage limit, and other cells greater than 0.1 above, charge from them",
Elmo likes this post
Reply
#3
Good points, especially about the hysteresis, basically all it will be is a software comparator, hysteresis is but another line of code, asymmetrical hysteresis may be desirable.

I hadn't considered conserving relay power, that's excellent. A reasonably wide hysteresis will help with power conservation. Relays would of course be configured to be normally in the off state.

As for what to do in an all over or all under situation that is up to the BMS overlord function that's calling the shots, balancing is but a peon, a humble subfunction if you will.
Reply
#4
Just a thought, but wouldn't it be better to use a couple mosfets instead of a relay? They can handle quite a bit of amperage, especially if paired/line. And, they wouldn't use no where near as much power to run.
Reply
#5
If I felt confident I could design such a MOSFET circuit without letting out a great deal of magic smoke in the process that's the terminology I would have used. I've followed enough discussions about MOSFETS and switching controllers to know that stuff is rather beyond my pay grade.

Elmo's comfort zone is a bit closer to stone axe technology, Elmo loves relays.

But that's a detail which isn't really relevant to a discussion about pseudocode. If I was going to resort to MOSFET I'm more comfortable with an inductor based flyback type of booster. There is a really nice MOSFET switch that will do 30A at 60V driven straight off a 3.3V logic line.

Getting the pseudocode right is the key to good programming, I kind of do it in my head when I write spaghetti code making one function work at a time but it's not the same as sitting down and hammering out the logical basis for your program before you ever write a line of Perl or Java or Forth or Logo or C- - or whatever.
Reply
#6
Yeah, I agree.

I never was a pseudo kinda programmer. I thought of all the logic and steps involved in my head for a few days (usually when I'm about to go to sleep, since that's when my brain isn't distracted), and when it's time to write, I can usually just plop it all down with little rewrites.

Or, at least, that's how I used to do it. I've been away from coding for quite some time and it's all a bit rusty now Tongue

I enjoy reading others info, tho. It helps me get back on track with stuff. Thanks for the thread and comments that are passing through. Smile
Reply
#7
I was looking at these mosfets for full pack shutdown: https://www.digikey.ca/product-detail/en...ND/1117519
process in building BMS/monitoring will provide temp, voltage of each 1s pack.  Will shutdown pack if temps get too high, or voltage to high/low. I will have remote web shutdown of discharge/charge circuit as well.

After I can get a basic system up and running, I'll probably look at combining bq76940 with ESP32 for better accuracy of battery voltage, but probably still plan on keep the separate discharge circuit since mine will do .75-1A discharge. http://www.ti.com/product/bq76940.
Korishan likes this post
Reply


Who read this thread?
82 User(s) read this thread:
frnandu (06-15-2017, 06:37 PM), watts-on (06-16-2017, 10:46 AM), jesusangel (06-20-2017, 07:51 PM), Hanssing (06-15-2017, 06:27 PM), Dicklinn (06-14-2017, 09:30 PM), bfleury (07-21-2017, 03:46 PM), Joost2 (08-12-2017, 01:58 PM), Hefferoni (10-18-2017, 03:11 AM), systemtm (07-05-2017, 08:06 AM), dinoN17 (05-30-2017, 08:28 AM), D.G.Lang (05-29-2017, 11:48 AM), josearaujo10 (04-23-2017, 12:10 PM), typ49 (06-16-2017, 08:31 AM), VicRC (05-17-2017, 10:57 PM), Jeremy Choy (06-15-2017, 06:14 PM), 1958 greyhound (06-16-2017, 11:44 AM), kktuo (09-30-2017, 11:49 PM), neilmc (06-28-2017, 12:28 PM), Ragulin83 (09-08-2017, 11:59 AM), Piotr Dziel (09-10-2017, 06:03 PM), Lubomir Lach (07-16-2017, 12:38 PM), kiwi (08-10-2017, 07:51 AM), Tyler (10-08-2017, 05:37 AM), bilaltiger (09-23-2017, 03:37 PM), goctav (09-24-2017, 01:49 PM), Ripvansparky (10-12-2017, 02:54 PM), Nobby (10-08-2017, 06:09 PM), tocool24 (10-12-2017, 07:38 AM), shonalex (10-19-2017, 07:37 PM), surestardel (10-07-2017, 09:46 PM), WallBender (09-20-2017, 05:18 PM), James_H (09-18-2017, 10:47 PM), Geek (08-22-2017, 02:22 AM), floydR (09-24-2017, 02:53 AM), SimonW (09-06-2017, 06:29 AM), Grumplestiltskin (10-04-2017, 04:50 AM), TimFr (11-15-2017, 07:20 PM), Stuart Pittaway (09-28-2017, 11:46 AM), ChrisD5710 (09-17-2017, 12:11 PM), jesse.rizzo (09-24-2017, 09:32 PM), JanWorthy (10-17-2017, 12:31 PM), hbpowerwall (06-18-2017, 09:44 AM), Bassiexp (07-11-2017, 08:35 PM), frasernator (03-13-2017, 03:55 PM), dobbers (05-25-2017, 01:02 PM), Herebus (04-01-2017, 06:51 AM), Rerouter (04-13-2017, 11:58 AM), JustJim (03-10-2017, 03:29 PM), Korishan (06-15-2017, 07:03 PM), A + A (08-18-2017, 07:37 PM), SeattlePowerwall (04-14-2017, 01:51 AM), miwall (04-12-2017, 07:15 PM), Chickey (10-11-2017, 11:27 AM), daromer (06-16-2017, 12:52 PM), mike (03-09-2017, 08:45 PM), Swolrath (06-03-2017, 02:24 PM), station240 (03-27-2017, 03:29 AM), Joaquinsfy (04-17-2017, 08:26 PM), NiVa (06-22-2017, 08:35 PM), Lux_Gamer (06-16-2017, 07:00 AM), PAF (04-06-2017, 10:08 PM), sz1729 (03-16-2017, 02:23 PM), Janis (03-11-2017, 03:20 PM), Mike C (03-20-2017, 02:17 AM), Droid126 (05-11-2017, 09:16 PM), Sohax (04-11-2017, 01:33 PM), jdeadman (09-11-2017, 12:57 PM), MikeCZ (04-01-2017, 07:14 PM), charlie246 (09-11-2017, 10:38 AM), wim (06-18-2017, 03:02 PM), hugo5464 (04-10-2017, 07:58 PM), flight4900 (09-13-2017, 10:33 AM), Tom60 (03-27-2017, 02:56 PM), Jose Reyes (05-20-2017, 02:52 AM), Batrium (07-21-2017, 12:45 AM), Wattsup (06-20-2017, 03:12 AM), Elmo (03-10-2017, 04:13 AM), ozz93666 (03-10-2017, 03:12 AM), Felineman (03-17-2017, 08:03 PM), egam (03-11-2017, 04:07 AM), CrankyCoder (10-15-2017, 08:04 PM), aad (04-20-2017, 04:39 AM)

Forum Jump:


Users browsing this thread: 1 Guest(s)