Announcement

Collapse
No announcement yet.

CSL '0401' Program Binary Disassembly Notes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • karter16
    replied
    Fun fact (which other people may already know, I just didn't) - the final RF calculation function in 0401 actually has provision for use of an HFM (MAF) sensor. The HFM sensor is assumed to to be plugged in to HFM1 (which in 0401 default config is the potentiometer for the CSL flap), but there are a number of parameters which can be set which configures the HFM1 A/D converter and ring buffer for a MAF sensor and derives the final RF from the ML value from HFM1. This is interesting as the final RF function in 0401 is not a copy/paste job from the standard MSS54HP code (e.g. it's an intentional inclusion, not a failure to omit). What I haven't looked into yet is whether any of the HFM tables differ from MSS54HP. I'm presuming that it would be calibrated for the standard M3 HFM sensor and cross-sectional area.

    Here's the relevant line from the final RF calc function which I've posted before:

    Click image for larger version  Name:	Screenshot 2025-03-06 at 5.44.34 PM.png Views:	0 Size:	13.5 KB ID:	296828

    And here's the function which reads the A/D converter ring buffer:

    Click image for larger version  Name:	Screenshot 2025-03-06 at 5.55.14 PM.png Views:	0 Size:	82.8 KB ID:	296829

    Leave a comment:


  • karter16
    replied
    Have identified the curve at 0xD002 - it describes the maximum torque to be applied by the Moment Manager in the event of a CAN SMG error state being stored in CAN_ED_SMG. The x axis is V (in km/h) and the y axis is torque (in Nm).

    I've named the curve kl_md_can_ed_smg_max.

    Click image for larger version

Name:	Screenshot 2025-03-03 at 5.40.06 PM.png
Views:	207
Size:	13.8 KB
ID:	296446

    The curve is referenced in the function at 0x0001b0c2 which I have named md_can_ed_smg_max_calc()

    Click image for larger version

Name:	Screenshot 2025-03-03 at 5.40.13 PM.png
Views:	152
Size:	54.8 KB
ID:	296447

    This function in turn is run in one of the timed tasks (pretty sure it's the 20ms task but not 100% sure yet) if the gearbox type is SMGII.

    Click image for larger version

Name:	Screenshot 2025-03-03 at 5.40.25 PM.png
Views:	137
Size:	112.4 KB
ID:	296448

    and md_can_ed_smg_max itself is used in the Torque Limitation function of the Moment Manager.

    Click image for larger version

Name:	Screenshot 2025-03-03 at 5.40.40 PM.png
Views:	143
Size:	178.4 KB
ID:	296449

    Leave a comment:


  • karter16
    replied
    Have published the XDF - figured it was worth it's own post so you can find that, along with the download link, here: https://nam3forum.com/forums/forum/s...p-csl-0401-xdf

    Leave a comment:


  • Bry5on
    replied
    And no overflows! Impressive .

    In my other car, I wrote my own motor controller code and found a sneaky overflow bug that commanded full throttle when a calculation overflowed above 55mph. I’d missed ONE mathematical operation in my giant excel sheet that hunted for overflows. Sure was freaky when that electric motor all of a sudden took off on my drive to work, and I was glad to have good brakes.

    Leave a comment:


  • karter16
    replied
    It occurred to me that it may or may not be immediately apparent to everyone as to why the program code contains so many scaling factors and offsets hardcoded into the program flow.

    The reason for this is that the MSS54 CPU does not have an FPU (floating point unit). This means that the CPU is unable to natively perform floating point calculations and therefore all calculations are done with integer values. This is where all the bitshifts (multiplication/division by powers of 2) multiplication/division/addition/subtraction of parameters and consts comes in.

    Say for example you have a filtered pressure reading from your MAP sensor of 800mbar. You now need to apply a correction factor of 1.03 (e.g. 800 * 1.03 = 824). The problem is that you can't represent 1.03 as floating point value, so you need to store it as a value that can be represented as an integer.We can't just round 1.03 to 1 because then we'll get 800 * 1 = 800, which isn't what we want. What we can do is represent 1.03 as 103 in an integer just fine, so we do that, we add a parameter into the partial binary and give it a value of DEC 103. Now we can apply our correction factor (e.g. 800 * 103 =82400). However now our result is 100 times too big. So what we do is modify the code to multiply our pressure by our correction factor and then divide the result by 100. This gives us (800 * 103 = 82400) and then we divide that by 100 to get 824. We've managed to get to the right end result without having to use floating point numbers.

    This is a simple example, but you can easily envisage calculations which require lots of these scenarios and it can quickly get complicated, like this:


    Click image for larger version  Name:	Screenshot 2025-02-27 at 4.02.25 PM.png Views:	0 Size:	71.1 KB ID:	295889
    Last edited by karter16; 02-26-2025, 06:09 PM.

    Leave a comment:


  • karter16
    replied
    Originally posted by ac427 View Post
    Thanks karter16

    I know you are focusing on the MAP sensor at the moment but do you know how much influence the exhaust temperature sensor has on the cold start routine?
    No worries - with the caveat that I haven't been through every reference to TABG (exhaust gas temp) I believe it is mostly used for calculating cat heating (including TKATM which is the cat temperature model) and the cat protection factor. Most of cold start factors that I have come across reference TMOT (and from memory TOEL in a couple of places, although I might be wrong). When I get a chance I'll look into this more and give you a more definitive answer.

    Leave a comment:


  • ac427
    replied
    Thanks karter16

    I know you are focusing on the MAP sensor at the moment but do you know how much influence the exhaust temperature sensor has on the cold start routine?

    Leave a comment:


  • karter16
    replied
    Originally posted by ac427 View Post

    Sorry for the dumb question but aren't the variables above just opposites of eachother?
    Not dumb at all as there's a lot of different variables used and naming them appropriately is also challenging.

    p_ask: is the air pressure as measured by the MAP sensor (once it's been filtered, scaled, etc)

    p_kvm: is a measure of vacuum in the manifold and is calculated as P_UMG (ambient pressure from the DME pressure sensor) minus p_ask. So essentially the difference between ambient and what the MAP sensor sees.

    If ambient pressure (P_UMG) is 1000mbar and MAP sensor is measuring 700mbar (p_ask) then manifold vacuum (p_kvm) is 300mbar.


    Edit: I should more correctly define p_ask as “Absolute Manifold Pressure” I will update this.
    Last edited by karter16; 02-25-2025, 12:06 PM.

    Leave a comment:


  • ac427
    replied
    Originally posted by karter16 View Post
    p_ask: Pressure Ansaugkrümmer (Manifold Air Pressure)
    p_kvm: Pressure Krümmervakuum (Manifold vacuum)
    Sorry for the dumb question but aren't the variables above just opposites of eachother?

    Leave a comment:


  • karter16
    replied
    I'm working now on the pressure and air mass functions - found the PT1 filter functions and matching up the disassembled code to the calculations.

    I realized as well a slight nuance to the code at the end of the calculation of rf_p_ask_i (the error condition behavior) is that when a WDK error occurs the code is ramping rf_p_ask_i to zero. Will update the comments.


    Sent from my iPhone using Tapatalk

    Leave a comment:


  • karter16
    replied
    Okay here's the calculation of the MAP Sensor based Integral component with updated variable names and comments now that I've had a chance to digest MpowerE36's document.

    In naming the various variables I've tried to do it in the same way I imagine BMW would have originally. Any variables I've named are lowercase. Known variable names from BMW are all caps.

    p_ask: Pressure Ansaugkrümmer (Manifold Air Pressure)
    p_kvm: Pressure Krümmervakuum (Manifold vacuum)

    All other variables are based on this naming.

    Click image for larger version

Name:	Screenshot 2025-02-24 at 8.34.46 PM.png
Views:	159
Size:	209.6 KB
ID:	295418
    Click image for larger version

Name:	Screenshot 2025-02-24 at 8.35.02 PM.png
Views:	164
Size:	225.1 KB
ID:	295419
    Click image for larger version

Name:	Screenshot 2025-02-24 at 8.35.12 PM.png
Views:	172
Size:	189.9 KB
ID:	295417

    Leave a comment:


  • SliM3
    replied
    Originally posted by Slideways View Post
    Nice work!

    I believe that terra , SliM3 , and olza had some ideas of how the MAP sensor worked in the old MSS54/HP comprehensive thread.

    This is the thread I made a while ago (https://nam3forum.com/forums/forum/s...ensor-function) and the images from the E92 and CSL technical document:

    IIRC, Terra said that BMW simplified the description of how the MAP sensor worked (mainly for the CSL).

    Did BMW use a MAP sensor before the S54 or was that the first engine with it? (Maybe the first because previous DMEs were not as advanced?)
    Yeah, I have an IDA Pro disassembly I completed a while ago but my interpretation as to how and when the MAP sensor is integrated is a little different than what's being described here, and what I've experienced playing around with the tune (swapping ram address, disabling flags, etc.). Never the less cool to compare notes, albeit I'm not too familiar with the tool being used here.

    Leave a comment:


  • karter16
    replied
    bmwfnatic and I have been talking and we think for the VE tuning process it may be better to disable the MAP sensor integrator so that the car is running pure AlphaN (with TABG adjustment). With the MAP integrator in the mix it's another variable. Large dataset probably mitigates this, but we think taking the MAP sensor out of the loop while doing the tuning could make it faster to get to the end result.

    Taking the MAP integrator out of the loop is as simple as changing the configuration byte from 0x12 to 0x02 which keeps the TABG adjustment but takes the integrator out of the final RF calculation.


    Sent from my iPhone using Tapatalk

    Leave a comment:


  • karter16
    replied
    MpowerE36 - thank you so much for this - the way you lay it out is fantastic and makes it so much clearer to understand. Your description of the rf_map as being an integrator is spot on and is possibly where my brain was trying to get to last night.

    I *think* the point is that the manifold air pressure is used as a kind of process variable to calculate an integral component (think PID controllers) to correct steady-state error in the RF calculation. It's limited to 2.5% in order to prevent integral windup (which is essentially a runaway condition when the integrator sums to infinity without being able to pull the error term to zero).

    At a high level my thinking is as follows:

    1: RF is largely set from the AlphaN map. This map is based on the input variables aq_rel (relative opening) and N (engine speed).
    2: The MAP sensor calculates a manifold air pressure based RF which feeds the integral component to eliminate the error-term in steady-state.
    3: Under a sudden change in conditions (engine speed or aq_rel) the AlphaN map sets the new target RF instantaneously.
    4: Under this condition it's entirely possible that the integral component saturates at +- 2.5% points of RF.
    5: But that's okay, as the engine responds to the new aq_rel the RF from AlphaN and RF from MAP will begin to converge.
    6: As they converge the integral component will fall back within it's saturation range and begin operating.

    It makes perfect sense. Indeed as you note BMW essentially inactivate the integrator under WOT conditions and under high RPM conditions, it's active exactly where it's needed, which is driveability/steady state where final RF is relatively low anyway and the changes in it are lower. The MAP sensor input IS limited to +- 2.5% (of max RF, not current RF) but that doesn't mean it only has a small impact, it's entire purpose is to eliminate the steady state error between the AlphaN table and real-world conditions.

    I don't know if anyone has done this yet, but if we apply the fix to "RF From MAP Sensor" via DS2 and log it and RF side by side I bet we see in drivability situations that the difference is less than 2.5% points (e.g. in the situations where it is useful the 2.5% points limit is NOT a limiting factor in what the MAP sensor contributes to the final RF)


    Edit: a further thought - in drivability conditions RF is usually less than 15 (out of 100) or so, which means in those conditions the integral component can be as high as about 17% or so of current RF.
    Last edited by karter16; 02-22-2025, 11:26 PM.

    Leave a comment:


  • karter16
    replied
    Originally posted by MpowerE36 View Post
    Here all my knowledge about the rf calculation of the BMW CSL engine. I hope this will be appreciated for its true value​. You will have to do a bit of translation because I wrote it in French in the past but I am sure that will not be a problem​.
    This is fantastic - thank you so much for this!


    Sent from my iPhone using Tapatalk

    Leave a comment:

Working...
X