common_code_v1
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
common_code_v1 [2016/08/26 12:49] – [Variables] hakcenter | common_code_v1 [2016/08/26 12:51] – [Timer2] hakcenter | ||
---|---|---|---|
Line 245: | Line 245: | ||
==== Timer1 ==== | ==== Timer1 ==== | ||
< | < | ||
- | void set_turbo_position() { | + | /* |
- | | + | |
- | | + | * All rights reserved. |
- | | + | * |
- | // Vane smoothing between large values | + | |
- | if (turbo_rpm < top_end_rpm && turbo_rpm | + | * Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. |
- | | + | * To view a copy of this license, |
- | | + | |
- | | + | */ |
- | | + | |
- | } else if (vane_position - 10 >= last_vane_position || vane_position + 10 <= last_vane_position) { | + | void sweep() { |
- | if (vane_position > last_vane_position + 2 && | + | if (turbo_feedback |
- | final_vane_position = last_vane_position + 2; | + | |
- | | + | |
- | | + | |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | if (sweep_counter | ||
+ | | ||
} | } | ||
+ | if (vane_position > 960) { sweep_counter++; | ||
+ | if (sweep_counter > 0) { | ||
+ | vane_position--; | ||
+ | } | ||
+ | if (vane_position < 40) { sweep_counter++; | ||
+ | } | ||
+ | if (sweep_counter == 2 || !sweep_position) { | ||
+ | sweep_position = false; | ||
+ | sweep_update = false; | ||
+ | sweep_counter = 0; | ||
+ | Serial.println(F(" | ||
+ | } | ||
+ | } else { sweep_update = true; } | ||
+ | } | ||
+ | |||
+ | void set_turbo_position() { | ||
+ | // if not sweeping smoothe vane changes | ||
+ | if (!sweep_position) { | ||
+ | // Keep vane position within constraints | ||
+ | constrain(vane_position, | ||
+ | final_vane_position = vane_position; | ||
+ | // Vane smoothing between large values | ||
+ | //if (turbo_rpm < curve_rpm[0] && (vane_position <= last_vane_position - 20 && last_vane_position > min_position + 10)) { final_vane_position = last_vane_position - 10; } | ||
+ | if (turbo_rpm < curve_rpm[0] && (vane_position <= last_vane_position - half_cm)) { final_vane_position = last_vane_position - quarter_cm; } | ||
+ | else if (!brake_mode && turbo_rpm >= curve_rpm[0] && turbo_rpm < top_end_rpm) { | ||
+ | // if vane_position change is 20 or more, move by half the difference | ||
+ | if (vane_position >= last_vane_position + 20) { final_vane_position = vane_position + ((last_vane_position - vane_position) >> 2); } | ||
+ | else if (vane_position <= last_vane_position - 20) { final_vane_position = vane_position - ((last_vane_position - vane_position) >> 2); } | ||
+ | // if vane_position change is 10 or less, move by 2 | ||
+ | if (vane_position - 10 >= last_vane_position) { final_vane_position = last_vane_position + 2; } | ||
+ | else if (vane_position + 10 <= last_vane_position) { final_vane_position = last_vane_position - 2; } | ||
+ | // end smoothing | ||
+ | } else if (turbo_rpm > top_end_rpm) { | ||
+ | // remove jitter during top end turbo speeds | ||
+ | if (vane_position - 5 >= last_vane_position || vane_position + 5 <= last_vane_position) { final_vane_position = vane_position; | ||
+ | } | ||
+ | /* | ||
+ | // Decel position on decel | ||
+ | if (turbo_accel[2] < -20 && turbo_rpm > 30000) { | ||
+ | vane_position = deceleration_position; | ||
+ | final_vane_position = deceleration_position; | ||
} | } | ||
- | | + | */ |
- | | + | // Constrain and update last_vane_position |
+ | constrain(final_vane_position, | ||
+ | last_vane_position = final_vane_position; | ||
+ | | ||
+ | // Ignore vane changes until startup is complete | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
} | } | ||
- | // Update last_vane_position | ||
- | last_vane_position = final_vane_position; | ||
byte lo_byte = lowByte(final_vane_position); | byte lo_byte = lowByte(final_vane_position); | ||
byte hi_byte = highByte(final_vane_position); | byte hi_byte = highByte(final_vane_position); | ||
Line 272: | Line 328: | ||
// data[2] = 0x02 for recalibrating gearbox | // data[2] = 0x02 for recalibrating gearbox | ||
// Load message and send | // Load message and send | ||
- | | + | |
} | } | ||
</ | </ | ||
Line 280: | Line 336: | ||
void keep_time() { | void keep_time() { | ||
timer++; | timer++; | ||
+ | // Startup Timer | ||
+ | if (turbo_rpm < minimum_turbo_rpm) { | ||
+ | if (startup > 249) { startup = 250; } | ||
+ | startup++; | ||
+ | } | ||
// Update vane_position every 10ms 100k+ / 25ms 60k - 100k / 100ms 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; } | ||
Line 294: | Line 355: | ||
if (turbo_rpm < top_end_rpm) { turbo_accel[2] = turbo_accel[1]; | if (turbo_rpm < top_end_rpm) { turbo_accel[2] = turbo_accel[1]; | ||
} | } | ||
+ | // Read Serial Input | ||
+ | if (timer % 10 == 0 && check_serial()) { read_serial(); | ||
+ | // Read CAN BUS | ||
+ | if (timer % 25 == 0) { read_can_data(can_id, | ||
// Modes | // Modes | ||
if (timer % 100 == 0 && turbo_rpm < top_end_rpm) { calculate_modes(); | if (timer % 100 == 0 && turbo_rpm < top_end_rpm) { calculate_modes(); | ||
+ | // Sweep vane_position | ||
+ | if (timer % 25 == 0 && sweep_position) { sweep(); } | ||
// Calculate vane_position | // Calculate vane_position | ||
- | if (update_vane_position) { | + | if (update_vane_position |
update_vane_position = false; | update_vane_position = false; | ||
calculate_vane_position(); | calculate_vane_position(); |
common_code_v1.txt · Last modified: 2016/08/26 12:52 by hakcenter