Commit Graph

376 Commits

Author SHA1 Message Date
tx_haggis 0f13753ed3
Performance: optimized 32-bit shifts (#1187)
* Add optimized 32-bit shifting

* Tooth based time to angle coversion is only used by a few decoders.
So move the functions into decoders.cpp

* Better separation of deocders and crank maths.

* Apply optimised shifts

* Doxygen
2024-05-30 14:12:14 +10:00
Josh Stewart 378200c2a7 Prevent potential fuel pump oscillation during tooth timeout period 2024-04-01 16:09:41 +11:00
tx_haggis e08d5dab25
test_math: make unit tests pass on Teensy (#1137)
Required converting dwell, actualDwell, dwellCrank & dwellRun to unsigned.
2024-03-21 11:45:10 +11:00
Daniel Tobias 3a712baf23
Comment typos correction (#1189)
* basic spelling fixes

* basic spelling fixes, external libs
2024-03-21 11:37:45 +11:00
Josh Stewart be3c49b0be Add injector open time back into total PW when auto staging is used.
Fixes #1172
2024-02-20 15:36:45 +11:00
dynfer 3f75f55bdd
Add support for RusEFI CAN Wideband based on STM32F042 (#1146)
* CAN WBO Support

* fix typo

* Change data handling

* add source repo information

* Added heater functionality and fixed value handling

* Missed 0

* Better condition handling and minor fixes to multiplication

* Remove code duplication

* fix

* Error fixing and correct address of controller for outgoing frames

* Page layout adjustment

* fix

* Second WBO added to be used in TS / MLV

* Add extended flag to out frame

* Functional test and fixes

* typo

* CAN WBO Support

fix typo

Change data handling

add source repo information

Added heater functionality and fixed value handling

Missed 0

Better condition handling and minor fixes to multiplication

Remove code duplication

fix

Error fixing and correct address of controller for outgoing frames

Page layout adjustment

fix

Second WBO added to be used in TS / MLV

Add extended flag to out frame

Add support for BlitzBox hardware in speeduino firmware (#1148)

* Add support for BlitzBox in init.cpp

added case 42 for BlitzBox support

* Added support for Blitzbox to speeduino.ini

Added support for Blitzbox to speeduino.ini to get an ECU entry in Tunerstudio

* Enabled spare pins in pin layout

Functional test and fixes

typo

Fix issue with LED indicator not working when MC33810 was in use

Resolve issue with Teensy not sending CAN msgs

Fix regression on MC33810 units from af2815d818

Added check for AFR greater than 25.5

Added overflow check of O2 value

Code clean up

Bump actions/upload-artifact from 3 to 4 (#1149)

Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Spelling and typo correction

missing space

* Fix possible overflow

* Allow for future CAN based WBO modules to be added

* rusEFI case as requested.

* fix

* CAN WBO Support

* fix typo

* Change data handling

* add source repo information

* Added heater functionality and fixed value handling

* Missed 0

* Better condition handling and minor fixes to multiplication

* Remove code duplication

* fix

* Error fixing and correct address of controller for outgoing frames

* Page layout adjustment

* fix

* Second WBO added to be used in TS / MLV

* Add extended flag to out frame

* Functional test and fixes

* typo

* Allow for future CAN based WBO modules to be added

* CAN WBO Support

fix typo

Change data handling

add source repo information

Added heater functionality and fixed value handling

Missed 0

Better condition handling and minor fixes to multiplication

Remove code duplication

fix

Error fixing and correct address of controller for outgoing frames

Page layout adjustment

fix

Second WBO added to be used in TS / MLV

Add extended flag to out frame

Add support for BlitzBox hardware in speeduino firmware (#1148)

* Add support for BlitzBox in init.cpp

added case 42 for BlitzBox support

* Added support for Blitzbox to speeduino.ini

Added support for Blitzbox to speeduino.ini to get an ECU entry in Tunerstudio

* Enabled spare pins in pin layout

Functional test and fixes

typo

Fix issue with LED indicator not working when MC33810 was in use

Resolve issue with Teensy not sending CAN msgs

Fix regression on MC33810 units from af2815d818

Added check for AFR greater than 25.5

Added overflow check of O2 value

Code clean up

Bump actions/upload-artifact from 3 to 4 (#1149)

Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Spelling and typo correction

missing space

* rusEFI case as requested.

* Revert "Merge branch 'master' of https://github.com/dynfer/speeduino"

This reverts commit 49dc0eab08, reversing
changes made to 56abc79008.

* fix merge

* fixes

* Added overflow prevention

* Final

---------

Co-authored-by: Josh Stewart <josh@noisymime.org>
2024-02-04 21:34:29 +11:00
Josh Stewart f49d6ca5d8 Fix erratic pulse issue with 3 and 5 squirt configurations 2024-01-22 17:20:06 +11:00
Josh Stewart 2e23675166 Fix for Teensy build 2024-01-18 18:20:57 +11:00
Josh Stewart edd3231102 Use the faster div100 function in PW() 2024-01-18 18:03:46 +11:00
Josh Stewart 1439750731 Separate PW Limit calculation into own function and optimise. Add unit tests for this 2024-01-16 22:25:15 +11:00
Josh Stewart 0a5182f353 Fix logic from bd25dee 2024-01-16 16:21:18 +11:00
Josh Stewart f14edc6d6c Fix warning/error with use of max() and signed variable 2024-01-13 12:20:04 +11:00
Josh Stewart bd25deec40 Ensure injector end angle is not greater than the maximum inj angle 2024-01-05 14:52:35 +09:00
Josh Stewart 7d817e3cde Resolve issue with Teensy not sending CAN msgs 2023-12-21 13:40:36 +11:00
Josh Stewart 4d4486df4f Minor memory optimisation 2023-12-06 14:47:13 +11:00
Josh Stewart 4d4b2a87f7 Disable ADC ISR after each full cycle and re-enable every 5ms (200Hz) 2023-12-06 13:39:32 +11:00
tx_haggis 963f6317ba
Save 600+ bytes RAM (step 5 of 9) - De-duplicate setSchedule functions (#1111)
* initialiseSchedulers: factor out shared code.

* Proxy setFuelSchedule\d through generic
setFuelSchedule() function

* Directly call setFuelSchedule

* Simplify unit tests

* Proxy setIgnitionSchedule\d through generic
setIgnitionSchedule() function

* Directly call setIgnitionSchedule

* Simplify unit tests

* Optimize by partially inlining
the set[Fuel|Ignition]Schedule funcs

* Use the embedded schedule compare
& counter members instead of using
hardcoded individual channel macros.

* Unit test adjustCrankAngle
2023-11-24 09:35:43 +11:00
Josh Stewart 36d22b4832 Allow secondary serial interface to be set on a per board basis rather than MCU only
Fixes #1135
2023-11-21 16:47:24 +11:00
tx_haggis 9bbd16c81b
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-06 09:10:08 +11:00
Josh Stewart 329a5278a7 Move CAN buffers into the relevant comms files rather than boards
This should resolve #1116
2023-11-03 15:22:11 +11:00
Josh Stewart 059f4b3adf Restructure CAN code into comms_CAN 2023-10-13 12:25:05 +11:00
tx_haggis b03db96ad7
Save 600+ bytes RAM (step 4 of 9) - deduplicate scheduler ISR functions (#1063) 2023-10-07 08:25:26 +11:00
Josh Stewart 55c98cab22 Allow mega2560 builds with non-standard _CHANNELS values 2023-10-06 20:43:15 +11:00
Josh Stewart 484e3916e3 Further cleanup work on secondary comms. Slight RAM free up. 2023-10-06 11:48:05 +11:00
Josh Stewart a6201f3b72 Prevent low probability race condition when disabling pending schedules 2023-08-28 11:21:55 +10:00
Josh Stewart 3d33a2cbf5 Delay spark re-engagement by 1 revolution when using Fuel+Spark cut on a 4 stroke engine 2023-08-22 18:20:36 +10:00
Josh Stewart d13c7d0ab5 Ensure already scheduled events are stopped when rolling cut goes active 2023-08-22 14:38:17 +10:00
Josh Stewart ee807bb243 Rolling limiter fixes for launch and flat shift 2023-07-31 13:39:27 +10:00
Josh Stewart 856bcfb242 Fix rolling limiter not working with coolant based RPM limit 2023-07-04 15:26:56 +10:00
Josh Stewart a1ae3db072 Fix for incorrect bracket in last commit 2023-06-26 16:17:59 +10:00
Josh Stewart 624d255123 Standardise all the fuel schedule setting channel calls 2023-06-26 15:52:02 +10:00
tx_haggis d9b5554a8c
Save 600+ bytes RAM (step 3 of 9) - remove per-channel schedule calculation functions, use generic equivalents instead (#1018)
* calculateInjector1Timeout proxies calculateInjectorNTimeout
Unit test still pass.

* Remove calculateInjector1Timeout,
Replace with call to calculateInjectorTimeout
All unit tests still pass.

* Remove unecassary unit test

* calculateIgnition1Timeout proxies calculateIgnitionNTimeout
Unit test all pass

* Remove calculateIgnition1Timeout,
Replace with call to calculateIgnitionTimeout
All unit tests still pass.

* Remove unecassary unit test

* calculateIgnitionAngle\d proxies
calculateIgnitionAngle
Unit tests all pass

* Remove calculateIgnitionAngle\d
Just call calculateIgnitionAngle() directly

* Route rotary ignition angle calcs
through generic calculateIgnitionTrailingRotary
function.

* Remove calculateIgnitionAngle\d
Just call calculateIgnitionTrailingRotary() directly

* calculateInjectorStartAngle: inject all parameters
Do not rely on global state
Easier unit testing.

* calculateIgnitionAngle: inject all parameters
Do not rely on global state
Easier unit testing.

* Pull all ignition global vars into schedule_calcs

* Conditional compile for schedule calc vars
Saves memory

* Optimize: break out angleToTimeIntervalRev
from angleToTime. The new function will
always be inlined.

* Optimize - simpler code path
when no channel offset (zero)

Some optimization of arithmetic operations.

* Fix unit tests

* Fix bug on injector angle calculations
Need while loops to correctly bring intermediate
values into range

---------

Co-authored-by: Josh Stewart <josh@noisymime.org>
2023-06-26 12:13:53 +10:00
Josh Stewart e44f4c7b54 Fix issue where staging fuel channels would be active even when not required 2023-06-26 10:46:11 +10:00
Josh Stewart 9c3e993b53 Initial commit of new rolling rev limiter 2023-06-09 16:10:43 +10:00
Vitor Moreno B. Sales 72dd807fb3
Consistent MAP readings for all platforms (#619)
* Added a 1000Hz call for MAP reading on ARM cores

* Use 1kHz section for map reads on all MCUs

---------

Co-authored-by: Josh Stewart <josh@noisymime.org>
2023-05-19 10:24:56 +10:00
Josh Stewart 6932101254 Add a cranking to running RPM hysteresis (15 rpm) 2023-05-18 15:21:30 +10:00
Josh Stewart 9bc49d9aa2 Warnings cleanup 2023-05-17 11:36:08 +10:00
mike501 805a535238
VVT2 improved logging & setup (#1036)
* 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.

* 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.

* 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.
2023-05-15 14:15:46 +10:00
Josh Stewart 78bed477f5 Merge branch 'master' of https://github.com/noisymime/speeduino 2023-05-03 15:41:38 +10:00
celso acyr da57378684
Read analog values via CAN BUS (#635)
* Read analog values via CAN BUS

Allows reading of 16 analog signals via CAN-BUS. with selection of Edianness.

* Moved function

Function moved to improve data readability.

---------

Co-authored-by: Josh Stewart <josh@noisymime.org>
2023-05-03 15:12:29 +10:00
Josh Stewart 65005c0019 Sync SD log with card at 4Hz interval 2023-05-02 13:13:19 +10:00
Josh Stewart d0286fe02d Ensure that output port manipulations are done atomically. Fixes #972 2023-04-24 10:30:51 +10:00
Josh Stewart 90530f65a3 Handle 3 cylinder, non-seq, staging with >= 6 fuel channels 2023-04-16 17:20:39 +10:00
Josh Stewart 6987c966f6 Fixes for regressions in the new staging code 2023-04-13 16:35:47 +10:00
tx_haggis 0afffb2ca0
Unit test the schedule calculations (#1010)
* Refactor: separate out schedule calcs from speeduino.ino
(so they can be unit tested)

* Add unit tests for compute_delay

* Use PROGMEM to store test input & output

* Add some 720 unit tests

* Rename unit test file

* Test ignition codepaths 2-8

* Test ign1 calcs

* Add first injector calc tests

* Add 720 deg tests
Simplify

* Simplify test_calc_inj1_timeout

* Claw back RAM

* Simplify test framework
Channel angle is part of the test data set.

* Move schedule calculation unit tests into their own harness
Competing for RAM with the rest of Speeduino
can cause them to fail,

* Performance: inline all schedule calcs.

* Unit test end angle

* Unit test calculateIgnitionAngle1

* Test start angles also
And test end angles for channel 1

* Unit test calculateIgnitionAngle3

* Unit test calculateIgnitionAngle4

* Improve unit test output

* Add Nissan360 decoder unit tests.

* Add Ford ST170 decoder unit tests

* Add NGC decoder unit tests
2023-03-06 17:23:17 +11:00
Josh Stewart 311cae3fac Allow fuel staging up to 8 total fuel channels (All reasonable combinations) 2023-03-06 16:49:30 +11:00
tx_haggis f95b4978cd
Refactor comms: save 130+ bytes RAM (#906)
* Remove serialCRC - only used within parseSerial()
Also hoist the CRC read into a function.

* Minimize global variable visibility

* Encapsulate write of multi-byte primitives

* Factor out sendBufferAndCrc()

* Push safety test into TS_CommandButtonsHandler()

* Extract writePage()

* Simpler parsing

* Remove some functions from public interface

* Store constant arrays in progmem

* Centralize high speed logger start/stop code

* Factor out loadO2Calibration()

* Factor out temperature calibration table update functions

* Remove dead code

* Fix sendToothLog()

* Fix sendCompositeLog()

* Replace tooth log send booleans with an enum
Saves a byte

* Remove sendBufferAndCrcProgMem()
Use serialPayload to send

* Whitespace clean up

* Optimize comms.cpp for size

* Replace global unsigned long with bool
Saves 2 bytes

* Replace 2 global bools with an enum
Saves a byte, reads better.

* Remove global FastCRC instance

* Make sendSerialReturnCode blocking.
It was using non-blocking functions but was never
re-entered.
Rename to make blocking & non-blocking calls
more obvious.

* Use one uint16_t to track RX/TX byte count

* Simplify new comms log tx API

* Extract loadPageToBuffer function

* All endianess changes use the same code

* Doxygen comments and code organization

* Remove serialWriteUpdateCrc() & updateTmpCalibration()

* Combine SerialStatus & logSendStatus enums.
Makes sense since we can only be doing one thing at a time.

* Remove global inProgressCompositeTime
Only used when sending composite log

* Replace 3 global bools with expanded SerialStatus enum

* Remove unused global tsCanId

* Limit scope of some comms globals.

* Remove isMap global - replace witth function

* Reduce the serial API to only 2 calls
transmit & receive

* Tidy up #define visibility

* Fix Black* build errors

* Workaround Teensy code race condition
availableForWrite() is not reliable.

* Prevent race condition
Was pematurely setting the serialStatusFlag to
SERIAL_INACTIVE before final CRC ws read from
serial.

* Use post write buffer availability checks
Remove buffer size check prior to writing.

* Write multi-byte values as single bytes.
(attempt to fix Teensy 3.5 issue)

* Only use Serial.available() as a boolean test
(Teensy fix)

* writeNonBlocking checks Serial.write() return value

* Non-blocking CRC write
In sendBufferAndCrcNonBlocking().

* Fix compile warning

* Set serial status flag prior to transmitting!

* Reliable blocking byte writes.

* Fix timeout code: not firing under some conditions

* MISRA fixes
2023-02-21 12:55:54 +11:00
DeionSi 2312102d4b
Replace 8 channelXInjEnabled variables with 1 (#1001) 2023-02-06 11:48:11 +11:00
Josh Stewart 6f61bd3ee6 Allow staged fuel table mode to work with TPS load
Fixes #998
2023-02-03 10:16:57 +11:00
Pasi Kemppainen 11313ba440
Fix decel in AE Add -mode (#971) 2023-01-10 08:46:34 +09:00