Adds support for toyota 3 tooth secondary and 2 tooth tertiary input (#1040)

* Disable SD on T4.1 temporarily to prevent lockups. See #847

* Fix unit test value

* Improve closedloop boost control (#736)

* First try on updating closedloop boost control

* added eeprom updates for backward comp[atibility

* fix merge conflict

* Change updates to next release EEPROM version.

* Fix some issues after merging master

* some cleanup to minimize changes and speedup review

* cleanup updates

* chances on updates to alaign with new table format

* move LUT to new config page in eeprom

* little cleanup

* Update storage.h comments

* fix some ini warnings

Co-authored-by: Tjeerd <tjeerdie@users.noreply.github.com>

* Minor cleanup of boost dialog from previous PR

* Add dynamic EEPROM block write limit based on RPM. Should fix #859

* Only set the idle up pin state on init if it's enabled

* AFR protection function (#861)

* Implementing AFR protection

* Update globals.h

* Bug fixes and code refactoring

* Moved variables to prevent ODR

* Dialog for AFR protection

* Data size and math corrections

* Possibility to use either AFR or lambda

* Updated default AFR protection values

* No need to do multiplications due to existing RPMdiv100 variable

* The X100 multiplier was wrongfully removed

* Add defaults in updates.ino, minor formatting cleanups

Co-authored-by: Josh Stewart <josh@noisymime.org>

* Prevent cranking and ASE corrections running at once. Alternative fix to #868

* Corrected RPM to TPS (#878). Fixes #874

* Fixed value mode for AFR protection (#877)

* bug fix. A workaround for failing emulated on internal flash writes + a root cause fix (#876)

* workaround for failing flash writes

* Root cause fix for EEPROM emulation on STM32

* Oops, remove some debugging functions.

Co-authored-by: Tjeerd <tjeerdie@users.noreply.github.com>

* Correct typos found by codespell (#880)

* Fix broken build on Teensy from #880

* Narrow scope of EEPROM_MAX_WRITE_BLOCK to writeConfig (#881)

* EEPROM_MAX_WRITE_BLOCK can be local to writeConfig()
This saves a byte of memory ;-)

* Fix MISRA/lint warnings
Correctly cast address parameter of eeprom_read_block
Statically access table 3d type_key member

* Remove force burn code - unused

* Replace eepromWritesPending with bit set/check

* Refactor: chain write_location instances.
Clearer code.

* Fix hanging on boot (#858)

* Further fixes to the ASE correction

* Enable use of disabled functions pins (#549)

* Enable use pins of disabled functions or unused ign channels

* Added new pins and functions to check

* Fix for semi-seq inj after #478 (#883)

* Don't try to run inappropriate CI on forked repositories (#871)

* Remove old unused corrections code

* Remove controller priority on trigger edge. Fixes #860

This was added for a specific FW update in 2018 and no longer needed.

* Add engine protection flags to datalog

* Add option for SD logging with external switch

* TS option to display pressure in bar #842 (#864)

Adds options in TunerStudio project settings to have default units
for fuel and oil pressure in bar. Adds gauge in kPa. This only
adds convertion from psi to bar, not affecting firmware.

Co-authored-by: Min <min@infcof.com>

* Fix typo from last commit

* Missing commas in ini

* bug fix EGO PID controller + some improvements.  (#879)

* Fix for EGO pid

* Further improvements on ego PID

* Stop EGO controllers from calculating while DFCO is active. To prevent integrator windup.

* Fix bug in DFCO enable/disable of the controller

Co-authored-by: Tjeerd <tjeerdie@users.noreply.github.com>

* Add necessary pin translations (#887). Fixes #867

* Signatures for 202207

* Update README.md

* Update signatures for 202207 in legacy comms

* Dev signatures for 202210-dev

* Volatile decoder variables (#902)

* triggerToothAngle is modified by interrupts

* triggerActualTeeth is never modified in interrupts

* fix check for DFCO off in correctionAFRclosedLoop() (#899)

line 608 has bit-and of configpage6.egotype > 0  & DFCO off.
it should be logical and &&

* cl boost control above baro should use logical and/or (#901)

* libdivide structs can be const - saves a few bytes (#886)

* Add OLCL mode to initBoard() for teensy (#903)

Co-authored-by: csmergs <christopher@smeraglinolo.com>

* Fix for idle PWM on STM32. Enable idle timer when idle pwm is enabled. Fixes #907 

Co-authored-by: Tjeerd <tjeerdie@users.noreply.github.com>

* Disable automatic retransmission (#910)

* Allow for float values in SD log where supported with FPU

* Increase most F temp field max values to 419F

* Revert "Merge branch 'master' into DoubleMissing"

This reverts commit bda3d89bf553df40951167870c826792ba92a715.

* recover missing files

* add vvt

* missing files

* fix stall time from debug version

* Add 3 tooth cam support

* added vvt2 and potential I4 cam

* fix

* fixes to VVT1 to always trigger on rotation 1

* fix attempt to vtt1 trigger

* fixed VVT trigger

* updated how vvt2 is calculated

* made code more readable and portable

instead of trying to set an unsigned int to its max value and handling different sized unsigned ints across different processes, using -1 and adding a comment to explain why. This will then work across all processors

* Allow updating of trigger edge for third cam

* Add logging to second cam & filtering

* include high speed logger in legacy comms

* adding VVT logging and trigger edge editing


fix missing define (temp fix?)


Revert "fix missing define (temp fix?)"

This reverts commit c6280f38ff69cc41278148a79c888736a71754b1.

fixes

* Create an additional logger screen in tunerstudio

Changes to create a third high speed logger window in tuner studio.

* missed save

* Change variable name 

Discord discussion requested compositeLogEnabled didn't do a test for false as the type is now a byte. Variable renamed to be compositeTriggerUsed and false replaced with 0. Variable name and values used should now make more logical sense.

* fix tertiary cam trigger

tertiary cam trigger is supposed to trigger on 2nd tooth, code had bug meaning it would never trigger.

* change how tertiary cam reset

(needs testing)

* added 4th composite logger for both cams

allows you to log both cams together and see the relationship between them.

* added more logging

Log the primary, secondary and third inputs as well as engine cycle on all composite logs. Still have 3 different logs to allow you to visualise which is the best way to present the information.

* Improve VVT1 detection

* fixes to merge

* update VVT2 trigger detection and reduce filtering

* Revert "Merge remote-tracking branch 'noisymime/master'"

This reverts commit 58e6e283e6.

* Correct merge error with master

missed decoders.h merge missing a reference to recordVVT1Angle which has been renamed to fit better into the naming convention within this file to triggerRecordVVT1Angle

* Removed tertiary decoder

Tertiary decoder hasn't completed testing & is specifically for certain v8 engines, removing so this can be submitted and built into the next release covering other Toyota engines (eg those used in Lexius inline 6)

* Make triggerRecordVVT1Angle static

---------

Co-authored-by: Josh Stewart <josh@noisymime.org>
Co-authored-by: Tjeerd <33102280+Tjeerdie@users.noreply.github.com>
Co-authored-by: Tjeerd <tjeerdie@users.noreply.github.com>
Co-authored-by: larmicfre <49905831+larmicfre@users.noreply.github.com>
Co-authored-by: Daniel Tobias <dantob@users.noreply.github.com>
Co-authored-by: tx_haggis <13982343+adbancroft@users.noreply.github.com>
Co-authored-by: Pasi Kemppainen <48950874+pazi88@users.noreply.github.com>
Co-authored-by: Vitor Moreno B. Sales <vitor.m.benevides@outlook.com>
Co-authored-by: Min <72794870+zceemja@users.noreply.github.com>
Co-authored-by: Min <min@infcof.com>
Co-authored-by: Afroboltski <70011435+Afroboltski@users.noreply.github.com>
Co-authored-by: DeionSi <DeionSi@users.noreply.github.com>
Co-authored-by: Jon Billings <jon.billings@bbc.co.uk>
Co-authored-by: a32guy <turboe30@gmail.com>
Co-authored-by: csmergs <christopher@smeraglinolo.com>
This commit is contained in:
mike501 2023-12-11 02:30:51 +00:00 committed by GitHub
parent f7ee4c6415
commit ef39476f8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 30 deletions

View File

@ -517,7 +517,7 @@ page = 4
fuelPumpPin= bits , U08, 6,[1:6], "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"
useResync = bits, U08, 6,[7:7], "No", "Yes"
sparkDur = scalar, U08, 7, "ms", 0.1, 0, 0, 25.5, 1 ; Spark duration
trigPatternSec = bits,U08, 8,[0:6], "Single tooth cam", "4-1 cam", "Poll level", "Rover 5-3-2 cam", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID"
trigPatternSec = bits,U08, 8,[0:6], "Single tooth cam", "4-1 cam", "Poll level", "Rover 5-3-2 cam", "Toyota 3 Tooth", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID"
PollLevelPol = bits, U08, 8,[7:7], "Low", "High",
;Reset Control

View File

@ -1,3 +1,5 @@
#define MJR 1
/*
Speeduino - Simple engine management for the Arduino Mega 2560 platform
Copyright (C) Josh Stewart
@ -53,6 +55,7 @@ int (*getCrankAngle)(void) = nullGetCrankAngle; ///Pointer to the getCrank Angle
void (*triggerSetEndTeeth)(void) = triggerSetEndTeeth_missingTooth; ///Pointer to the triggerSetEndTeeth function of each decoder
static void triggerRoverMEMSCommon(void);
static inline void triggerRecordVVT1Angle (void);
volatile unsigned long curTime;
volatile unsigned long curGap;
@ -552,12 +555,15 @@ void triggerPri_missingTooth(void)
if( (secondaryToothCount > 0) || (configPage4.TrigSpeed == CAM_SPEED) || (configPage4.trigPatternSec == SEC_TRIGGER_POLL) || (configPage2.strokes == TWO_STROKE) )
{
currentStatus.hasSync = true;
BIT_CLEAR(currentStatus.status3, BIT_STATUS3_HALFSYNC); //the engine is fully synced so clear the Half Sync bit
if(configPage4.trigPatternSec == SEC_TRIGGER_SINGLE) { secondaryToothCount = 0; } //Reset the secondary tooth counter to prevent it overflowing
BIT_CLEAR(currentStatus.status3, BIT_STATUS3_HALFSYNC); //the engine is fully synced so clear the Half Sync bit
}
else if(currentStatus.hasSync != true) { BIT_SET(currentStatus.status3, BIT_STATUS3_HALFSYNC); } //If there is primary trigger but no secondary we only have half sync.
}
else { currentStatus.hasSync = true; BIT_CLEAR(currentStatus.status3, BIT_STATUS3_HALFSYNC); } //If nothing is using sequential, we have sync and also clear half sync bit
if(configPage4.trigPatternSec == SEC_TRIGGER_SINGLE || configPage4.trigPatternSec == SEC_TRIGGER_TOYOTA_3) //Reset the secondary tooth counter to prevent it overflowing, done outside of sequental as v6 & v8 engines could be batch firing with VVT that needs the cam resetting
{
secondaryToothCount = 0;
}
triggerFilterTime = 0; //This is used to prevent a condition where serious intermittent signals (Eg someone furiously plugging the sensor wire in and out) can leave the filter in an unrecoverable state
toothLastMinusOneToothTime = toothLastToothTime;
@ -613,32 +619,52 @@ void triggerSec_missingTooth(void)
if ( curGap2 >= triggerSecFilterTime )
{
if ( configPage4.trigPatternSec == SEC_TRIGGER_4_1 )
switch (configPage4.trigPatternSec)
{
targetGap2 = (3 * (toothLastSecToothTime - toothLastMinusOneSecToothTime)) >> 1; //If the time between the current tooth and the last is greater than 1.5x the time between the last tooth and the tooth before that, we make the assertion that we must be at the first tooth after the gap
toothLastMinusOneSecToothTime = toothLastSecToothTime;
if ( (curGap2 >= targetGap2) || (secondaryToothCount > 3) )
{
secondaryToothCount = 1;
case SEC_TRIGGER_4_1:
targetGap2 = (3 * (toothLastSecToothTime - toothLastMinusOneSecToothTime)) >> 1; //If the time between the current tooth and the last is greater than 1.5x the time between the last tooth and the tooth before that, we make the assertion that we must be at the first tooth after the gap
toothLastMinusOneSecToothTime = toothLastSecToothTime;
if ( (curGap2 >= targetGap2) || (secondaryToothCount > 3) )
{
secondaryToothCount = 1;
revolutionOne = 1; //Sequential revolution reset
triggerSecFilterTime = 0; //This is used to prevent a condition where serious intermitent signals (Eg someone furiously plugging the sensor wire in and out) can leave the filter in an unrecoverable state
triggerRecordVVT1Angle ();
}
else
{
triggerSecFilterTime = curGap2 >> 2; //Set filter at 25% of the current speed. Filter can only be recalc'd for the regular teeth, not the missing one.
secondaryToothCount++;
}
break;
case SEC_TRIGGER_SINGLE:
//Standard single tooth cam trigger
revolutionOne = 1; //Sequential revolution reset
triggerSecFilterTime = 0; //This is used to prevent a condition where serious intermittent signals (Eg someone furiously plugging the sensor wire in and out) can leave the filter in an unrecoverable state
}
else
{
triggerSecFilterTime = curGap2 >> 2; //Set filter at 25% of the current speed. Filter can only be recalculated for the regular teeth, not the missing one.
triggerSecFilterTime = curGap2 >> 1; //Next secondary filter is half the current gap
secondaryToothCount++;
}
}
else if ( configPage4.trigPatternSec == SEC_TRIGGER_SINGLE )
{
//Standard single tooth cam trigger
revolutionOne = 1; //Sequential revolution reset
triggerSecFilterTime = curGap2 >> 1; //Next secondary filter is half the current gap
secondaryToothCount++;
triggerRecordVVT1Angle ();
break;
case SEC_TRIGGER_TOYOTA_3:
// designed for Toyota VVTI (2JZ) engine - 3 triggers on the cam.
// the 2 teeth for this are within 1 rotation (1 tooth first 360, 2 teeth second 360)
secondaryToothCount++;
if(secondaryToothCount == 2)
{
revolutionOne = 1; // sequential revolution reset
triggerRecordVVT1Angle ();
}
//Next secondary filter is 25% the current gap, done here so we don't get a great big gap for the 1st tooth
triggerSecFilterTime = curGap2 >> 2;
break;
}
toothLastSecToothTime = curTime2;
} //Trigger filter
}
static inline void triggerRecordVVT1Angle (void)
{
//Record the VVT Angle
if( (configPage6.vvtEnabled > 0) && (revolutionOne == 1) )
{
@ -650,13 +676,14 @@ void triggerSec_missingTooth(void)
currentStatus.vvt1Angle = ANGLE_FILTER( (curAngle << 1), configPage4.ANGLEFILTER_VVT, currentStatus.vvt1Angle);
}
}
void triggerThird_missingTooth(void)
{
//Record the VVT2 Angle (the only purpose of the third trigger)
//Record the VVT2 Angle (the only purpose of the third trigger)
//NB no filtering of this signal with current implementation unlike Cam (VVT1)
int16_t curAngle;
curTime3 = micros();
curGap3 = curTime3 - toothLastThirdToothTime;
@ -671,16 +698,17 @@ void triggerThird_missingTooth(void)
if ( curGap3 >= triggerThirdFilterTime )
{
thirdToothCount++;
triggerThirdFilterTime = curGap3 >> 1; //Next third filter is 50% the current gap
triggerThirdFilterTime = curGap3 >> 2; //Next third filter is 25% the current gap
curAngle = getCrankAngle();
while(curAngle > 360) { curAngle -= 360; }
curAngle -= configPage4.triggerAngle; //Value at TDC
if( configPage6.vvtMode == VVT_MODE_CLOSED_LOOP ) { curAngle -= configPage4.vvt2CL0DutyAng; }
//currentStatus.vvt2Angle = int8_t (curAngle); //vvt1Angle is only int8, but +/-127 degrees is enough for VVT control
currentStatus.vvt2Angle = ANGLE_FILTER( (curAngle << 1), configPage4.ANGLEFILTER_VVT, currentStatus.vvt2Angle);
currentStatus.vvt2Angle = ANGLE_FILTER( (curAngle << 1), configPage4.ANGLEFILTER_VVT, currentStatus.vvt2Angle);
toothLastThirdToothTime = curTime3;
} // Trigger filter
} //Trigger filter
}
uint16_t getRPM_missingTooth(void)

View File

@ -76,6 +76,7 @@ uint16_t getRPM_missingTooth(void);
int getCrankAngle_missingTooth(void);
extern void triggerSetEndTeeth_missingTooth(void);
void triggerSetup_DualWheel(void);
void triggerPri_DualWheel(void);
void triggerSec_DualWheel(void);

View File

@ -255,6 +255,7 @@
#define SEC_TRIGGER_4_1 1
#define SEC_TRIGGER_POLL 2
#define SEC_TRIGGER_5_3_2 3
#define SEC_TRIGGER_TOYOTA_3 4
#define ROTARY_IGN_FC 0
#define ROTARY_IGN_FD 1
@ -1469,8 +1470,8 @@ extern byte pinCoil7; //Pin for coil 7
extern byte pinCoil8; //Pin for coil 8
extern byte ignitionOutputControl; //Specifies whether the coils are controlled directly (Via an IO pin) or using something like the MC33810
extern byte pinTrigger; //The CAS pin
extern byte pinTrigger2; //The Cam Sensor pin
extern byte pinTrigger3; //the 2nd cam sensor pin
extern byte pinTrigger2; //The Cam Sensor pin known as secondary input
extern byte pinTrigger3; //the 2nd cam sensor pin known as tertiary input
extern byte pinTPS;//TPS input pin
extern byte pinMAP; //MAP sensor pin
extern byte pinEMAP; //EMAP sensor pin