Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignition schedulers update #578

Closed
wants to merge 33 commits into from
Closed

Conversation

TBAMax
Copy link
Contributor

@TBAMax TBAMax commented May 10, 2021

Made ignition timing be calculated in the schedulers from the IgnitionEndAngle. Should be more accurate because IgnitionEndAngle is directly the angle that the spark is suppose to be fired at.

Improvements to the dwell timing:
-Dwell time is directly applied to timers now without intermediate conversion to the dwell angle domain and back.
-Dwell time is controlled entirely in the interrupts, so even when main loop completely locks up, it do not cause changes to the dwell time.

Also reduced code repetition and made all ignition channels to use the same function. To get them all channels accept the changes with less effort.

Update: Tested, and works with per tooth ignition timing as well.

TBAMax added 5 commits May 7, 2021 13:20
Ignition timing changed to be calculated directly from ingnition end angle (previous art was endAngle -> startAngle -> endtime)
Other channels left as is at the moment.
Initial work on refactoring ignition schedules
Updated interrupt functions on all channels to be compatible with the previous changes to the interrupt schedulers.
Reduced code repetition in ignition interrupt functions.
Copy link
Contributor

@mike501 mike501 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downloaded this version and I'm seeing issues with spark 1. Spark 2 to 4 look good. Run with ardustim generating data on 36-1 with single tooth cam. Spark 1 drops out for a few spark events, when it restarts it usually has a very large spark for the first event. Will post image of logic level output on slack of what i can see.

Further testing has show the issue moves between sparks depending on the engine speed and as it increases gets worse. Low speed (cranking) has poor timing (individual spark events have variable gaps between them). Details posted on Slack with images.

TBAMax and others added 6 commits May 18, 2021 12:15
Only allow the overdwell protection in the timers.ino to run when it is enabled and with the new ignition mode(to increase performance).
For old ignition mode incorporate the overdwell protection to the schedulers.
Plus some comments tweaked in scheduler.ino
Rearranged the angleToTime in the setIgnitionShedule() only calculated when it is really needed. Now it is not calculated when corresponding schedule is already running, this saves some time and may help on atmega platvorm since those calculations include division.
Time window between staging and impulse starting interrupts was too small for the Atmega to keep up. Just add a little extra time.
Plus make setIgnitionxCompare functions use COMPARE_TYPE, for possible future multi platvorm differences.
Adds extra parentheses around the macro argument.
@TBAMax
Copy link
Contributor Author

TBAMax commented Jun 17, 2021

Now the issues that was initially with running on Amega2560 platvorm are fixed.
Also tested updates from this pull request on actual car with running Speeduino v0.4 board (Arduino Mega).

TBAMax and others added 3 commits June 25, 2021 12:22
Put default envs back to the megaatmega2560. Should not have been changed in the first place, would be cleaner PR.
@TBAMax TBAMax changed the title Optimizations and refactoring of ignition schedules Ignition schedulers update Aug 27, 2021
TBAMax and others added 7 commits September 2, 2021 00:01
Change some more variables type to COMPARE_TYPE. Currently all timer comparators are used with 16bit. So the COMPARE_TYPE is currently uint16_t. Anyway when possibly changing the COMPARE_TYPE in the future, great care must be taken to evaluate all effects. This just adds a little bit closer to make smooth changing of COMPARE_TYPE possible.
Organize variables to use COMPARE_TYPE definition in some more places. With intention to make schedulers compatible with different width timers comparators.
The inline specifier is only a compiler hint, and the compiler is free to completely ignore it. Compilers that we are using today actually are supposed to do the inlining automatically without this specifier too, but for good measure still add it.
For cleaner and shorter code, remove the multiple global variables and place the same functionality inside the existing struct. The ignitionSchedule struct now has new member.
Basically done with intention to reduce arguments count of setIgnitionSchedule function after that.
reduce setIgnitionSchedule function arguments count by 1.
  channelIgnDegrees are now taken directly from corresponding ignitionSchedule struct
@TBAMax
Copy link
Contributor Author

TBAMax commented Sep 1, 2021

Those also need to be COMPARE_TYPE.

@VitorBoss sorry, what exactly do you mean also need to be COMPARE_TYPE?
Now I was looking the inline uint32_t getIgn1Counter(); small functions. Oh, yes those too!

Convert small "getIgnCoutenter()" functions also to the COMPARE_TYPE.
@TBAMax
Copy link
Contributor Author

TBAMax commented Oct 8, 2021

Currently seems this has broken fixed cranking override on some decoders. Under investigation.

Fix Fixed Cranking Override for all decoders.
Previously there was excessice dwell and spark produced at trigger edge. Changed that so that now coil charging is started at trigger edge and normal dwell is used. This retards the timing slightly for starting-- should be a good thing. (For most decoders that use fixed timing for starting the trigger edge should be at 5degrees BTDC).

Prevent per tooth ignition from running with fixed cranking ignition override

Add decoderHasFixedCrankingTiming = true; on some decoders that had that missing.
@TBAMax
Copy link
Contributor Author

TBAMax commented Oct 11, 2021

fixed cranking override also now repaired.

TBAMax and others added 8 commits October 18, 2021 01:22
Do not allow per tooth ignition mode to run during the fixedcrankingtiming on all triggers that support both.

Add decoderHasFixedCrankingTiming = true; on some decoders that had that missing.
Remove unused variables:
int ignition1StartAngle
int ignition2StartAngle
int ignition3StartAngle
int ignition4StartAngle
int ignition5StartAngle
int ignition6StartAngle
int ignition7StartAngle
int ignition8StartAngle
All those angles are not used any more. All things are based on ignitionEndAngles(actual spark angle).

affected files: speeduino.ino; globals.h
Cleaner code. Remove dwell angle from calculateIgnitionAngle() function arguments, since this is actually unused. Dwell is based directy on dwell time.
Remove "fixedCrankingOverride" variable because it it not used any more. It was previously used to regulate dwell during fixed cranking timing, but now the dwell is regulated in the schedulers.
Those function declarations were still not updated. Functions themselves were already updated earlier.
Use functions to set the ignition compare values with the perToothTiming. This fixes the some kind of type conversion issue that caused occassional very early spark events previously.
Add cast to COMPARE_TYPE also for idle. Similar issue of that cast missing was causing issues with the ignition timing. This is needed when 32bit timer is used in the 16bit overflow mode. So apply it here too.
TBAMax added a commit to TBAMax/speeduino that referenced this pull request Nov 27, 2021
Combine setIgnitionSchedule functions into a new generic function. This reduces code duplication in this area quite a lot.

This is a continuation/alternative from noisymime#686 and noisymime#578. Only taking some(better) parts from the both and keeping changes in the manageable level. Only the code parts that are in the main loop are modified, interrupts are left as is at the moment, because do not want to add extra function calls to the interrupts. And also this would be to probably too much for single PR.
It was discovered that ignitionSchedule[i].member calls seem to be slowed than ignitionSchedule->member calls so this uses the latter variant. Also this seems to be the safer option.
Move IgnitionStartFunction and IgnitionEndFunction to be with the ignition schedule struct. Reduced code repetition.
0.1% RAM saving, 0.1% Flash saving observed on black_F407VE
@TBAMax
Copy link
Contributor Author

TBAMax commented Jan 21, 2022

At the moment this is still a draft because some bugs were discovered and need to be fixed here. All the fixes are already done in the https://github.com/TBAMax/speeduino/tree/mainbranch but need to be brought over. Can not do this by simple cherry-pick but must manually copy paste over because in the mainbranch there are also changes to the fuel chedulers. Thinking of maybe doing a joint PR for new fuel and ignition both, but unsure if there is any interest at the moment.

@TBAMax
Copy link
Contributor Author

TBAMax commented Feb 28, 2022

@mike501 left a good comments on the slack about how to test the ignition jitter with the Sigrock PulseView. Too bad it is gone from there by now. Need to do some tests and figure that out again.

@TBAMax
Copy link
Contributor Author

TBAMax commented Feb 28, 2022

Replaced by #804

@TBAMax TBAMax closed this Feb 28, 2022
@mike501
Copy link
Contributor

mike501 commented Feb 28, 2022

The comments may be gone, but I am not! Give me a shout on Discord or Slack and I'll figure out what I told you before. It will have been along the lines of set up a 'timing' decoder for each ignition channel, remove average, select 1 edge (usually falling) and delta. You can then see how much the individual ignition event moves on that specific channel by looking at the delta. To improve my debugging I also added some code to turn on a single specific pin every time any ignition event occurred & set a flag high. I then added code in the main loop to turn off the pin if the flag was high and reset the flag. This allowed me to monitor every ignition event compared to each ignoring the specific ignition channel via another 'timing' decoder.

@TBAMax TBAMax deleted the Testimiseks branch April 7, 2022 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants