HE351 code for me78569

Started by me78569, June 11, 2015, 09:38:57 AM

hakcenter

#165
I won't be driving until much later today... so here's the rendition that I'll run later

Variable changes

// Turbo
const int minimum_turbo_rpm = 4000;
byte stage = 1;
unsigned long turbo_rpm = 0;
unsigned long last_turbo_rpm = 0;
double turbo_accel = 0.0;
double accel_factor = 0.0;


Serial Output

void serial_output() {
  if (turbo_rpm > minimum_turbo_rpm) {
    String output = "";
    String extra = "";
    byte current_mode = 2;
    if (idle_mode) { current_mode = 0; }
    if (idle_walkdown_mode) { current_mode = 1; }
    if (cruise_mode) { current_mode = 5; }
    if (performance_mode) { current_mode = 6; }
    if (brake_mode) { current_mode = 4; }
    if (spare_mode) { current_mode = 3; }
    // Addes extra spaces infront of position to keep things aligned
    if (vane_position < 10) { extra = "  "; } else if (vane_position < 100) { extra = " "; }
    output += "CPOS : " + extra + vane_position + " | ";
    extra = "";
    if (final_vane_position < 10) { extra = "  "; } else if (final_vane_position < 100) { extra = " "; }
    output += "APOS : " + extra + final_vane_position + " | RPM : ";
    extra = "";
    // Addes extra spaces infront of turbo_rpm to keep things aligned
    if (turbo_rpm < 1000) { extra = "   "; } else if (turbo_rpm < 10000) { extra = "  "; } else if (turbo_rpm < 100000) { extra = " "; }
    output += extra + turbo_rpm + " | ";
    output += "Accel : ";
    if (turbo_accel >= 0) { output += " "; }
    output += turbo_accel;
    Serial.print(output);
    output = " | Mode : " + current_mode_array[current_mode];
    Serial.println(output);
  }
  if (millis_out) {
    Serial.print(time_elapsed1);
    Serial.print(" ms |loop()");
    Serial.print(" || " );
    Serial.print(time_elapsed2);
    Serial.print(" ms |keep_time()");
    Serial.print(" || " );
    Serial.print(time_elapsed3);
    Serial.print(" ms |calculate_vane_position()");
    Serial.print(" || " );
    Serial.print(time_elapsed4);
    Serial.println(" ms |set_turbo_position()");
  }
}


Timer2

void keep_time() {
  time_start2 = millis();
  timer++;
  if (staging_enabled) {
    // Keeps turbo staging in time
    stage_timer++;
    if (stage_timer > 200) { stage_timer = 200; }
    if (timer % 2 == 0 && turbo_rpm > 100000) { update_vane_position = true; }
  }
  // Update vane_position every 10ms 100k+ / 25ms 60k - 100k / 50ms 0 - 60k
       if (timer % 10 == 0 && turbo_rpm > top_end_rpm) { update_vane_position = true; accel_factor = 10.0;}
  else if (turbo_rpm > curve_rpm[4] && timer % 25 == 0) { update_vane_position = true; accel_factor = 25.0; }
  else if (timer % 50 == 0) { update_vane_position = true; accel_factor = 50.0;}
  // Update turbo_accel before calculating vane_position
  if (update_vane_position) {
    turbo_accel = (turbo_rpm / (60000.0 / accel_factor)) - (last_turbo_rpm / (60000.0 / accel_factor));
    last_turbo_rpm = turbo_rpm;
  }
  // Modes
  if (timer % 100 == 0) { calculate_modes(); }
  // Calculate vane_position
  if (update_vane_position) { update_vane_position = false; calculate_vane_position(); }
  if (serial_out) {
    if (turbo_rpm < top_end_rpm && timer % 100 == 0) { serial_output(); }
    if (turbo_rpm > top_end_rpm && timer % 10 == 0) { serial_output(); }
  }
  if (timer == 1000) { timer = 0; }
  time_finished2 = millis();
  time_elapsed2 = time_finished2 - time_start2;
}


Should be about right. Probably multiply by 1000, get a bit more resolution on the decimal places and get it into RPs acceleration.


BTW if you couldn't tell from the accel log, I've fixed idle_walkdown :D, and it jumps out of idle to curve[0] when its off idle accel.
TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

me78569

Do I have to wait until version 1.2 to see how you accomplished the offidle jump?  I am VERY curious.
2000 Dodge 2500 quad-cab 5.9 Cummins slt, homebuilt 47re revmax 3.5 messed with vb, Quad adr iquad, 4" tbe , pureflow 150 gph. he351ve in the works 100hp DFI inj

hakcenter

I'm going to figure out a way to do bitwise and move the decimal at the end or something. Maybe do 2x + 8x then, use the front minus 8 bitshift as the front of the decimal and the back only the first byte...  It'll come to me after i finish some yard work
TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

me78569

No hurry haha. 


So using my pot control  I decided to do some testing.  I left the pot at a specified position then went and drove like a crazy man.

Final pos of 14 for injector only makes it hard to overspeed.  16 for can bus fueling addition and 18 for wiretap fueling.


So I guess I know where I need to end up haha.
2000 Dodge 2500 quad-cab 5.9 Cummins slt, homebuilt 47re revmax 3.5 messed with vb, Quad adr iquad, 4" tbe , pureflow 150 gph. he351ve in the works 100hp DFI inj

hakcenter

TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

me78569

#170
Sorry,


I have a Potentionmeter in the cab that I can set the vane position manually.  I dunno why I didn't do this earlier, but I went out and set the vanes manually.

I started without a tuner at all, just my 100hp injectors

At position 12cm^2 I was unable to get the turbo rpm to go over 130,000


With my tuner set to 65hp+ over stock I can run at 14cm^2 and not get over 130,000

With my tuner set to "kill" 180hp over stock I set it at 18cm and I was unable to get over 130,000


I want to have 3 curves , Tow, DD, and Perf that will follow the above tuner settings.  so now that I know what my upper limit has to be I can adjust the curve below 100,000 to keep it from slingshotting past 130k.


just gotta figure out how to slow down the shaft acceleration haha. 

Looking forward to trying what you come out with.
2000 Dodge 2500 quad-cab 5.9 Cummins slt, homebuilt 47re revmax 3.5 messed with vb, Quad adr iquad, 4" tbe , pureflow 150 gph. he351ve in the works 100hp DFI inj

hakcenter

#171
Ya I'll keep thinking, I may have to just give up on 100% accuracy and go with like a 51/256 or something.. to find out if its even faster I'll have to setup millis.. which I've been doing haha..

Work on one thing, get an idea for another... decided to time serial output, and there was room to speed it up...

Simulated RPM...

CPOS : 666 | APOS : 667 | RPM :  99217 | Accel :  0.27 | Mode : Normal
1400uS
CPOS : 664 | APOS : 664 | RPM : 101731 | Accel :  0.27 | Mode : Normal
1420uS
CPOS : 600 | APOS : 662 | RPM :   4344 | Accel : -82.71 | Mode : Normal
1392uS
CPOS : 600 | APOS : 600 | RPM :   6904 | Accel :  1.09 | Mode : Idle
1360uS
CPOS : 600 | APOS : 600 | RPM :   9472 | Accel :  1.09 | Mode : Idle

versus

CPOS : 666 | APOS : 667 | RPM :  99261 | Accel :  0.27 | Mode : Normal
1124uS
CPOS : 664 | APOS : 664 | RPM : 101775 | Accel :  0.26 | Mode : Normal
1152uS
CPOS : 600 | APOS : 662 | RPM :   4399 | Accel : -82.7 | Mode : Normal
1116uS
CPOS : 600 | APOS : 600 | RPM :   6967 | Accel :  1.09 | Mode : Idle
1084uS
CPOS : 600 | APOS : 600 | RPM :   9515 | Accel :  1.09 | Mode : Idle


0.2ms faster not bad... lol

Then you ask, how did you make adding Strings together faster... lolol



  if (update_vane_position) {
    turbo_accel = ((turbo_rpm / 60000.0) - (last_turbo_rpm / 60000.0)) * accel_factor;
    last_turbo_rpm = turbo_rpm;
  }


Bout as fast as it can get, 80-84uS. throwing big bitshifts isn't helping when its not twice as fast.. so I'd rather have better resolution.
TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

Rx7man


if (update_vane_position) {
    turbo_accel = ((turbo_rpm / 60000.0) - (last_turbo_rpm / 60000.0)) * accel_factor;
    last_turbo_rpm = turbo_rpm;
  }


You can get that faster by refactoring

if (update_vane_position) {
    turbo_accel = (turbo_rpm  - last_turbo_rpm) / 60000.0 * accel_factor;  // <---refactored.. one less division
    last_turbo_rpm = turbo_rpm;
  }
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

hakcenter

yep thanks. wasted so much time in bitwise math >.>
TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

Rx7man

Just remember to get the low-hanging fruit first :)
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

hakcenter

It's tough when you spend so much time in thought of how to save a couple nanoseconds! lolol

Did quite well on the serial output. Decided to go for the whole re-write and happy I did, results are workagering ^_~
TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

Rx7man

On my code I haven't bothered trying to make it fast yet.. I'm keeping it readable, lots of divisions and multiplications could be refactored, but until it drives, I'd like to make it make sense to me after I haven't looked at the code for a month or two.. It's amazing how fast you forget how something worked!  I have dozens of old projects that I don't think I could figure out if I had to look at them again... or at the least it would take a lot of thinking to get into it. 
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

hakcenter

ya I'm almost to the point of releasing 1.1.1, I want to figure out a use for the acceleration variable.. might use it to tune the top end over multiple pulls or something /shrug
TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

me78569

#178
while I am curiously waiting for 1.1.1 I have been tuning / testing with VERY nice results. 

I have moved the curve some to

// Turbo Curves & Factors
const byte two_cm = 80;
const byte one_cm = 40;
const byte half_cm = 20;
const unsigned int idle_rpm = 12000;
const unsigned int idle_walkdown_rpm = 22000; 
const unsigned long lit_rpm = 105000;  //RPM where turbo is considered to be making full boost
const unsigned long BarkRpm = 75000;  // If rpm is over this rpm process runs to keep turbo from barking when letting off throttle
const unsigned long Target_Rpm_Low = 120000;  //Lower rpm range where you want to hold RPMS at top end
const unsigned long Target_Rpm_High= 128000;  //upper rpm range where you want to hold RPMS at top end
const unsigned int curve_rpm[5] = { 17000, 20000, 26000, 37000, 65000 };
unsigned int turbo_curve[5] = { 0,0,0,0,0 };
const unsigned int turbo_curve_1[5] = { 770,730,710,600,416 };  //Perf curve larger vane position due to more fuel can + tap fuel. Curve is choosen by inactive pot position watchpot();
const unsigned int turbo_curve_2[5] = { 800,760,720,625,500 };  //DD curve with can fueling only mid curve
const unsigned int turbo_curve_3[5] = { 830,790,730,650,550 };  //Tow curve for timing only no extra fueling


Then I have changed the PosCalc to

/*  This code is put in place to control an HE351ve turbo using Turbo RPM and other inputs.
*   
*  Sections of this code, including but not limited to the rpm based vane position calculations, Freq Measure, and
*  Timer setup are thanks to Curtis R Hacker at lilbb.com and his RPM based HE351vgt arduino shield.

*  This work is licensed under the
*  Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
*  To view a copy of this license,
*  visit [url=http://creativecommons.org/licenses/by-nc-sa/4.0/]Creative Commons &mdash; Attribution-NonCommercial-ShareAlike 4.0 International
&mdash; CC BY-NC-SA 4.0 [/url].
*/

/////////////////////////////POS Manage////////////////////////////////////////
void PosManage() {
      if (turbo_rpm <= curve_rpm[4]) {
        if (ThrottlePosition < 3) {  // Idle Section
          if (turbo_rpm > BarkRpm) {AntiBark = true; vane_position = min_position;} else {AntiBark = false;}
            if(turbo_rpm <= idle_rpm) {
             vane_position = idle_position;
             idle_walkdown_mode = false;
          } else {
            if (turbo_rpm <= idle_walkdown_rpm) { idle_walkdown_mode = true;} else { idle_walkdown_mode = false; }
            if (idle_walkdown_mode) { vane_position = constrain((final_vane_position - 10),idle_position-two_cm, 800); }
                       
          }
        }else {  AntiBark = false;
          // -----
          // Curve section
               
               if (turbo_rpm <= curve_rpm[0]) { vane_position = constrain(map(turbo_rpm, idle_rpm , curve_rpm[0], Offidle_position, turbo_curve[0]), Offidle_position, turbo_curve[0]);} //turbo_curve[0];}
          else if (turbo_rpm <= curve_rpm[1]) { vane_position = map(turbo_rpm, curve_rpm[0], curve_rpm[1], turbo_curve[0], turbo_curve[1]);}
          else if (turbo_rpm <= curve_rpm[2]) { vane_position = turbo_curve[1];}
          else if (turbo_rpm <= curve_rpm[3]) { vane_position = map(turbo_rpm, curve_rpm[2], curve_rpm[3], turbo_curve[1], turbo_curve[2]);}
          else { vane_position = map(turbo_rpm, curve_rpm[3], curve_rpm[4], turbo_curve[2], turbo_curve[3]);} //+ TPS_range was put into place to open the vane more if throttle input was higher
        }
      } else if (turbo_rpm < lit_rpm) { AntiBark = false;
          vane_position = map(turbo_rpm, curve_rpm[4], lit_rpm, turbo_curve[3], turbo_curve[4] - TPS_range);}
       else{
        AntiBark = false;
        if (curvea){
            if(turbo_rpm < Target_Rpm_Low){
            vane_position = map(turbo_rpm, lit_rpm, Target_Rpm_Low, turbo_curve[4] - TPS_range, 233 - TPS_range);   
            Stable_Pos = vane_position;
            }
             else if (turbo_rpm > Target_Rpm_Low && turbo_rpm < Target_Rpm_High){
              vane_position = Stable_Pos;}         
             
             else if (turbo_rpm > Target_Rpm_High){
              vane_position -= constrain(map(Movement, Target_Rpm_High, turbo_rpm, 1, 10),1,10);
              constrain(vane_position, min_position, 233 - TPS_range);
          }  Stable_Pos = vane_position; //else { vane_position = 333;}
       }
        if (curveb){
            if(turbo_rpm < Target_Rpm_Low){
            vane_position = map(turbo_rpm, lit_rpm, Target_Rpm_Low, turbo_curve[4] - TPS_range, 333 - TPS_range);   
            Stable_Pos = vane_position;
            }
             else if (turbo_rpm > Target_Rpm_Low && turbo_rpm < Target_Rpm_High){
              vane_position = Stable_Pos;}       
             else if (turbo_rpm > Target_Rpm_High){
              vane_position -= constrain(map(Movement, Target_Rpm_High, turbo_rpm, 1, 10),1,10);
              constrain(vane_position, min_position, 333 - TPS_range);
          }  Stable_Pos = vane_position;  //else { vane_position = 416;}
        }
        if (curvec){
            if(turbo_rpm < Target_Rpm_Low){
            vane_position = map(turbo_rpm, lit_rpm, Target_Rpm_Low, turbo_curve[4] - TPS_range, 416 - TPS_range);   
            Stable_Pos = vane_position;
            }
             else if (turbo_rpm > Target_Rpm_Low && turbo_rpm < Target_Rpm_High){
              vane_position = Stable_Pos;}       
             else if (turbo_rpm > Target_Rpm_High){
              vane_position -= constrain(map(Movement, Target_Rpm_High, turbo_rpm, 1, 10),1,10);
              constrain(vane_position, min_position, 416 - TPS_range);
          }  Stable_Pos = vane_position; //else { vane_position = 500;}
        }

        // Overrun protection
      if (over_run > 145000){
        if (!curvea) {vane_position -= half_cm;} //{overrun = true;} else{overrun = false;}
         
      //if (overrun) {vane_position = min_position;}
    }
   }


Big things to note are the AntiBark function if tps is below 3% and turbo rpm is above barkrpm.  This works VERY well to keep barking from happening.  I have not had one bark since putting it into place. 

Next big thing is the upper end control, snippet from above
        if (curvea){
            if(turbo_rpm < Target_Rpm_Low){
            vane_position = map(turbo_rpm, lit_rpm, Target_Rpm_Low, turbo_curve[4] - TPS_range, 233 - TPS_range);   
            Stable_Pos = vane_position;
            }
             else if (turbo_rpm > Target_Rpm_Low && turbo_rpm < Target_Rpm_High){
              vane_position = Stable_Pos;}         
             
             else if (turbo_rpm > Target_Rpm_High){
              vane_position -= constrain(map(Movement, Target_Rpm_High, turbo_rpm, 1, 10),1,10);
              constrain(vane_position, min_position, 233 - TPS_range);
          }  Stable_Pos = vane_position; //else { vane_position = 333;}
       }


I change the the end position based upon which curve I have selected, inactive pot position <20 or 20<>970 or >970,  if I am running the perf curve I set the end position to 233 - tps_range. 

Note that there is a range of turbo shaft speeds on the top end that I don't adjust vane position, between Target_Rpm_Low 120,000 and Target_Rpm_High 128,000.

the thought is I adjust the tuner fueling based on what curve. 

anyways this upper end curve does a VERY good job of keeping the turbo RPMS between 120k and 127k.  RPMS will spike to 140 for a split second then walk down nicely and hold.

As I tested before the positions that I can run on each curves without overspeeding at 16cm for injector only fueling, 18cm for canbus plus injectors, and 20cm for tuner set to "kill" and injectors.  So that is why I set the positon where I did for the top end.

 
2000 Dodge 2500 quad-cab 5.9 Cummins slt, homebuilt 47re revmax 3.5 messed with vb, Quad adr iquad, 4" tbe , pureflow 150 gph. he351ve in the works 100hp DFI inj

hakcenter

Yeah bark is bad, I'll probably enable the smoothing function while acceleration is negative over top end
TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.