mirror of
https://github.com/stevenhowes/MX5-Arduino.git
synced 2026-05-26 15:53:40 +01:00
Fuel injection WIP - map only suitable for warm idle
This commit is contained in:
@@ -19,6 +19,16 @@ void setup() {
|
|||||||
digitalWrite(pin_coil1, LOW);
|
digitalWrite(pin_coil1, LOW);
|
||||||
digitalWrite(pin_coil2, 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
|
// Set up serial speed etc and do intro output
|
||||||
debug_setup();
|
debug_setup();
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ void battery_init()
|
|||||||
{
|
{
|
||||||
Serial.println("ERR: Battery low");
|
Serial.println("ERR: Battery low");
|
||||||
}
|
}
|
||||||
else if(battery_voltage_value > 14)
|
else if(battery_voltage_value > 15)
|
||||||
{
|
{
|
||||||
Serial.println("ERR: Battery high");
|
Serial.println("ERR: Battery high");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 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))
|
if((cas_sync_fail == 0) && (rpm_limited == 0))
|
||||||
{
|
{
|
||||||
|
// Igntion
|
||||||
if((cylinder_next_fire == 1) || (cylinder_next_fire == 4))
|
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)]));
|
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_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]);
|
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)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ const int rpm_range_min = 0; // Index 0
|
|||||||
const int rpm_range_max = 7200; // Index 15
|
const int rpm_range_max = 7200; // Index 15
|
||||||
byte rpm_current_index = 0; // Table index of current RPM
|
byte rpm_current_index = 0; // Table index of current RPM
|
||||||
int rpm_current_value = 0; // Current engine 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; // uSec per degree of rotation at current RPM
|
||||||
//unsigned long usec_per_degree = 0;
|
|
||||||
|
|
||||||
// Cam Angle Sensor
|
// Cam Angle Sensor
|
||||||
unsigned long cas_sgt_lastrise = 0; // micros() of the last rise
|
unsigned long cas_sgt_lastrise = 0; // micros() of the last rise
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
void task_injectorx_close_run(int pin)
|
||||||
|
{
|
||||||
|
digitalWrite(pin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void task_injectorx_open_run(int pin)
|
||||||
|
{
|
||||||
|
digitalWrite(pin, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -12,10 +12,10 @@ const int pin_map = A3; // IN: Manifold absolute pressure
|
|||||||
const int pin_batt = A4; // IN: Battery voltage
|
const int pin_batt = A4; // IN: Battery voltage
|
||||||
//const int pin_o2 = A8; // IN: O2 sensor
|
//const int pin_o2 = A8; // IN: O2 sensor
|
||||||
|
|
||||||
//const int pin_injector1 = 8;
|
const int pin_injector1 = 8;
|
||||||
//const int pin_injector2 = 9;
|
const int pin_injector2 = 9;
|
||||||
//const int pin_injector3 = 10;
|
const int pin_injector3 = 10;
|
||||||
//const int pin_injector4 = 11;
|
const int pin_injector4 = 11;
|
||||||
|
|
||||||
const int pin_coil1 = 47;
|
const int pin_coil1 = 47;
|
||||||
const int pin_coil2 = 45;
|
const int pin_coil2 = 45;
|
||||||
|
|||||||
+10
-2
@@ -17,7 +17,15 @@ unsigned long task_tach_high = 0; // Ilde
|
|||||||
unsigned long task_tach_low = 0; // Idle
|
unsigned long task_tach_low = 0; // Idle
|
||||||
|
|
||||||
unsigned long task_coil1_charge = 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_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
|
||||||
|
|||||||
@@ -30,6 +30,58 @@ void schedule_process()
|
|||||||
tasks++;
|
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
|
// Only carry on to the lower priority stuff if we did nothing else
|
||||||
if(tasks > 0)
|
if(tasks > 0)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -2,23 +2,23 @@
|
|||||||
// Y = kPA 250 - 20
|
// Y = kPA 250 - 20
|
||||||
// Index = [rpm_current_index + (map_current_index << 4)]
|
// Index = [rpm_current_index + (map_current_index << 4)]
|
||||||
// Value = injector base pulse width
|
// Value = injector base pulse width
|
||||||
byte table_pulsewidth[] = {
|
int table_pulsewidth[] = {
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
|
||||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
|
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000
|
||||||
};
|
};
|
||||||
|
|
||||||
// X = RPM 0 - 7200
|
// X = RPM 0 - 7200
|
||||||
|
|||||||
Reference in New Issue
Block a user