diff --git a/reference/speeduino.ini b/reference/speeduino.ini index 7dce59cd..05478134 100644 --- a/reference/speeduino.ini +++ b/reference/speeduino.ini @@ -431,7 +431,7 @@ page = 1 #endif ;VSS settings - vssMode = bits, U08, 102, [0:1], "Off", "INVALID", "Pulses per KM", "Pulses per mile" ;INVALID value will be CAN + vssMode = bits, U08, 102, [0:1], "Off", "CAN/Serial/Analog", "Pulses per KM", "Pulses per mile" ;vssPullup = bits, U08, 102, [1:1], "Off", "On" vssPin = bits, U08, 102, [2:7], "Board Default", "INVALID", "INVALID", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "INVALID", "A8", "A9", "A10", "A11", "A12", "A13", "A14", "A15", "INVALID" vssPulsesPerKm= scalar, U16, 103, "pulses", 1.0, 0.0, 0.0, 25500, 0 @@ -463,7 +463,7 @@ page = 1 ;These are reserved for future use, in case of more CAN broadcasting features are added enable1Cluster = bits, U08, 126, [2:2], "Off", "On" enable2Cluster = bits, U08, 126, [3:3], "Off", "On" - unusedClusterBits = bits, U08, 126, [4:7], "Off","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID","INVALID" + vssAuxCh = bits, U08, 126, [4:7], "Aux0", "Aux1", "Aux2", "Aux3", "Aux4", "Aux5", "Aux6", "Aux7", "Aux8", "Aux9", "Aux10", "Aux11", "Aux12", "Aux13", "Aux14", "Aux15" decelAmount = scalar, U08, 127, "%", 1.0, 0.0, 0.0, 150.0, 0 @@ -962,9 +962,9 @@ page = 9 caninput_source_num_bytes12 = bits, U16, 65, [12:12], "1", "2" caninput_source_num_bytes13 = bits, U16, 65, [13:13], "1", "2" caninput_source_num_bytes14 = bits, U16, 65, [14:14], "1", "2" - caninput_source_num_bytes15 = bits, U16, 65, [15:15], "1", "2" - - unused10_67 = scalar, U08, 67, "", 1, 0, 0, 255, 0 + caninput_source_num_bytes15 = bits, U16, 65, [15:15], "1", "2" + caninputEndianess = bits, U08, 67, [0:0], "Big-Endian", "Little-Endian" + unused10_68 = scalar, U08, 68, "", 1, 0, 0, 255, 0 enable_intcandata_out = bits, U08, 69, [0:0], "Off", "On" @@ -993,8 +993,8 @@ page = 9 canoutput_param_num_bytes5 = bits, U08, 107, [0:1], "INVALID", "1", "2", "INVALID" canoutput_param_num_bytes6 = bits, U08, 108, [0:1], "INVALID", "1", "2", "INVALID" canoutput_param_num_bytes7 = bits, U08, 109, [0:1], "INVALID", "1", "2", "INVALID" - - unused10_110 = scalar, U08, 110, "", 1, 0, 0, 255, 0 + + unused10_110 = scalar, U08, 110, "", 1, 0, 0, 255, 0 unused10_111 = scalar, U08, 111, "", 1, 0, 0, 255, 0 unused10_112 = scalar, U08, 112, "", 1, 0, 0, 255, 0 unused10_113 = scalar, U08, 113, "", 1, 0, 0, 255, 0 @@ -2064,7 +2064,8 @@ menuDialog = main airConIdleUpRPMAdder = "Increase the idle RPM target (as used by Idle Advance and Closed-Loop Idle) by this amount when the A/C request is active." airConPwmFanMinDuty = "If you are using a PWM cooling fan, the fan duty will be clamped to this value or higher (based on the coolant temp./duty cycle table) when the A/C compressor is engaged." - vssPulsesPerKm = "The number of pulses on the VSS signal per KM/Mile" + vssPulsesPerKm = "The number of pulses on the VSS signal per KM/Mile when "pulses per KM/Mile" -mode is used.\nIn "CAN/Serial/Analog" -mode the Aux input value is divided by this number to get correct VSS. 0 = No dividing/disabled." + vssAuxCh = "Use the Auxilary Input Channel Configuration -menus to read VSS from desired source (CAN/Serial/Analog) and then select that Aux in channel here" vssSmoothing = "A smoothing factor to help reduce noise in the VSS signal. Typical values are between 0 and 50" aeTime = "The duration of the acceleration enrichment" @@ -2357,6 +2358,7 @@ menuDialog = main tachoMode = "The output mode for the tacho pulse. Fixed timing will produce a pulse that is always of the same duration, which works better with mode modern digital tachos. Dwell based output creates a pulse that is matched to the coil/s dwell time. If enabled the tacho pulse duration and timing is same as coil dwell and the number of pulses is same as number of ignition events. This can work better on some styles of tacho but note that the pulse duration might become problem on higher cylinder number engines." canBMWCluster = "Enables CAN broadcasting for BMW E46, E39 and E38 instrument clusters with message ID's 0x316, 0x329 and 0x545" canVAGCluster = "Enables CAN broadcasting for VAG instrument clusters with message ID's 0x280 and 0x5A0" + caninputEndianess= "Byte ordering for values with two bytes." boostControlEnable = "Set the trigger to enable/disable the closedloop boost controller. When set to: \n 'fixed': if the fuel load exceeds the threshold closedloop boost controller is enbaled.\n 'baro': if the fuel load exceeds the baro the controller is enabled (legacy) " boostDCWhenDisabled = "When the closedloop boost controller is disabled by 'enable trigger', this is the Duty cycle set on the boost selenoid. Ususally this is 99% because it keeps the waste gate firmly closed until the threshold and builds boost as fast as possible (no wastegate leak)" @@ -2481,22 +2483,22 @@ menuDialog = main dialog = vss_gear_1, "", xAxis field = "Speed ratio 1", vssRatio1 - commandButton = "Set Gear 1", cmdVSSratio1, { vssMode > 1 } + commandButton = "Set Gear 1", cmdVSSratio1, { vssMode > 0 } dialog = vss_gear_2, "", xAxis field = "Speed ratio 2", vssRatio2 - commandButton = "Set Gear 2", cmdVSSratio2, { vssMode > 1 } + commandButton = "Set Gear 2", cmdVSSratio2, { vssMode > 0 } dialog = vss_gear_3, "", xAxis field = "Speed ratio 3", vssRatio3 - commandButton = "Set Gear 3", cmdVSSratio3, { vssMode > 1 } + commandButton = "Set Gear 3", cmdVSSratio3, { vssMode > 0 } dialog = vss_gear_4, "", xAxis field = "Speed ratio 4", vssRatio4 - commandButton = "Set Gear 4", cmdVSSratio4, { vssMode > 1 } + commandButton = "Set Gear 4", cmdVSSratio4, { vssMode > 0 } dialog = vss_gear_5, "", xAxis field = "Speed ratio 5", vssRatio5 - commandButton = "Set Gear 5", cmdVSSratio5, { vssMode > 1 } + commandButton = "Set Gear 5", cmdVSSratio5, { vssMode > 0 } dialog = vss_gear_6, "", xAxis field = "Speed ratio 6", vssRatio6 - commandButton = "Set Gear 6", cmdVSSratio6, { vssMode > 1 } + commandButton = "Set Gear 6", cmdVSSratio6, { vssMode > 0 } dialog = vss_gear_detection, "Gear Detection", yAxis field = "After setting 'Pulses per km/mile' above" @@ -2509,15 +2511,16 @@ menuDialog = main panel = vss_gear_6 dialog = vss_calibration, "VSS Calibration" - field = "Pulses Per KM", vssPulsesPerKm, { vssMode > 1 } - commandButton = "60km/h auto-calibrate", cmdVSS60kmh, { vssMode > 1 } - field = "Smoothing Factor", vssSmoothing, { vssMode > 1 } + field = "Pulses Per KM/VSS ratio", vssPulsesPerKm, { vssMode > 0 } + commandButton = "60km/h auto-calibrate", cmdVSS60kmh, { vssMode > 0 } + field = "Smoothing Factor", vssSmoothing, { vssMode > 0 } dialog = vssSettings, "", yAxis topicHelp = "https://wiki.speeduino.com/en/configuration/VSS" field = "VSS Input Mode", vssMode field = "VSS Pin", vssPin, { vssMode > 1 } ;field = "Use Pullup", vssPullup, { vssMode > 1 } + field = "VSS Aux in Channel", vssAuxCh, { vssMode == 1 } panel = vss_calibration panel = vss_gear_detection @@ -3183,7 +3186,7 @@ menuDialog = main field = "Valve minimum duty cycle", boostMinDuty, { boostEnabled && boostType == 1 } field = "Valve maximum duty cycle", boostMaxDuty, { boostEnabled && boostType == 1 } panel = boostCut - panel = boostByGear, { boostEnabled && vssMode > 1 } + panel = boostByGear, { boostEnabled && vssMode > 0 } field = "Closed Loop settings" field = "Control mode", boostMode, { boostEnabled && boostType == 1 } field = "Boost control enable trigger", boostControlEnable { boostEnabled && boostType == 1 } @@ -3452,7 +3455,10 @@ menuDialog = main displayOnlyField = !"Internal CANBUS NOT AVAILABLE to MCU", blankfield, {enable_intcan == 1 && intcan_available == 0},{enable_intcan == 1 && intcan_available == 0} displayOnlyField = !"Internal CANBUS NOT AVAILABLE to MCU", blankfield, {enable_intcan == 0 && intcan_available == 0},{enable_intcan == 0 && intcan_available == 0} field = " If Secondary Serial or Internal CANBUS is DISABLED then any input channel assigned to that external source will NOT function" - + + dialog = selectionOfEdianness. , "Endianness", yAxis + field = "", caninputEndianess {(enable_intcan && intcan_available)} + dialog = canAuxinput_alias, "", yAxis field = "Input Alias" field = "", AUXin00Alias , {(caninput_sel0a && (!enable_secondarySerial && (!enable_intcan || (enable_intcan && intcan_available == 0)))) || (caninput_sel0b && (enable_secondarySerial || (enable_intcan && intcan_available)))} @@ -3630,7 +3636,11 @@ menuDialog = main panel = caninconfig_blank1 panel = caninput_parameter_start_byte panel = caninconfig_blank1 - panel = caninput_parameter_num_byte + panel = caninput_parameter_num_byte + + dialog = AuxinCenter, "", xAxis + field = "" + panel = selectionOfEdianness. ;dialog = Canin_config2, "External Data Input" ; field = "Enable External data input", enable_intcandata_in @@ -3638,6 +3648,7 @@ menuDialog = main dialog = Canin_config, "",yAxis topicHelp = "http://speeduino.com/wiki/index.php/Secondary_Serial_IO_interface#Read_external_analog_data" panel = Auxin_north + panel = AuxinCenter panel = Canin_config1 dialog = canAuxoutput_alias, "", yAxis diff --git a/speeduino/TS_CommandButtonHandler.ino b/speeduino/TS_CommandButtonHandler.ino index 20a81693..f2537a67 100644 --- a/speeduino/TS_CommandButtonHandler.ino +++ b/speeduino/TS_CommandButtonHandler.ino @@ -292,14 +292,24 @@ bool TS_CommandButtonsHandler(uint16_t buttonCommand) //VSS Calibration routines case TS_CMD_VSS_60KMH: { - //Calibrate the actual pulses per distance - uint32_t calibrationGap = vssGetPulseGap(0); - if( calibrationGap > 0 ) + if(configPage2.vssMode == 1) { - configPage2.vssPulsesPerKm = 60000000UL / calibrationGap; + //Calculate the ratio of VSS reading from Aux input and actual VSS (assuming that actual VSS is really 60km/h). + configPage2.vssPulsesPerKm = (currentStatus.canin[configPage2.vssAuxCh] / 60); writeConfig(1); // Need to manually save the new config value as it will not trigger a burn in tunerStudio due to use of ControllerPriority BIT_SET(currentStatus.status3, BIT_STATUS3_VSS_REFRESH); //Set the flag to trigger the UI reset } + else + { + //Calibrate the actual pulses per distance + uint32_t calibrationGap = vssGetPulseGap(0); + if( calibrationGap > 0 ) + { + configPage2.vssPulsesPerKm = 60000000UL / calibrationGap; + writeConfig(1); // Need to manually save the new config value as it will not trigger a burn in tunerStudio due to use of ControllerPriority + BIT_SET(currentStatus.status3, BIT_STATUS3_VSS_REFRESH); //Set the flag to trigger the UI reset + } + } } break; diff --git a/speeduino/cancomms.h b/speeduino/cancomms.h index 7c39bdff..89e71025 100644 --- a/speeduino/cancomms.h +++ b/speeduino/cancomms.h @@ -27,5 +27,6 @@ void sendcanValues(uint16_t offset, uint16_t packetLength, byte cmd, byte portNu void can_Command(void); void sendCancommand(uint8_t cmdtype , uint16_t canadddress, uint8_t candata1, uint8_t candata2, uint16_t sourcecanAddress); void obd_response(uint8_t therequestedPID , uint8_t therequestedPIDlow, uint8_t therequestedPIDhigh); +void readAuxCanBus(); #endif // CANCOMMS_H diff --git a/speeduino/cancomms.ino b/speeduino/cancomms.ino index dc2198fd..bf89eac7 100644 --- a/speeduino/cancomms.ino +++ b/speeduino/cancomms.ino @@ -807,4 +807,35 @@ if (PIDmode == 0x01) } } } + +void readAuxCanBus() +{ + for (int i = 0; i < 16; i++) + { + if (inMsg.id == (configPage9.caninput_source_can_address[i] + 0x100)) //Filters frame ID + { + + if (!BIT_CHECK(configPage9.caninput_source_num_bytes, i)) + { + // Gets the one-byte value from the Data Field. + currentStatus.canin[i] = inMsg.buf[configPage9.caninput_source_start_byte[i]]; + } + + else + { + + if (configPage9.caninputEndianess == 1) + { + //Gets the two-byte value from the Data Field in Litlle Endian. + currentStatus.canin[i] = ((inMsg.buf[configPage9.caninput_source_start_byte[i]]) | (inMsg.buf[configPage9.caninput_source_start_byte[i] + 1] << 8)); + } + else + { + //Gets the two-byte value from the Data Field in Big Endian. + currentStatus.canin[i] = ((inMsg.buf[configPage9.caninput_source_start_byte[i]] << 8) | (inMsg.buf[configPage9.caninput_source_start_byte[i] + 1])); + } + } + } + } +} #endif diff --git a/speeduino/globals.h b/speeduino/globals.h index 4e57002d..b9c3e2db 100644 --- a/speeduino/globals.h +++ b/speeduino/globals.h @@ -905,7 +905,7 @@ struct config2 { byte canVAGCluster : 1; byte enableCluster1 : 1; byte enableCluster2 : 1; - byte unusedClusterBits : 4; + byte vssAuxCh : 4; byte decelAmount; @@ -1129,7 +1129,10 @@ struct config9 { uint16_t caninput_source_can_address[16]; //u16 [15] array holding can address of input uint8_t caninput_source_start_byte[16]; //u08 [15] array holds the start byte number(value of 0-7) uint16_t caninput_source_num_bytes; //u16 bit status of the number of bytes length 1 or 2 - byte unused10_67; + + byte caninputEndianess:1; + //byte unused:2 + //... byte unused10_68; byte enable_candata_out : 1; byte canoutput_sel[8]; diff --git a/speeduino/sensors.ino b/speeduino/sensors.ino index b77f8813..5a684552 100644 --- a/speeduino/sensors.ino +++ b/speeduino/sensors.ino @@ -627,10 +627,20 @@ uint32_t vssGetPulseGap(byte historyIndex) uint16_t getSpeed(void) { uint16_t tempSpeed = 0; - + // Get VSS from CAN, Serial or Analog by using Aux input channels. if(configPage2.vssMode == 1) { - //VSS mode 1 is (Will be) CAN + // Direct reading from Aux channel + if (configPage2.vssPulsesPerKm == 0) + { + tempSpeed = currentStatus.canin[configPage2.vssAuxCh]; + } + // Adjust the reading by dividing it by set amount. + else + { + tempSpeed = (currentStatus.canin[configPage2.vssAuxCh] / configPage2.vssPulsesPerKm); + } + tempSpeed = ADC_FILTER(tempSpeed, configPage2.vssSmoothing, currentStatus.vss); //Apply speed smoothing factor } // Interrupt driven mode else if(configPage2.vssMode > 1) diff --git a/speeduino/speeduino.ino b/speeduino/speeduino.ino index d719cbd5..09745ee9 100644 --- a/speeduino/speeduino.ino +++ b/speeduino/speeduino.ino @@ -123,12 +123,13 @@ void loop(void) #if defined (NATIVE_CAN_AVAILABLE) //currentStatus.canin[12] = configPage9.enable_intcan; if (configPage9.enable_intcan == 1) // use internal can module - { + { //check local can module // if ( BIT_CHECK(LOOP_TIMER, BIT_TIMER_15HZ) or (CANbus0.available()) while (Can0.read(inMsg) ) { can_Command(); + readAuxCanBus(); //Can0.read(inMsg); //currentStatus.canin[12] = inMsg.buf[5]; //currentStatus.canin[13] = inMsg.id;