diff --git a/ECU.ino b/ECU.ino index d51dfee..fa17d87 100644 --- a/ECU.ino +++ b/ECU.ino @@ -19,6 +19,16 @@ void setup() { digitalWrite(pin_coil1, LOW); digitalWrite(pin_coil2, LOW); + pinMode(pin_injector1, OUTPUT); + pinMode(pin_injector2, OUTPUT); + pinMode(pin_injector3, OUTPUT); + pinMode(pin_injector4, OUTPUT); + + digitalWrite(pin_injector1, LOW); + digitalWrite(pin_injector2, LOW); + digitalWrite(pin_injector3, LOW); + digitalWrite(pin_injector4, LOW); + // Set up serial speed etc and do intro output debug_setup(); diff --git a/battery.ino b/battery.ino index 622d97c..146b5b8 100644 --- a/battery.ino +++ b/battery.ino @@ -8,7 +8,7 @@ void battery_init() { Serial.println("ERR: Battery low"); } - else if(battery_voltage_value > 14) + else if(battery_voltage_value > 15) { Serial.println("ERR: Battery high"); } diff --git a/cas.ino b/cas.ino index d1e2665..d86e7e4 100644 --- a/cas.ino +++ b/cas.ino @@ -69,6 +69,7 @@ void cas_process() // If we're out of sync, we kill ignition for a bit for now. Same if we're at crazy RPM if((cas_sync_fail == 0) && (rpm_limited == 0)) { + // Igntion if((cylinder_next_fire == 1) || (cylinder_next_fire == 4)) { task_coil1_fire = micros() + (usec_per_degree * (180 + ignition_offset - table_ignition[rpm_current_index + (map_current_index << 4)])); @@ -78,6 +79,25 @@ void cas_process() task_coil2_fire = micros() + (usec_per_degree * (180 + ignition_offset - table_ignition[rpm_current_index + (map_current_index << 4)])); task_coil2_charge = task_coil2_fire - (coil_dwell + table_dwell_voltage[battery_voltage_index] + table_dwell_rpm[rpm_current_index]); } + + // Injection + if(cylinder_next_fire == 1) + { + task_injector1_close = micros() + (usec_per_degree * (360 + ignition_offset + 130)); + task_injector1_open = task_injector1_close - table_pulsewidth[rpm_current_index + (map_current_index << 4)]; + }else if(cylinder_next_fire == 2) + { + task_injector2_close = micros() + (usec_per_degree * (360 + ignition_offset + 130)); + task_injector2_open = task_injector2_close - table_pulsewidth[rpm_current_index + (map_current_index << 4)]; + }else if(cylinder_next_fire == 3) + { + task_injector3_close = micros() + (usec_per_degree * (360 + ignition_offset + 130)); + task_injector3_open = task_injector3_close - table_pulsewidth[rpm_current_index + (map_current_index << 4)]; + }else if(cylinder_next_fire == 4) + { + task_injector4_close = micros() + (usec_per_degree * (360 + ignition_offset + 130)); + task_injector4_open = task_injector4_close - table_pulsewidth[rpm_current_index + (map_current_index << 4)]; + } } } } diff --git a/data.h b/data.h index d8cb000..ff9dc93 100644 --- a/data.h +++ b/data.h @@ -13,8 +13,7 @@ const int rpm_range_min = 0; // Index 0 const int rpm_range_max = 7200; // Index 15 byte rpm_current_index = 0; // Table index of current RPM int rpm_current_value = 0; // Current engine RPM -int usec_per_degree = 0; // uSec per degree of rotation at current RPM -//unsigned long usec_per_degree = 0; +unsigned long usec_per_degree = 0; // uSec per degree of rotation at current RPM // Cam Angle Sensor unsigned long cas_sgt_lastrise = 0; // micros() of the last rise diff --git a/injection.ino b/injection.ino new file mode 100644 index 0000000..2018cd2 --- /dev/null +++ b/injection.ino @@ -0,0 +1,10 @@ +void task_injectorx_close_run(int pin) +{ + digitalWrite(pin, LOW); +} + +void task_injectorx_open_run(int pin) +{ + digitalWrite(pin, HIGH); +} + diff --git a/pins.h b/pins.h index 6be5472..897c6f0 100644 --- a/pins.h +++ b/pins.h @@ -12,10 +12,10 @@ const int pin_map = A3; // IN: Manifold absolute pressure const int pin_batt = A4; // IN: Battery voltage //const int pin_o2 = A8; // IN: O2 sensor -//const int pin_injector1 = 8; -//const int pin_injector2 = 9; -//const int pin_injector3 = 10; -//const int pin_injector4 = 11; +const int pin_injector1 = 8; +const int pin_injector2 = 9; +const int pin_injector3 = 10; +const int pin_injector4 = 11; const int pin_coil1 = 47; const int pin_coil2 = 45; diff --git a/schedule.h b/schedule.h index c9b592f..720c360 100644 --- a/schedule.h +++ b/schedule.h @@ -17,7 +17,15 @@ unsigned long task_tach_high = 0; // Ilde unsigned long task_tach_low = 0; // Idle unsigned long task_coil1_charge = 0; // Idle -unsigned long task_coil1_fire = 0; // Idle +unsigned long task_coil1_fire = 1; // Looks mad but stops us cooking coils unsigned long task_coil2_charge = 0; // Idle -unsigned long task_coil2_fire = 0; // Idle +unsigned long task_coil2_fire = 1; // Looks mad but stops us cooking coils +unsigned long task_injector1_open = 0; // Idle +unsigned long task_injector1_close = 1; // Idle +unsigned long task_injector2_open = 0; // Idle +unsigned long task_injector2_close = 1; // Idle +unsigned long task_injector3_open = 0; // Idle +unsigned long task_injector3_close = 1; // Idle +unsigned long task_injector4_open = 0; // Idle +unsigned long task_injector4_close = 1; // Idle diff --git a/schedule.ino b/schedule.ino index a1cb90e..6cbde57 100644 --- a/schedule.ino +++ b/schedule.ino @@ -30,6 +30,58 @@ void schedule_process() tasks++; } + // Injector 1 + if((task_injector1_close > 0) && (micros() > task_injector1_close)) + { + task_injectorx_close_run(pin_injector1); + task_injector1_close = 0; + tasks++; + }else if((task_injector1_open > 0) && (micros() > task_injector1_open)) + { + task_injectorx_open_run(pin_injector1); + task_injector1_open= 0; + tasks++; + } + + // Injector 2 + if((task_injector2_close > 0) && (micros() > task_injector2_close)) + { + task_injectorx_close_run(pin_injector2); + task_injector2_close = 0; + tasks++; + }else if((task_injector2_open > 0) && (micros() > task_injector2_open)) + { + task_injectorx_open_run(pin_injector2); + task_injector2_open= 0; + tasks++; + } + + // Injector 3 + if((task_injector3_close > 0) && (micros() > task_injector3_close)) + { + task_injectorx_close_run(pin_injector3); + task_injector3_close = 0; + tasks++; + }else if((task_injector3_open > 0) && (micros() > task_injector3_open)) + { + task_injectorx_open_run(pin_injector3); + task_injector3_open= 0; + tasks++; + } + + // Injector 4 + if((task_injector4_close > 0) && (micros() > task_injector4_close)) + { + task_injectorx_close_run(pin_injector4); + task_injector4_close = 0; + tasks++; + }else if((task_injector4_open > 0) && (micros() > task_injector4_open)) + { + task_injectorx_open_run(pin_injector4); + task_injector4_open= 0; + tasks++; + } + // Only carry on to the lower priority stuff if we did nothing else if(tasks > 0) return; diff --git a/tables.h b/tables.h index 98d312e..7babf1b 100644 --- a/tables.h +++ b/tables.h @@ -2,23 +2,23 @@ // Y = kPA 250 - 20 // Index = [rpm_current_index + (map_current_index << 4)] // Value = injector base pulse width -byte table_pulsewidth[] = { - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 +int table_pulsewidth[] = { + 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, + 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, + 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, + 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, + 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, + 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, + 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, + 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, + 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, + 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, + 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, + 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, + 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, + 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, + 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, + 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000 }; // X = RPM 0 - 7200