Much better debug output (controlled) and live re-map support (ha)

This commit is contained in:
Steve Howes
2018-09-23 20:01:12 +01:00
parent 23293422cc
commit b4f0c89561
4 changed files with 174 additions and 48 deletions
+1 -1
View File
@@ -19,11 +19,11 @@ void setup() {
digitalWrite(pin_coil1, LOW); digitalWrite(pin_coil1, LOW);
digitalWrite(pin_coil2, LOW); digitalWrite(pin_coil2, LOW);
// Injector Outputs
pinMode(pin_injector1, OUTPUT); pinMode(pin_injector1, OUTPUT);
pinMode(pin_injector2, OUTPUT); pinMode(pin_injector2, OUTPUT);
pinMode(pin_injector3, OUTPUT); pinMode(pin_injector3, OUTPUT);
pinMode(pin_injector4, OUTPUT); pinMode(pin_injector4, OUTPUT);
digitalWrite(pin_injector1, LOW); digitalWrite(pin_injector1, LOW);
digitalWrite(pin_injector2, LOW); digitalWrite(pin_injector2, LOW);
digitalWrite(pin_injector3, LOW); digitalWrite(pin_injector3, LOW);
+5 -1
View File
@@ -46,8 +46,12 @@ void cas_process()
// We'll drop sparks until we're back and log it // We'll drop sparks until we're back and log it
if(cylinder_next_seq[cylinder_tdc] != 1) if(cylinder_next_seq[cylinder_tdc] != 1)
{ {
cas_sync_fail=1; // Don't output if it's already happened once
if(cas_sync_fail == 0)
cas_sync_fail_log=1; cas_sync_fail_log=1;
// Log fail so we abandon time sensitive stuff
cas_sync_fail=1;
} }
else else
{ {
+154 -32
View File
@@ -1,48 +1,20 @@
byte debug_live_index = 0;
byte debug_rpm = 0;
void debug_setup() void debug_setup()
{ {
Serial.begin(115200); Serial.begin(115200);
// Flush
Serial.println(""); Serial.println("");
Serial.println(""); Serial.println("");
Serial.print("DAT: ");
Serial.print("map_current_index");
Serial.print(",");
Serial.print("rpm_current_index");
Serial.print(",");
Serial.print("battery_voltage_index");
Serial.print(",");
Serial.print("map_current_value");
Serial.print(",");
Serial.print("rpm_current_value");
Serial.print(",");
Serial.print("battery_voltage_value");
Serial.print(",");
Serial.print("throttle_current_value");
Serial.println("");
// Now we have init we can do real loop // Now we have init we can do real loop
task_debug = 1; task_debug = 1;
} }
void task_debug_run() void task_debug_run()
{ {
Serial.print("DAT: ");
Serial.print(map_current_index);
Serial.print(",");
Serial.print(rpm_current_index);
Serial.print(",");
Serial.print(battery_voltage_index);
Serial.print(",");
Serial.print(map_current_value);
Serial.print(",");
Serial.print(rpm_current_value);
Serial.print(",");
Serial.print(battery_voltage_value);
Serial.print(",");
Serial.print(throttle_current_value);
Serial.println("");
// Log if we're out of sync timing-wise // Log if we're out of sync timing-wise
if(cas_sync_fail_log > 0) if(cas_sync_fail_log > 0)
{ {
@@ -56,6 +28,156 @@ void task_debug_run()
Serial.println("ERR: RPM limit"); Serial.println("ERR: RPM limit");
rpm_limited_log = 0; rpm_limited_log = 0;
} }
// If we're outputting live index - print it
if(debug_live_index == 1)
{
Serial.print("IDX: ");
Serial.println(rpm_current_index + (map_current_index << 4));
} }
// If we're currently outputting RPM - print it
if(debug_rpm == 1)
{
Serial.print("RPM: ");
Serial.println(rpm_current_value);
}
// If we're being asked for something
if (Serial.available() > 0)
{
// Kills ignition and injection until CAS re-sync (for safety in long I/O)
task_debug_safekill();
// Read the first char (the command)
char readbyte = Serial.read();
if(readbyte == 't') // Dump table
{
readbyte = Serial.read();
// i for ignition and f for fel
if(readbyte == 'f')
task_debug_dumpfueltable();
else if(readbyte == 'i')
task_debug_dumpignitiontable();
}
else if(readbyte == 'T') // Ammend table
{
// Up to the first comma is the table (as on a read)
String table = "";
while(1)
{
readbyte = Serial.read();
if(readbyte == ',')
break;
else
table += readbyte;
}
// The next parameter is the index in the table (TODO: bounds check?)
String index = "";
while(1)
{
readbyte = Serial.read();
if(readbyte == ',')
break;
else
index += readbyte;
}
// The final section is the value in decimal (TODO: bounds check?)
String value = "";
while(1)
{
readbyte = Serial.read();
if(readbyte == '\n')
break;
else
value += readbyte;
}
// Update the value
if(table == "i")
{
table_ignition[index.toInt()] = value.toInt();
}else if(table == "f")
{
table_pulsewidth[index.toInt()] = value.toInt();
}
}else if(readbyte == 'i') // Disable index output
{
debug_live_index = 0;
}else if(readbyte == 'I') // Enable index output
{
debug_live_index = 1;
}else if(readbyte == 'r') // Disable RPM output
{
debug_rpm = 0;
}else if(readbyte == 'R') // Enable RPM output
{
debug_rpm = 1;
}
}
}
// Outputs the fuel table as JSON
void task_debug_dumpfueltable()
{
Serial.print("TBF: [");
for(int i=0; i <= 255; i++)
{
Serial.print(table_pulsewidth[i]);
if(i != 255)
Serial.print(",");
}
Serial.print("]\n");
}
// Ignition table as json
void task_debug_dumpignitiontable()
{
Serial.print("TBI: [");
for(int i=0; i <= 255; i++)
{
Serial.print(table_ignition[i]);
if(i != 255)
Serial.print(",");
}
Serial.print("]\n");
}
// Stops charging all coils, closes all injectors
// Marks CAS as out of sync to prevent anything changing
void task_debug_safekill()
{
// Stop charging coils
task_coilx_fire_run(pin_coil1);
task_coilx_fire_run(pin_coil2);
// Close all injectors
task_injectorx_close_run(pin_injector1);
task_injectorx_close_run(pin_injector2);
task_injectorx_close_run(pin_injector3);
task_injectorx_close_run(pin_injector4);
// Cancel all scheduled timing-sensitive events
task_coil1_charge = 0;
task_coil1_fire = 0;
task_coil2_charge = 0;
task_coil2_fire = 0;
task_injector1_open = 0;
task_injector1_close = 0;
task_injector2_open = 0;
task_injector2_close = 0;
task_injector3_open = 0;
task_injector3_close = 0;
task_injector4_open = 0;
task_injector4_close = 0;
// And dont schedule any more until we're back in sync (two Cly1 TDC events matching predictions)
cas_sync_fail=1;
cas_sync_fail_log=0;
}
+14 -14
View File
@@ -1,8 +1,16 @@
// X = RPM 0 - 7200 // X = RPM 0 - 7200
// Y = kPA 250 - 20 // Y = kPA 20 - 250
// 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
int table_pulsewidth[] = { int table_pulsewidth[] = {
2010, 2020, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2030, 2040,
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,
3000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 4000,
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,
@@ -10,19 +18,11 @@ 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, 2050, 2060, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2070, 2080
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 // X = RPM 0 - 15 (0 - 7200)
// Y = kPA 250 - 20 // Y = kPA 0 - 15 (20 - 250)
// Index = [rpm_current_index + (map_current_index << 4)] // Index = [rpm_current_index + (map_current_index << 4)]
// Value = degrees // Value = degrees
byte table_ignition[] = { byte table_ignition[] = {
@@ -44,14 +44,14 @@ byte table_ignition[] = {
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10
}; };
// X = Voltage 7-16 // X = Voltage 0 - 9 (7-16)
// Index = [battery_voltage_index] // Index = [battery_voltage_index]
// Value = additional dwell in usec // Value = additional dwell in usec
const int table_dwell_voltage[] = { const int table_dwell_voltage[] = {
2000, 2000, 2000, 2000, 1000, 0, 0, 0, 0, 0 2000, 2000, 2000, 2000, 1000, 0, 0, 0, 0, 0
}; };
// X = RPM 0 - 7200 // X = RPM 0 - 15 (0 - 7200)
// Index = [rpm_current_index] // Index = [rpm_current_index]
// Value = additional dwell in usec // Value = additional dwell in usec
const int table_dwell_rpm[] = { const int table_dwell_rpm[] = {