speeduino/speeduino/decoders.h

341 lines
14 KiB
C
Raw Normal View History

2016-10-25 16:21:46 -07:00
#ifndef DECODERS_H
#define DECODERS_H
#include "globals.h"
2017-04-20 23:33:24 -07:00
#if defined(CORE_AVR)
2017-06-15 15:45:39 -07:00
#define READ_PRI_TRIGGER() ((*triggerPri_pin_port & triggerPri_pin_mask) ? true : false)
#define READ_SEC_TRIGGER() ((*triggerSec_pin_port & triggerSec_pin_mask) ? true : false)
#define READ_THIRD_TRIGGER() ((*triggerThird_pin_port & triggerThird_pin_mask) ? true : false)
2018-07-21 07:17:08 -07:00
#else
2017-04-20 23:33:24 -07:00
#define READ_PRI_TRIGGER() digitalRead(pinTrigger)
#define READ_SEC_TRIGGER() digitalRead(pinTrigger2)
#define READ_THIRD_TRIGGER() digitalRead(pinTrigger3)
2017-04-20 23:33:24 -07:00
#endif
#define DECODER_MISSING_TOOTH 0
#define DECODER_BASIC_DISTRIBUTOR 1
#define DECODER_DUAL_WHEEL 2
#define DECODER_GM7X 3
#define DECODER_4G63 4
#define DECODER_24X 5
#define DECODER_JEEP2000 6
#define DECODER_AUDI135 7
#define DECODER_HONDA_D17 8
#define DECODER_MIATA_9905 9
#define DECODER_MAZDA_AU 10
#define DECODER_NON360 11
#define DECODER_NISSAN_360 12
#define DECODER_SUBARU_67 13
#define DECODER_DAIHATSU_PLUS1 14
#define DECODER_HARLEY 15
#define DECODER_36_2_2_2 16
#define DECODER_36_2_1 17
#define DECODER_420A 18
#define DECODER_WEBER 19
#define DECODER_ST170 20
#define DECODER_DRZ400 21
#define DECODER_NGC 22
#define DECODER_VMAX 23
Renix 44 tooth decoder (includes 66 tooth code) (#1037) * Renix 44-2-2 & 66-2-2-2 initial version coded, not tested yet, saving to secure code * First working version on ardustim * updates to trigger setup * latest changes * 66 tooth working but occasional short dwell * staging before major rewrite updating the primary trigger to look for 12th system tooth to increment toothCurrentCount after this checking * updated working but with bad dwell/timing code works but the timing and dwell are not accurate once rpm goes over 400rpm * Renix code 1st release updated code to do both 44 and 66 tooth within a single set of functions * remove support for sequential for 44 tooth Sequential (via cam) was added for 44 tooth to enable future expansion. This is interfering with the normal code on the first testers car. * updated cam position * remove Dev logging * remove logging * updates to trigger decoding fixes to 66 tooth pattern and removal of secondary flag for 44 tooth decoder * fixes to decoder - rpm double * updates to support display cam tooth position added code to display which teeth the cam tooth arrives on as VVT1 & 2 and as Aux0 and Aux1. * Revert "updates to support display cam tooth position" This reverts commit d2ace89ea7495a6bf811af823d7f015189306340. * fixes from update to latest speeduino firmware * Add 4cyl semi-seq injector pairing option * Add timestamp field to SD logs * Fix soft and hard rev limiter (#813) * Increase dwell limiter in RX-8 type ignition (#820) Currently the dwell limiter calculation considers rotary ignition to have more than 1 pulse per revolution. This only holds true for FC/FD type ignition which is wasted spark correctly resulting in 2 pulses per revolution. RX-8 type ignition however is fully sequential so there is only 1 pulse per revolution. As a result the dwell limiter is being calculated too low. This change fixes the issue by correctly assuming 1 pulse per revolution in RX-8 type ignition * All tapers use byte counters (#746) Fixes Update idle.ino * Correct variable size for MAPlast * Fix issue with SD RPM threshold not correctly detecting on/off * Reorganise Engine Protection UI * Add low/high battery voltage indicator (#824) Fixes #822 * Remove tacho output flags (#814) * fix typos in code documentation (#816) * fix typos in code documentation * minor reverts * fix typos in ini Co-authored-by: Josh Stewart <josh@noisymime.org> * Added Trigger for the Yamaha Vmax motorcycle, 1990 and up. (#823) * Test 1 * Added the Vmax decoder option * Added the Yamaha Vmax decoder Co-authored-by: RempageR1 <unconfigured@null.spigotmc.org> Co-authored-by: Josh Stewart <josh@noisymime.org> * Allow for '?' command through legacy comms. Fixes #821 * Added idle advance start threshold (#747) * Added idle advance start threshold On lower temp and/or on ethanol the engine need to crank more, without this my starter get a kick and the engine backfires. This enable it only at 200 RPM below the target * Use define to idle advance RPM threshold Co-authored-by: Josh Stewart <josh@noisymime.org> * Remove previousLoopTime - never used (#706) * Simplify the corrections calculations using div100 * Fix the calculations dash figures when battery correction is applied to open time only * PWM and on/off idle fixes/cleanup (#806) * Idle fixes #1 * Idle fixes #2 Co-authored-by: Josh Stewart <josh@noisymime.org> * Remove duplicate iacClosedLoopTable. Lookup idle target RPM @ 4Hz after CLT reading * Fix validTrigger assignment in Vmax decoder * Align TPS_rateOfChange scale. Potential fix for #773 * Enable semi sequential and wasted COP on half sync (#478) * Semi/Full sequential mode Semi sequential in case of absent phase input at crank, engine will almost aways start in semi sequential mode Minimal code change at speeduino.ino Fix RPM reading when in half sync * Update with latest changes in master * Less calls to change functions See #478 chat history for details * Semi/Full sequential mode Semi sequential in case of absent phase input at crank, engine will almost aways start in semi sequential mode Minimal code change at speeduino.ino Fix RPM reading when in half sync * Update with latest changes in master * Less calls to change functions See #478 chat history for details * Add sync status to log * Updates Updated speeduino.ini Updated updates.ino * Fix error in half to full sync function Co-authored-by: Josh Stewart <josh@noisymime.org> * Fixes after merge with speeduino master * improved debug on sync loss using VVTangle * additional debug uses aux channels for debug eg currentStatus.canin[2] these need removing from the full version. Also uses VVT1 pin for debug via VVT1_PIN_OFF() and VVT1_PIN_ON() * fixes * remove secondary trigger * different logging * Final Version * added automated tests * fixed fuel pump always being on * fix build issues after merge with master * Change how 44 or 66 tooth selected Updated to work out 44 or 66 tooth decoder based on the number of cylinders, 4 cylinder = 44 tooth, 6 cylinder = 66 tooth * Fix typo in ini * Delete compile_commands.json * Remove duplicate declarations * Remove VVT code from other PR * fix speeduino.ino Remove unintended additions to speeduino.ino --------- Co-authored-by: Josh Stewart <josh@noisymime.org> Co-authored-by: Pasi Kemppainen <48950874+pazi88@users.noreply.github.com> Co-authored-by: theKraid <37898397+theKraid@users.noreply.github.com> Co-authored-by: Vitor Moreno B. Sales <vitor_boss@yahoo.com.br> Co-authored-by: Corey-Harding <91717711+Corey-Harding@users.noreply.github.com> Co-authored-by: Daniel Tobias <dantob@users.noreply.github.com> Co-authored-by: RempageR1 <103254506+RempageR1@users.noreply.github.com> Co-authored-by: RempageR1 <unconfigured@null.spigotmc.org> Co-authored-by: tx_haggis <13982343+adbancroft@users.noreply.github.com> Co-authored-by: Vitor Moreno B. Sales <vitor.m.benevides@outlook.com>
2023-04-30 01:30:34 -07:00
#define DECODER_RENIX 24
#define DECODER_ROVERMEMS 25
Suzuki K6A Decoder (#1109) * 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 * Revert "Merge remote-tracking branch 'noisymime/master'" This reverts commit 58e6e283e6c264590b475f7db466fcbfeb86894c. * initial version * added speeduino.ini so can select pattern * fixes to pattern detection and crank angle calcs * temp fix low speed cranking * comments on tooth sizes * fix filters * update - per tooth ignition doesn't work * remove debug for decoder & fix spark1 dwell * Fix merge error with decoders.h K6A definitions missed on the merge, now added back in * Change default case for decoder back to RISING/FALLING edge --------- 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>
2024-02-01 20:35:30 -08:00
#define DECODER_SUZUKI_K6A 26
#define BIT_DECODER_2ND_DERIV 0 //The use of the 2nd derivative calculation is limited to certain decoders. This is set to either true or false in each decoders setup routine
#define BIT_DECODER_IS_SEQUENTIAL 1 //Whether or not the decoder supports sequential operation
#define BIT_DECODER_UNUSED1 2
#define BIT_DECODER_HAS_SECONDARY 3 //Whether or not the decoder supports fixed cranking timing
#define BIT_DECODER_HAS_FIXED_CRANKING 4
#define BIT_DECODER_VALID_TRIGGER 5 //Is set true when the last trigger (Primary or secondary) was valid (ie passed filters)
#define BIT_DECODER_TOOTH_ANG_CORRECT 6 //Whether or not the triggerToothAngle variable is currently accurate. Some patterns have times when the triggerToothAngle variable cannot be accurately set.
//220 bytes free
extern volatile uint8_t decoderState;
/*
extern volatile bool validTrigger; //Is set true when the last trigger (Primary or secondary) was valid (ie passed filters)
extern volatile bool triggerToothAngleIsCorrect; //Whether or not the triggerToothAngle variable is currently accurate. Some patterns have times when the triggerToothAngle variable cannot be accurately set.
extern bool secondDerivEnabled; //The use of the 2nd derivative calculation is limited to certain decoders. This is set to either true or false in each decoders setup routine
extern bool decoderIsSequential; //Whether or not the decoder supports sequential operation
extern bool decoderHasSecondary; //Whether or not the pattern uses a secondary input
extern bool decoderHasFixedCrankingTiming;
*/
//This isn't to to filter out wrong pulses on triggers, but just to smooth out the cam angle reading for better closed loop VVT control.
Performance: optimize division (#1082) * Add udiv_32_16 * Apply udiv_32_16() where possible * Convert udiv_32_16 to assembler It's worth 20 loop/s * Remove unused functions * Remove degreesPeruSx2048 - unused * Remove angleToTime - replace with direct calls 1. Drop angleToTime() It's slow, only partially implemented and adds zero value (and has MISRA violations) 2. Consistent function naming 3. Doxygen * triggerPri_Nissan360 shouldn't set timePerDegree. It will be overwritten every loop by doCrankSpeedCalcs() * Use angleToTimeMicroSecPerDegree() instead of timePerDegree No loss in performance Increased injection open/close time accuracy (so unit test values must change) Can remove timePerDegree global. * Hide (encapsulate) crank math globals. * Base all angle to time conversions on decoder computed variables. This is within 2us of the revolution based method and is much faster - which is essentially zero percent change. * Performance: move calculation of degreesPeruSx32768 into decoders. Remove doCrankSpeedCalcs() - it's doing nothing at the moment. * Apply libdivide to triggerSetEndTeeth functions. Since triggerToothAngle is set once at initialization time, we can generate the libdivide struct once and reuse it many times. * Remove lastToothCalcAdvance - unused * Replace 16-bit division with shift * Replace 32-bit divison with 16-bit division * Avoid 32-bit division; use div100() * inline percentage() * Optimize div100() * MISRA fixes * Replace magic numbers with #defs * Replace libdivide structs with inline constants No perf or memory changes * Use fixed types for PWM max count variables * Accurate rounded integer division * Formalise rounding behavior (DIV_ROUND_CORRECT) * Apply DIV_ROUND_CORRECT to DIV_ROUND_CLOSEST(), UDIV_ROUND_CLOSEST(), div100(), div360(), percentage() & halfPercentage() * Add, fix & improve unit tests * Add udiv_32_16_closest() * Perf: Limit percentage calculations to 16-bits * MISRA fixes * Add compare_executiontime() to encapsulate common perf testing code * Signed to unsigned division * Convert ignitionLimits() to an inline function. Slight speed up, probably due to removing multiple evaluations of macro arguments. * Split unit tests up. * udiv_32_16 - check for valid parameters
2023-11-05 14:10:08 -08:00
#define ANGLE_FILTER(input, alpha, prior) (((long)(input) * (256 - (alpha)) + ((long)(prior) * (alpha)))) >> 8
2022-11-05 15:43:29 -07:00
void loggerPrimaryISR(void);
void loggerSecondaryISR(void);
void loggerTertiaryISR(void);
2018-08-15 00:44:30 -07:00
//All of the below are the 6 required functions for each decoder / pattern
2022-11-05 15:43:29 -07:00
void triggerSetup_missingTooth(void);
void triggerPri_missingTooth(void);
void triggerSec_missingTooth(void);
void triggerThird_missingTooth(void);
uint16_t getRPM_missingTooth(void);
int getCrankAngle_missingTooth(void);
extern void triggerSetEndTeeth_missingTooth(void);
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 58e6e283e6c264590b475f7db466fcbfeb86894c. * 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>
2023-12-10 18:30:51 -08:00
2022-11-05 15:43:29 -07:00
void triggerSetup_DualWheel(void);
void triggerPri_DualWheel(void);
void triggerSec_DualWheel(void);
uint16_t getRPM_DualWheel(void);
int getCrankAngle_DualWheel(void);
void triggerSetEndTeeth_DualWheel(void);
void triggerSetup_BasicDistributor(void);
void triggerPri_BasicDistributor(void);
void triggerSec_BasicDistributor(void);
uint16_t getRPM_BasicDistributor(void);
int getCrankAngle_BasicDistributor(void);
void triggerSetEndTeeth_BasicDistributor(void);
void triggerSetup_GM7X(void);
void triggerPri_GM7X(void);
void triggerSec_GM7X(void);
uint16_t getRPM_GM7X(void);
int getCrankAngle_GM7X(void);
void triggerSetEndTeeth_GM7X(void);
void triggerSetup_4G63(void);
void triggerPri_4G63(void);
void triggerSec_4G63(void);
uint16_t getRPM_4G63(void);
int getCrankAngle_4G63(void);
void triggerSetEndTeeth_4G63(void);
void triggerSetup_24X(void);
void triggerPri_24X(void);
void triggerSec_24X(void);
uint16_t getRPM_24X(void);
int getCrankAngle_24X(void);
void triggerSetEndTeeth_24X(void);
void triggerSetup_Jeep2000(void);
void triggerPri_Jeep2000(void);
void triggerSec_Jeep2000(void);
uint16_t getRPM_Jeep2000(void);
int getCrankAngle_Jeep2000(void);
void triggerSetEndTeeth_Jeep2000(void);
void triggerSetup_Audi135(void);
void triggerPri_Audi135(void);
void triggerSec_Audi135(void);
uint16_t getRPM_Audi135(void);
int getCrankAngle_Audi135(void);
void triggerSetEndTeeth_Audi135(void);
void triggerSetup_HondaD17(void);
void triggerPri_HondaD17(void);
void triggerSec_HondaD17(void);
uint16_t getRPM_HondaD17(void);
int getCrankAngle_HondaD17(void);
void triggerSetEndTeeth_HondaD17(void);
void triggerSetup_Miata9905(void);
void triggerPri_Miata9905(void);
void triggerSec_Miata9905(void);
uint16_t getRPM_Miata9905(void);
int getCrankAngle_Miata9905(void);
void triggerSetEndTeeth_Miata9905(void);
int getCamAngle_Miata9905(void);
void triggerSetup_MazdaAU(void);
void triggerPri_MazdaAU(void);
void triggerSec_MazdaAU(void);
uint16_t getRPM_MazdaAU(void);
int getCrankAngle_MazdaAU(void);
void triggerSetEndTeeth_MazdaAU(void);
void triggerSetup_non360(void);
void triggerPri_non360(void);
void triggerSec_non360(void);
uint16_t getRPM_non360(void);
int getCrankAngle_non360(void);
void triggerSetEndTeeth_non360(void);
void triggerSetup_Nissan360(void);
void triggerPri_Nissan360(void);
void triggerSec_Nissan360(void);
uint16_t getRPM_Nissan360(void);
int getCrankAngle_Nissan360(void);
void triggerSetEndTeeth_Nissan360(void);
void triggerSetup_Subaru67(void);
void triggerPri_Subaru67(void);
void triggerSec_Subaru67(void);
uint16_t getRPM_Subaru67(void);
int getCrankAngle_Subaru67(void);
void triggerSetEndTeeth_Subaru67(void);
void triggerSetup_Daihatsu(void);
void triggerPri_Daihatsu(void);
void triggerSec_Daihatsu(void);
uint16_t getRPM_Daihatsu(void);
int getCrankAngle_Daihatsu(void);
void triggerSetEndTeeth_Daihatsu(void);
void triggerSetup_Harley(void);
void triggerPri_Harley(void);
void triggerSec_Harley(void);
uint16_t getRPM_Harley(void);
int getCrankAngle_Harley(void);
void triggerSetEndTeeth_Harley(void);
void triggerSetup_ThirtySixMinus222(void);
void triggerPri_ThirtySixMinus222(void);
void triggerSec_ThirtySixMinus222(void);
uint16_t getRPM_ThirtySixMinus222(void);
int getCrankAngle_ThirtySixMinus222(void);
void triggerSetEndTeeth_ThirtySixMinus222(void);
void triggerSetup_ThirtySixMinus21(void);
void triggerPri_ThirtySixMinus21(void);
void triggerSec_ThirtySixMinus21(void);
uint16_t getRPM_ThirtySixMinus21(void);
int getCrankAngle_ThirtySixMinus21(void);
void triggerSetEndTeeth_ThirtySixMinus21(void);
void triggerSetup_420a(void);
void triggerPri_420a(void);
void triggerSec_420a(void);
uint16_t getRPM_420a(void);
int getCrankAngle_420a(void);
void triggerSetEndTeeth_420a(void);
void triggerPri_Webber(void);
void triggerSec_Webber(void);
void triggerSetup_FordST170(void);
void triggerSec_FordST170(void);
uint16_t getRPM_FordST170(void);
int getCrankAngle_FordST170(void);
void triggerSetEndTeeth_FordST170(void);
void triggerSetup_DRZ400(void);
void triggerSec_DRZ400(void);
void triggerSetup_NGC(void);
void triggerPri_NGC(void);
void triggerSec_NGC4(void);
void triggerSec_NGC68(void);
uint16_t getRPM_NGC(void);
void triggerSetEndTeeth_NGC(void);
void triggerSetup_Renix(void);
2023-05-16 18:36:08 -07:00
void triggerPri_Renix(void);
void triggerSetEndTeeth_Renix(void);
Renix 44 tooth decoder (includes 66 tooth code) (#1037) * Renix 44-2-2 & 66-2-2-2 initial version coded, not tested yet, saving to secure code * First working version on ardustim * updates to trigger setup * latest changes * 66 tooth working but occasional short dwell * staging before major rewrite updating the primary trigger to look for 12th system tooth to increment toothCurrentCount after this checking * updated working but with bad dwell/timing code works but the timing and dwell are not accurate once rpm goes over 400rpm * Renix code 1st release updated code to do both 44 and 66 tooth within a single set of functions * remove support for sequential for 44 tooth Sequential (via cam) was added for 44 tooth to enable future expansion. This is interfering with the normal code on the first testers car. * updated cam position * remove Dev logging * remove logging * updates to trigger decoding fixes to 66 tooth pattern and removal of secondary flag for 44 tooth decoder * fixes to decoder - rpm double * updates to support display cam tooth position added code to display which teeth the cam tooth arrives on as VVT1 & 2 and as Aux0 and Aux1. * Revert "updates to support display cam tooth position" This reverts commit d2ace89ea7495a6bf811af823d7f015189306340. * fixes from update to latest speeduino firmware * Add 4cyl semi-seq injector pairing option * Add timestamp field to SD logs * Fix soft and hard rev limiter (#813) * Increase dwell limiter in RX-8 type ignition (#820) Currently the dwell limiter calculation considers rotary ignition to have more than 1 pulse per revolution. This only holds true for FC/FD type ignition which is wasted spark correctly resulting in 2 pulses per revolution. RX-8 type ignition however is fully sequential so there is only 1 pulse per revolution. As a result the dwell limiter is being calculated too low. This change fixes the issue by correctly assuming 1 pulse per revolution in RX-8 type ignition * All tapers use byte counters (#746) Fixes Update idle.ino * Correct variable size for MAPlast * Fix issue with SD RPM threshold not correctly detecting on/off * Reorganise Engine Protection UI * Add low/high battery voltage indicator (#824) Fixes #822 * Remove tacho output flags (#814) * fix typos in code documentation (#816) * fix typos in code documentation * minor reverts * fix typos in ini Co-authored-by: Josh Stewart <josh@noisymime.org> * Added Trigger for the Yamaha Vmax motorcycle, 1990 and up. (#823) * Test 1 * Added the Vmax decoder option * Added the Yamaha Vmax decoder Co-authored-by: RempageR1 <unconfigured@null.spigotmc.org> Co-authored-by: Josh Stewart <josh@noisymime.org> * Allow for '?' command through legacy comms. Fixes #821 * Added idle advance start threshold (#747) * Added idle advance start threshold On lower temp and/or on ethanol the engine need to crank more, without this my starter get a kick and the engine backfires. This enable it only at 200 RPM below the target * Use define to idle advance RPM threshold Co-authored-by: Josh Stewart <josh@noisymime.org> * Remove previousLoopTime - never used (#706) * Simplify the corrections calculations using div100 * Fix the calculations dash figures when battery correction is applied to open time only * PWM and on/off idle fixes/cleanup (#806) * Idle fixes #1 * Idle fixes #2 Co-authored-by: Josh Stewart <josh@noisymime.org> * Remove duplicate iacClosedLoopTable. Lookup idle target RPM @ 4Hz after CLT reading * Fix validTrigger assignment in Vmax decoder * Align TPS_rateOfChange scale. Potential fix for #773 * Enable semi sequential and wasted COP on half sync (#478) * Semi/Full sequential mode Semi sequential in case of absent phase input at crank, engine will almost aways start in semi sequential mode Minimal code change at speeduino.ino Fix RPM reading when in half sync * Update with latest changes in master * Less calls to change functions See #478 chat history for details * Semi/Full sequential mode Semi sequential in case of absent phase input at crank, engine will almost aways start in semi sequential mode Minimal code change at speeduino.ino Fix RPM reading when in half sync * Update with latest changes in master * Less calls to change functions See #478 chat history for details * Add sync status to log * Updates Updated speeduino.ini Updated updates.ino * Fix error in half to full sync function Co-authored-by: Josh Stewart <josh@noisymime.org> * Fixes after merge with speeduino master * improved debug on sync loss using VVTangle * additional debug uses aux channels for debug eg currentStatus.canin[2] these need removing from the full version. Also uses VVT1 pin for debug via VVT1_PIN_OFF() and VVT1_PIN_ON() * fixes * remove secondary trigger * different logging * Final Version * added automated tests * fixed fuel pump always being on * fix build issues after merge with master * Change how 44 or 66 tooth selected Updated to work out 44 or 66 tooth decoder based on the number of cylinders, 4 cylinder = 44 tooth, 6 cylinder = 66 tooth * Fix typo in ini * Delete compile_commands.json * Remove duplicate declarations * Remove VVT code from other PR * fix speeduino.ino Remove unintended additions to speeduino.ino --------- Co-authored-by: Josh Stewart <josh@noisymime.org> Co-authored-by: Pasi Kemppainen <48950874+pazi88@users.noreply.github.com> Co-authored-by: theKraid <37898397+theKraid@users.noreply.github.com> Co-authored-by: Vitor Moreno B. Sales <vitor_boss@yahoo.com.br> Co-authored-by: Corey-Harding <91717711+Corey-Harding@users.noreply.github.com> Co-authored-by: Daniel Tobias <dantob@users.noreply.github.com> Co-authored-by: RempageR1 <103254506+RempageR1@users.noreply.github.com> Co-authored-by: RempageR1 <unconfigured@null.spigotmc.org> Co-authored-by: tx_haggis <13982343+adbancroft@users.noreply.github.com> Co-authored-by: Vitor Moreno B. Sales <vitor.m.benevides@outlook.com>
2023-04-30 01:30:34 -07:00
void triggerSetup_RoverMEMS(void);
void triggerPri_RoverMEMS(void);
void triggerSec_RoverMEMS(void);
uint16_t getRPM_RoverMEMS(void);
int getCrankAngle_RoverMEMS(void);
void triggerSetEndTeeth_RoverMEMS(void);
2023-03-29 20:29:38 -07:00
void triggerSetup_Vmax(void);
void triggerPri_Vmax(void);
void triggerSec_Vmax(void);
uint16_t getRPM_Vmax(void);
int getCrankAngle_Vmax(void);
void triggerSetEndTeeth_Vmax(void);
Suzuki K6A Decoder (#1109) * 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 * Revert "Merge remote-tracking branch 'noisymime/master'" This reverts commit 58e6e283e6c264590b475f7db466fcbfeb86894c. * initial version * added speeduino.ini so can select pattern * fixes to pattern detection and crank angle calcs * temp fix low speed cranking * comments on tooth sizes * fix filters * update - per tooth ignition doesn't work * remove debug for decoder & fix spark1 dwell * Fix merge error with decoders.h K6A definitions missed on the merge, now added back in * Change default case for decoder back to RISING/FALLING edge --------- 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>
2024-02-01 20:35:30 -08:00
void triggerSetup_SuzukiK6A(void);
void triggerPri_SuzukiK6A(void);
void triggerSec_SuzukiK6A(void);
uint16_t getRPM_SuzukiK6A(void);
int getCrankAngle_SuzukiK6A(void);
void triggerSetEndTeeth_SuzukiK6A(void);
2022-11-05 15:43:29 -07:00
extern void (*triggerHandler)(void); //Pointer for the trigger function (Gets pointed to the relevant decoder)
extern void (*triggerSecondaryHandler)(void); //Pointer for the secondary trigger function (Gets pointed to the relevant decoder)
extern void (*triggerTertiaryHandler)(void); //Pointer for the tertiary trigger function (Gets pointed to the relevant decoder)
extern uint16_t (*getRPM)(void); //Pointer to the getRPM function (Gets pointed to the relevant decoder)
extern int (*getCrankAngle)(void); //Pointer to the getCrank Angle function (Gets pointed to the relevant decoder)
extern void (*triggerSetEndTeeth)(void); //Pointer to the triggerSetEndTeeth function of each decoder
extern volatile unsigned long curTime;
extern volatile unsigned long curGap;
extern volatile unsigned long curTime2;
extern volatile unsigned long curGap2;
extern volatile unsigned long lastGap;
extern volatile unsigned long targetGap;
extern unsigned long MAX_STALL_TIME; //The maximum time (in uS) that the system will continue to function before the engine is considered stalled/stopped. This is unique to each decoder, depending on the number of teeth etc. 500000 (half a second) is used as the default value, most decoders will be much less.
extern volatile uint16_t toothCurrentCount; //The current number of teeth (Once sync has been achieved, this can never actually be 0
extern volatile byte toothSystemCount; //Used for decoders such as Audi 135 where not every tooth is used for calculating crank angle. This variable stores the actual number of teeth, not the number being used to calculate crank angle
extern volatile unsigned long toothSystemLastToothTime; //As below, but used for decoders where not every tooth count is used for calculation
extern volatile unsigned long toothLastToothTime; //The time (micros()) that the last tooth was registered
extern volatile unsigned long toothLastSecToothTime; //The time (micros()) that the last tooth was registered on the secondary input
extern volatile unsigned long toothLastThirdToothTime; //The time (micros()) that the last tooth was registered on the second cam input
extern volatile unsigned long toothLastMinusOneToothTime; //The time (micros()) that the tooth before the last tooth was registered
extern volatile unsigned long toothLastMinusOneSecToothTime; //The time (micros()) that the tooth before the last tooth was registered on secondary input
extern volatile unsigned long targetGap2;
extern volatile unsigned long toothOneTime; //The time (micros()) that tooth 1 last triggered
extern volatile unsigned long toothOneMinusOneTime; //The 2nd to last time (micros()) that tooth 1 last triggered
extern volatile bool revolutionOne; // For sequential operation, this tracks whether the current revolution is 1 or 2 (not 1)
extern volatile unsigned int secondaryToothCount; //Used for identifying the current secondary (Usually cam) tooth for patterns with multiple secondary teeth
extern volatile unsigned long secondaryLastToothTime; //The time (micros()) that the last tooth was registered (Cam input)
extern volatile unsigned long secondaryLastToothTime1; //The time (micros()) that the last tooth was registered (Cam input)
extern uint16_t triggerActualTeeth;
extern volatile unsigned long triggerFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering)
extern volatile unsigned long triggerSecFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) for the secondary input
extern unsigned int triggerSecFilterTime_duration; // The shortest valid time (in uS) pulse DURATION
extern volatile uint16_t triggerToothAngle; //The number of crank degrees that elapse per tooth
extern byte checkSyncToothCount; //How many teeth must've been seen on this revolution before we try to confirm sync (Useful for missing tooth type decoders)
extern unsigned long elapsedTime;
extern unsigned long lastCrankAngleCalc;
extern unsigned long lastVVTtime; //The time between the vvt reference pulse and the last crank pulse
Performance: optimize division (#1082) * Add udiv_32_16 * Apply udiv_32_16() where possible * Convert udiv_32_16 to assembler It's worth 20 loop/s * Remove unused functions * Remove degreesPeruSx2048 - unused * Remove angleToTime - replace with direct calls 1. Drop angleToTime() It's slow, only partially implemented and adds zero value (and has MISRA violations) 2. Consistent function naming 3. Doxygen * triggerPri_Nissan360 shouldn't set timePerDegree. It will be overwritten every loop by doCrankSpeedCalcs() * Use angleToTimeMicroSecPerDegree() instead of timePerDegree No loss in performance Increased injection open/close time accuracy (so unit test values must change) Can remove timePerDegree global. * Hide (encapsulate) crank math globals. * Base all angle to time conversions on decoder computed variables. This is within 2us of the revolution based method and is much faster - which is essentially zero percent change. * Performance: move calculation of degreesPeruSx32768 into decoders. Remove doCrankSpeedCalcs() - it's doing nothing at the moment. * Apply libdivide to triggerSetEndTeeth functions. Since triggerToothAngle is set once at initialization time, we can generate the libdivide struct once and reuse it many times. * Remove lastToothCalcAdvance - unused * Replace 16-bit division with shift * Replace 32-bit divison with 16-bit division * Avoid 32-bit division; use div100() * inline percentage() * Optimize div100() * MISRA fixes * Replace magic numbers with #defs * Replace libdivide structs with inline constants No perf or memory changes * Use fixed types for PWM max count variables * Accurate rounded integer division * Formalise rounding behavior (DIV_ROUND_CORRECT) * Apply DIV_ROUND_CORRECT to DIV_ROUND_CLOSEST(), UDIV_ROUND_CLOSEST(), div100(), div360(), percentage() & halfPercentage() * Add, fix & improve unit tests * Add udiv_32_16_closest() * Perf: Limit percentage calculations to 16-bits * MISRA fixes * Add compare_executiontime() to encapsulate common perf testing code * Signed to unsigned division * Convert ignitionLimits() to an inline function. Slight speed up, probably due to removing multiple evaluations of macro arguments. * Split unit tests up. * udiv_32_16 - check for valid parameters
2023-11-05 14:10:08 -08:00
typedef uint32_t UQ24X8_t;
constexpr uint8_t UQ24X8_Shift = 8U;
/** @brief uS per degree at current RPM in UQ24.8 fixed point */
extern UQ24X8_t microsPerDegree;
constexpr uint8_t microsPerDegree_Shift = UQ24X8_Shift;
typedef uint16_t UQ1X15_t;
constexpr uint8_t UQ1X15_Shift = 15U;
/** @brief Degrees per uS in UQ1.15 fixed point.
*
* Ranges from 8 (0.000246) at MIN_RPM to 3542 (0.108) at MAX_RPM
*/
extern UQ1X15_t degreesPerMicro;
constexpr uint8_t degreesPerMicro_Shift = UQ1X15_Shift;
2020-02-27 16:20:13 -08:00
extern uint16_t ignition1EndTooth;
extern uint16_t ignition2EndTooth;
extern uint16_t ignition3EndTooth;
extern uint16_t ignition4EndTooth;
extern uint16_t ignition5EndTooth;
extern uint16_t ignition6EndTooth;
extern uint16_t ignition7EndTooth;
extern uint16_t ignition8EndTooth;
extern int16_t toothAngles[24]; //An array for storing fixed tooth angles. Currently sized at 24 for the GM 24X decoder, but may grow later if there are other decoders that use this style
2015-07-12 21:22:05 -07:00
Performance: optimize division (#1082) * Add udiv_32_16 * Apply udiv_32_16() where possible * Convert udiv_32_16 to assembler It's worth 20 loop/s * Remove unused functions * Remove degreesPeruSx2048 - unused * Remove angleToTime - replace with direct calls 1. Drop angleToTime() It's slow, only partially implemented and adds zero value (and has MISRA violations) 2. Consistent function naming 3. Doxygen * triggerPri_Nissan360 shouldn't set timePerDegree. It will be overwritten every loop by doCrankSpeedCalcs() * Use angleToTimeMicroSecPerDegree() instead of timePerDegree No loss in performance Increased injection open/close time accuracy (so unit test values must change) Can remove timePerDegree global. * Hide (encapsulate) crank math globals. * Base all angle to time conversions on decoder computed variables. This is within 2us of the revolution based method and is much faster - which is essentially zero percent change. * Performance: move calculation of degreesPeruSx32768 into decoders. Remove doCrankSpeedCalcs() - it's doing nothing at the moment. * Apply libdivide to triggerSetEndTeeth functions. Since triggerToothAngle is set once at initialization time, we can generate the libdivide struct once and reuse it many times. * Remove lastToothCalcAdvance - unused * Replace 16-bit division with shift * Replace 32-bit divison with 16-bit division * Avoid 32-bit division; use div100() * inline percentage() * Optimize div100() * MISRA fixes * Replace magic numbers with #defs * Replace libdivide structs with inline constants No perf or memory changes * Use fixed types for PWM max count variables * Accurate rounded integer division * Formalise rounding behavior (DIV_ROUND_CORRECT) * Apply DIV_ROUND_CORRECT to DIV_ROUND_CLOSEST(), UDIV_ROUND_CLOSEST(), div100(), div360(), percentage() & halfPercentage() * Add, fix & improve unit tests * Add udiv_32_16_closest() * Perf: Limit percentage calculations to 16-bits * MISRA fixes * Add compare_executiontime() to encapsulate common perf testing code * Signed to unsigned division * Convert ignitionLimits() to an inline function. Slight speed up, probably due to removing multiple evaluations of macro arguments. * Split unit tests up. * udiv_32_16 - check for valid parameters
2023-11-05 14:10:08 -08:00
#define CRANK_SPEED 0U
#define CAM_SPEED 1U
2018-06-25 19:17:43 -07:00
2018-09-30 21:21:13 -07:00
#define TOOTH_CRANK 0
#define TOOTH_CAM_SECONDARY 1
#define TOOTH_CAM_TERTIARY 2
2018-09-30 21:21:13 -07:00
// used by the ROVER MEMS pattern
#define ID_TOOTH_PATTERN 0 // have we identified teeth to skip for calculating RPM?
#define SKIP_TOOTH1 1
#define SKIP_TOOTH2 2
#define SKIP_TOOTH3 3
#define SKIP_TOOTH4 4
2016-10-25 16:21:46 -07:00
#endif