User Tools

Site Tools


common_code

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
common_code [2015/10/22 12:19] – [Performance] hakcentercommon_code [2015/10/30 12:54] (current) hakcenter
Line 20: Line 20:
 \\ ''<fc #4682b4>boolean</fc> idle_mode = false;'' --  \\ ''<fc #4682b4>boolean</fc> idle_mode = false;'' -- 
 \\ ''<fc #4682b4>boolean</fc> idle_walkdown_mode = false;'' -- toggles when code is walking turbo down to idle \\ ''<fc #4682b4>boolean</fc> idle_walkdown_mode = false;'' -- toggles when code is walking turbo down to idle
-\\ ''<fc #4682b4>boolean</fc> idle_check = false;'' -- toggle when turbo_rpm exceded idle_walkdown_rpm 
 \\ ''<fc #4682b4>boolean</fc> spare_mode = false;'' **-- spare digital i/o toggle** \\ ''<fc #4682b4>boolean</fc> spare_mode = false;'' **-- spare digital i/o toggle**
 \\ ''<fc #4682b4>boolean</fc> brake_mode = false;'' **-- exhaust brake toggle** \\ ''<fc #4682b4>boolean</fc> brake_mode = false;'' **-- exhaust brake toggle**
 \\ ''<fc #4682b4>boolean</fc> cruise_mode = false;'' **-- cruise toggle** \\ ''<fc #4682b4>boolean</fc> cruise_mode = false;'' **-- cruise toggle**
 \\ ''<fc #4682b4>boolean</fc> performance_mode = false;'' **-- performance toggle** \\ ''<fc #4682b4>boolean</fc> performance_mode = false;'' **-- performance toggle**
 +\\ ''<fc #4682b4>boolean</fc> deceleration_mode = false;'' **-- triggered for anti-surge**
  
 **Minimum and Maximum Vane Positions** **Minimum and Maximum Vane Positions**
Line 31: Line 31:
  
 **Vane Positions** **Vane Positions**
-\\ ''<fc #4682b4>const unsigned int</fc> idle_position = **<fc #008000>400</fc>**;'' -- position used when turbo is at idle stage +\\ ''<fc #4682b4>const unsigned int</fc> idle_position = **<fc #008000>480</fc>**;'' -- position used when turbo is at idle stage 
-\\ ''<fc #4682b4>const unsigned int</fc> cruise_position = 600;'' -- position used when cruise mode is toggled+\\ ''<fc #4682b4>const unsigned int</fc> cruise_position = **<fc #008000>600</fc>**;'' -- position used when cruise mode is toggled 
 +\\ ''<fc #4682b4>const unsigned int</fc> deceleration_position = **<fc #ffa500>500</fc>**;'' -- position used when deceleration mode is toggled
 \\ ''<fc #4682b4>unsigned int</fc> vane_position = 0;'' **-- calculated vane position** \\ ''<fc #4682b4>unsigned int</fc> vane_position = 0;'' **-- calculated vane position**
 \\ ''<fc #4682b4>unsigned int</fc> last_vane_position = 0;'' **-- vane position 2ms ago** \\ ''<fc #4682b4>unsigned int</fc> last_vane_position = 0;'' **-- vane position 2ms ago**
Line 51: Line 52:
 \\ ''<fc #4682b4>const unsigned int</fc> idle_walkdown_rpm = 21000;'' \\ ''<fc #4682b4>const unsigned int</fc> idle_walkdown_rpm = 21000;''
 \\ ''<fc #4682b4>const unsigned long</fc> top_end_rpm = 105000;'' -- first point in top end curve \\ ''<fc #4682b4>const unsigned long</fc> top_end_rpm = 105000;'' -- first point in top end curve
-\\ ''<fc #4682b4>const unsigned int</fc> curve_rpm[5] = { <fc #ff0000>**17000, 200002600037000, 65000**</fc> };'' **-- curve rpm points**+\\ ''<fc #4682b4>const unsigned int</fc> curve_rpm[5] = { <fc #ff0000>**17000, 220003000045000, 65000**</fc> };'' **-- curve rpm points**
 \\ ''<fc #4682b4>unsigned int</fc> turbo_curve[5] = { 0,0,0,0,0 };'' **-- array to store curve from JP1** \\ ''<fc #4682b4>unsigned int</fc> turbo_curve[5] = { 0,0,0,0,0 };'' **-- array to store curve from JP1**
-\\ ''<fc #4682b4>const unsigned int</fc> turbo_curve_1[5] = { <fc #ffa500>**800,740,700,640,600**</fc> };'' +\\ ''<fc #4682b4>const unsigned int</fc> turbo_curve_1[5] = { <fc #ffa500>**760,720,680,640,600**</fc> };'' 
-\\ ''<fc #4682b4>const unsigned int</fc> turbo_curve_2[5] = { <fc #ffa500>**820,760,720,660,620**</fc> };'' +\\ ''<fc #4682b4>const unsigned int</fc> turbo_curve_2[5] = { <fc #ffa500>**780,740,700,660,620**</fc> };'' 
-\\ ''<fc #4682b4>const unsigned int</fc> turbo_curve_3[5] = { <fc #ffa500>**840,780,740,680,640**</fc> };'' +\\ ''<fc #4682b4>const unsigned int</fc> turbo_curve_3[5] = { <fc #ffa500>**800,760,720,680,640**</fc> };'' 
-\\ ''<fc #4682b4>const unsigned int</fc> turbo_curve_4[5] = { <fc #ffa500>**860,800,760,700,660**</fc> };''+\\ ''<fc #4682b4>const unsigned int</fc> turbo_curve_4[5] = { <fc #ffa500>**820,780,740,700,660**</fc> };''
  
 **Turbo** **Turbo**
Line 76: Line 77:
 The acceleration variable, is computed at 100ms and 10ms, and it represents the turbo rpm acceleration rate in, rpm per ms. The acceleration variable, is computed at 100ms and 10ms, and it represents the turbo rpm acceleration rate in, rpm per ms.
 <code> <code>
-    // Division by 10 +  // Update turbo_accel before calculating vane_position 
-    turbo_accel[0] = ((turbo_rpm - last_turbo_rpm[0]) * 205) >> 11;+  if (timer % 10 == 0) { 
 +    turbo_accel[0] = (int) (turbo_rpm - last_turbo_rpm[0]) / 10.0f;
     last_turbo_rpm[0] = turbo_rpm;     last_turbo_rpm[0] = turbo_rpm;
     if (timer % 100 == 0) {     if (timer % 100 == 0) {
-      // Division by 100 +      turbo_accel[1] = (int) (turbo_rpm - last_turbo_rpm[1]) / 100.0f;
-      turbo_accel[1] = ((turbo_rpm - last_turbo_rpm[1]) * 164) >> 14;+
       last_turbo_rpm[1] = turbo_rpm;       last_turbo_rpm[1] = turbo_rpm;
     }     }
     if (turbo_rpm < top_end_rpm) { turbo_accel[2] = turbo_accel[1]; } else { turbo_accel[2] = turbo_accel[0]; }     if (turbo_rpm < top_end_rpm) { turbo_accel[2] = turbo_accel[1]; } else { turbo_accel[2] = turbo_accel[0]; }
 +  }
 </code> </code>
 \\ **<fc #6495ed>last_turbo_rpm[0]</fc>** is updated every 10ms \\ **<fc #6495ed>last_turbo_rpm[0]</fc>** is updated every 10ms
Line 95: Line 97:
           // -----           // -----
           // Idle Section           // Idle Section
-          idle_check = false; 
           if (turbo_rpm <= idle_rpm) {           if (turbo_rpm <= idle_rpm) {
-            vane_position = idle_position; 
             idle_mode = true;             idle_mode = true;
             idle_walkdown_mode = false;             idle_walkdown_mode = false;
           } else {           } else {
             idle_mode = false;             idle_mode = false;
-            if (idle_walkdown_mode) { vane_position = last_vane_position - quarter_cm; } else { vane_position = turbo_curve[0]; } 
           }           }
 +          if (turbo_accel[2] <= 2) { vane_position = idle_position; } else { vane_position = turbo_curve[0]; }
         } else {         } else {
           // -----           // -----
           // Curve section           // Curve section
-          if (turbo_rpm <idle_walkdown_rpm && idle_check) { idle_walkdown_mode true; } else idle_walkdown_mode = false; } +               if (turbo_rpm < idle_walkdown_rpm) { 
-          if (turbo_rpm idle_walkdown_rpm) { idle_check = true; } +                 if (turbo_accel[2] <2) 
-               if (idle_walkdown_mode) { vane_position = last_vane_position - quarter_cm; }+                   if (last_vane_position >= min_position + half_cm) { 
 +                     idle_walkdown_mode = true; 
 +                     vane_position = last_vane_position - half_cm; 
 +                   } else { 
 +                     vane_position = min_position; 
 +                   } 
 +                 } else { 
 +                   vane_position = 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[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[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 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]); }           else { vane_position = map(turbo_rpm, curve_rpm[3], curve_rpm[4], turbo_curve[2], turbo_curve[3]); }
 +          if (turbo_accel[2] > 2) { idle_walkdown_mode = false; }
         }         }
 </code> </code>
Line 155: Line 165:
 Cruise mode tries to keep turbo rpm within 47,500 to 52,500. Roughly 5,000 total rpm difference. Cruise mode tries to keep turbo rpm within 47,500 to 52,500. Roughly 5,000 total rpm difference.
 <code> <code>
 +byte counter = 0;
 +byte adjustment = 0;
 +
 void cruise() { void cruise() {
-  if (turbo_rpm > 55000) { vane_position -= one_cm; } +  if (turbo_rpm > 55000) { 
-  if (turbo_rpm > 52500) { vane_position -= half_cm; }+    adjustment = one_cm; 
 +  
 +  if (turbo_rpm > 52500) { 
 +    adjustment = half_cm; 
 +    counter++; 
 +  } 
 +  if (counter > 3) { 
 +    counter = 0; 
 +    vane_position -= adjustment; 
 +  }
   if (vane_position <= min_position) { vane_position = min_position; }   if (vane_position <= min_position) { vane_position = min_position; }
-  if (turbo_rpm < 47500) { vane_position += quarter_cm; }+  if (turbo_rpm < 47500) { 
 +    vane_position += quarter_cm; 
 +    counter = 0; 
 +  }
   if (vane_position >= cruise_position) { vane_position = cruise_position; }   if (vane_position >= cruise_position) { vane_position = cruise_position; }
 +  constrain(vane_position, min_position, max_position);
 } }
 </code> </code>
   * When turbo rpm is under 47,500 vane position is set to variable **<fc #6495ed>cruise_position</fc>**.   * When turbo rpm is under 47,500 vane position is set to variable **<fc #6495ed>cruise_position</fc>**.
-  * When turbo rpm is over 52,500 vane position decreases every 100ms until turbo rpm is finally within bounds.+  * When turbo rpm is over 52,500 vane position decreases every ~400ms until turbo rpm is finally within bounds.
  
 ---- ----
Line 176: Line 202:
     vane_position = max_position;     vane_position = max_position;
   }   }
 +  constrain(vane_position, min_position, max_position);
 } }
 </code> </code>
Line 212: Line 239:
       }       }
     }     }
 +  } else if (turbo_rpm > top_end_rpm) {
 +    if (vane_position - 5 >= last_vane_position || vane_position + 5 <= last_vane_position) { final_vane_position = vane_position; } else { final_vane_position = last_vane_position; }
   }   }
   // Update last_vane_position   // Update last_vane_position
Line 228: Line 257:
 void keep_time() { void keep_time() {
   timer++;   timer++;
-  // Update vane_position every 10ms 100k+ / 25ms 60k - 100k / 50ms 0 - 60k+  // Update vane_position every 10ms 100k+ / 25ms 60k - 100k / 100ms 0 - 60k
        if (timer % 10 == 0 && turbo_rpm > top_end_rpm) { update_vane_position = true; }        if (timer % 10 == 0 && turbo_rpm > top_end_rpm) { update_vane_position = true; }
   else if (timer % 25 == 0 && turbo_rpm > curve_rpm[4]) { update_vane_position = true; }   else if (timer % 25 == 0 && turbo_rpm > curve_rpm[4]) { update_vane_position = true; }
-  else if (timer % 50 == 0) { update_vane_position = true; }+  else if (timer % 100 == 0) { update_vane_position = true; }
   // Update turbo_accel before calculating vane_position   // Update turbo_accel before calculating vane_position
   if (timer % 10 == 0) {   if (timer % 10 == 0) {
-    // Division by 10 +    turbo_accel[0] = (int) (turbo_rpm - last_turbo_rpm[0]) / 10.0f;
-    turbo_accel[0] = ((turbo_rpm - last_turbo_rpm[0]) * 205) >> 11;+
     last_turbo_rpm[0] = turbo_rpm;     last_turbo_rpm[0] = turbo_rpm;
     if (timer % 100 == 0) {     if (timer % 100 == 0) {
-      // Division by 100 +      turbo_accel[1] = (int) (turbo_rpm - last_turbo_rpm[1]) / 100.0f;
-      turbo_accel[1] = ((turbo_rpm - last_turbo_rpm[1]) * 164) >> 14;+
       last_turbo_rpm[1] = turbo_rpm;       last_turbo_rpm[1] = turbo_rpm;
     }     }
Line 245: Line 272:
   }   }
   // Modes   // Modes
-  if (timer % 100 == 0) { calculate_modes(); }+  if (timer % 100 == 0 && turbo_rpm < top_end_rpm) { calculate_modes(); }
   // Calculate vane_position   // Calculate vane_position
-  if (update_vane_position) { update_vane_position = false; calculate_vane_position();+  if (update_vane_position) { 
-  if (serial_out) { +    update_vane_position = false; 
-    if (turbo_rpm < top_end_rpm && timer % 100 == 0) { serial_output(); } +    calculate_vane_position(); 
-    if (turbo_rpm > top_end_rpm && timer % 10 == 0) { serial_output(); }+    if (serial_out) { serial_output(); }
   }   }
   if (timer == 1000) { timer = 0; }   if (timer == 1000) { timer = 0; }
 } }
 </code> </code>
common_code.txt · Last modified: 2015/10/30 12:54 by hakcenter