TPS read and tidy up

This commit is contained in:
Steve Howes
2018-09-14 18:33:36 +01:00
parent 437a2cc9a5
commit b0d2f98594
7 changed files with 85 additions and 52 deletions
+3 -1
View File
@@ -7,6 +7,7 @@ void setup() {
// Sensors
pinMode(pin_map, INPUT);
pinMode(pin_batt, INPUT);
pinMode(pin_throttle, INPUT);
// Dash / debug outputs
pinMode(pin_tach, OUTPUT);
@@ -21,9 +22,10 @@ void setup() {
// Set up serial speed etc and do intro output
debug_setup();
// Get an initial reading and output debug if it's not atmospheric
// Get initial values and check they are sane
map_init();
battery_init();
throttle_init();
}
void loop() {
+9 -3
View File
@@ -25,14 +25,14 @@ unsigned long cas_sgc_lastrise = 0; // micros() of the las
unsigned long cas_sgc_lastfall = 0; // "" of the last fall
byte cas_sgc_lastvalue = 0; // The state of SGC on the previous cycle
byte cas_sync_fail = 0;
byte cas_sync_fail_log = 0;
byte cas_sync_fail = 0; // We lost track of a cylinder
byte cas_sync_fail_log = 0; // We need to output this in debug
// Cylinder sequencing
byte cylinder_tdc = 0; // Most recent cylinder to hit TDC
byte cylinder_next_fire = 0; // Next cylinder due a spark
//byte cylinder_next_inject = 0; // Next cylinder due fuel
byte cylinder_next[] = {0,2,1,2,1}; // CAn be 0,3,1,4,2 if we ever go sequential
byte cylinder_next[] = {0,2,1,2,1}; // Can be 0,3,1,4,2 if we ever go sequential
// Ignition
const int coil_dwell = 4000; // 4 read from scope on factory ECU
@@ -53,3 +53,9 @@ byte battery_voltage_index = 7; // The above as an ind
const int battery_cal_7v = 252; // Cal value for 7v using 10k/1k potential divider
const int battery_cal_16v = 579; // The above for 16v
// TPS
byte throttle_current_value = 0; // Percentage
byte throttle_previous_1_value = 0; // Percentage
byte throttle_previous_2_value = 0; // Percentage
byte throttle_delta = 0; // Difference between current and delta
+4
View File
@@ -17,6 +17,8 @@ void debug_setup()
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
@@ -37,6 +39,8 @@ void task_debug_run()
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
+1 -1
View File
@@ -7,7 +7,7 @@ const int pin_cas_sgt = 18; // IN: ignition pulse -white
const int pin_tach = 49; // OUT: pulse for tach
//const int pin_intake_temp = A0; // IN: Intake temperature
//const int pin_coolant_temp = A1; // IN: Coolant temperature
//const int pin_throttle_position = A2; // IN: Throttle position
const int pin_throttle = A2; // IN: Throttle position
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
+3
View File
@@ -1,6 +1,9 @@
unsigned long task_map = 1; // Get initial figure
const unsigned long task_map_interval = 93000; // 93ms
unsigned long task_throttle = 1; // Get initial figure
const unsigned long task_throttle_interval = 88000; // 88ms
unsigned long task_rpm = 1; // Get initial figure
const unsigned long task_rpm_interval = 199000; // 199ms
+5
View File
@@ -45,6 +45,11 @@ void schedule_process()
task_rpm = micros() + task_rpm_interval;
task_rpm_run();
tasks++;
}else if(micros() > task_throttle)
{
task_throttle = micros() + task_throttle_interval;
task_throttle_run();
tasks++;
}else if(micros() > task_battery)
{
task_battery = micros() + task_battery_interval;
+13
View File
@@ -0,0 +1,13 @@
void throttle_init()
{
task_throttle_run();
}
void task_throttle_run()
{
throttle_previous_2_value = throttle_previous_1_value;
throttle_previous_1_value = throttle_current_value;
throttle_current_value = map(analogRead(pin_throttle), 0, 1023, 0, 100);
}