Megasquirt Running with Fuel!!!
Alright, just an update...
I did some mods to my idle advance code, and I've gotten about 75% of the way done with the staging transition code.
I've made it configurable from 0 to 255 ignition events for the transition, and tonight I'll just be writing the code to actually do the transition (I'm changing where it does the transition in the code to make it easier to do a timed gradual transition, and figuring out exactly how it was done already took the bulk of my time last night.... about an hour or so for coding).
So hopefully by the end of tonight or tomorrow I'll have something worth trying out in a car... and it's also possible that tofuball will have tried it.
After I get this stuff done, I'll try to implement the multiple transitions (KPA+RPM) with the and/or functionality.
I did some mods to my idle advance code, and I've gotten about 75% of the way done with the staging transition code.
I've made it configurable from 0 to 255 ignition events for the transition, and tonight I'll just be writing the code to actually do the transition (I'm changing where it does the transition in the code to make it easier to do a timed gradual transition, and figuring out exactly how it was done already took the bulk of my time last night.... about an hour or so for coding).
So hopefully by the end of tonight or tomorrow I'll have something worth trying out in a car... and it's also possible that tofuball will have tried it.
After I get this stuff done, I'll try to implement the multiple transitions (KPA+RPM) with the and/or functionality.
Originally Posted by muythaibxr
Alright, just an update...
So hopefully by the end of tonight or tomorrow I'll have something worth trying out in a car... and it's also possible that tofuball will have tried it.
So hopefully by the end of tonight or tomorrow I'll have something worth trying out in a car... and it's also possible that tofuball will have tried it.
. I have been driving with the 4k rpm transition and while not as bad, it is still noticable. I may have one descent log w/good AFR readings.
Scott
another update, I got the code written and compiling/assembling, I changed the logic significantly from what I was doing before, and that made it a lot more simple.
I'll try to test it tonight if I have time, otherwise I'll have to get to it this weekend sometime.
After that's well tested, I'll add the and/or with a second parameter functionality.
I'll try to test it tonight if I have time, otherwise I'll have to get to it this weekend sometime.
After that's well tested, I'll add the and/or with a second parameter functionality.
Ken,
What's the algorithm you came up with? Does it work with various primary/secondary injector size combinations? I took a quick look at my old blended transition code, and it was written assuming identical primary and secondary injector sizes, and would not be well-suited to injectors of differing sizes. After thinking about it further, it might be easier to simply add a transition enrichment feature, very similar to accel enrichment, rather than trying to calculate separate primary and secondary pulse widths during that transition period.
Here's what I'm thinking: Use two config bytes, one for the pulse width adder when in transition mode (transition adder), and the second to determine the number of cycles over which to add this extra fuel. With each subsequent squirt, reduce the transition adder. Pseudocode as follows:
if (conditions for staging = true AND counter = 0) then (transition = true AND staged = true)
if conditions for staging = false then counter = 0 ; reset counter when exiting staged mode
calculate staged pw ; as in present code
if (transition = true AND counter < transition cycles) then ; set transition bit when staged logic = true
staged pw = staged pw + (transition adder) * (transition cycles - counter)/transition cycles
end if
increment the counter with each squirt
It could easily be further modified to use a constant pulse width adder for the first 'x' cycles as well. Also, users who have no need for this modification could disable it by simply setting the transition adder constant to zero.
I'd love to see fuel rail pressure datalogged during that transition event. It's very possible that firing all four injectors simultaneously causes rail pressure (and therefore fuel delivered) to drop considerably. Perhaps the dynamics of the system are such that there is a delay prior to the pressure regulator compensating for the new operating conditions, or maybe the VE table itself compensates once you move past that transition event?
What's the algorithm you came up with? Does it work with various primary/secondary injector size combinations? I took a quick look at my old blended transition code, and it was written assuming identical primary and secondary injector sizes, and would not be well-suited to injectors of differing sizes. After thinking about it further, it might be easier to simply add a transition enrichment feature, very similar to accel enrichment, rather than trying to calculate separate primary and secondary pulse widths during that transition period.
Here's what I'm thinking: Use two config bytes, one for the pulse width adder when in transition mode (transition adder), and the second to determine the number of cycles over which to add this extra fuel. With each subsequent squirt, reduce the transition adder. Pseudocode as follows:
if (conditions for staging = true AND counter = 0) then (transition = true AND staged = true)
if conditions for staging = false then counter = 0 ; reset counter when exiting staged mode
calculate staged pw ; as in present code
if (transition = true AND counter < transition cycles) then ; set transition bit when staged logic = true
staged pw = staged pw + (transition adder) * (transition cycles - counter)/transition cycles
end if
increment the counter with each squirt
It could easily be further modified to use a constant pulse width adder for the first 'x' cycles as well. Also, users who have no need for this modification could disable it by simply setting the transition adder constant to zero.
I'd love to see fuel rail pressure datalogged during that transition event. It's very possible that firing all four injectors simultaneously causes rail pressure (and therefore fuel delivered) to drop considerably. Perhaps the dynamics of the system are such that there is a delay prior to the pressure regulator compensating for the new operating conditions, or maybe the VE table itself compensates once you move past that transition event?
The algorithm I came up with should take care of both Injectors of indentical and differing sizes, and should take care of a VE that changes over the course of the transition.
My logic for turning off and on the staging transition is similar to yours, except I have it set up such that if REStaging is set, but StgTransitionDone is not set, it assumes it's supposed to be transitioning, and increments a counter (lets call this StgTransitionCnt) every ignition event. If StgTransitionDone is set, it uses the staged pulse width for both.... I reset the counter almost exactly how you describe it. I decide if StgTransitionDone should be set if StgTransitionCnt == StgTransition (StgTransition is the configurable transition count).
For the staging transition period (I'm leaving out the injector opening time here to make it easier to explain), I made the number of ignition events configurable from 0 (old behavior) to 255 (lets use StgTransition as the variable). I also created another variable, which I called pw_staged2...
I allow your normal calculation of pw_staged to complete, and then use the following for the amount of fuel to increase the secondary by and decrease the primary by:
pw_staged2 (during transition) = (pw_staged / StgTransition) * StgTransitionCnt
pw_staged (during transition) = tmp11 - (((tmp11 - pw_staged) / StgTransition) * StgTransitionCnt) where tmp11 is the total pulse width passed into your staged calculation subroutine.
The only thing I have left to do is to add a little code to round up a bit when the divisions end up less than .1 ms (I just realized that part).
After getting pw_staged and pw_staged2, I changed the part of the code that was setting the pulse widths of pwcalc1 and pwcalc2 so that pw_staged and pw_staged2 are used instead of just pw_staged.
I'm sure I've missed a thing or two here or there (like the rounding above in the case of 0 answers with remainders in divisions above), but I think I can get it all working in a satisfactory manner after some testing... If anything with the rounding I plan on doing, during the transition, the AFR will go slightly rich (from being a little too rich by .1 ms or so on the secondaries).
As for your pressure drop stuff, I think the way the stock ECU compensates is by turning off vacuum to the fuel pressure regulator when the secondaries come on... That's also how I plan on tuning my cars.... (letting the MS control the fuel pressure regulator solonoid). I think the pressure drop is most likely a momentary thing when the secondaries first come on... making sure that no vacuum is getting to the FPR will maximize the pressure, getting rid of anything but a temporary pressure drop... besides, from my reading, I believe all 4 injectors fire in batch after the transition on the stock ECU, which is exactly what we do after the transition...
My logic for turning off and on the staging transition is similar to yours, except I have it set up such that if REStaging is set, but StgTransitionDone is not set, it assumes it's supposed to be transitioning, and increments a counter (lets call this StgTransitionCnt) every ignition event. If StgTransitionDone is set, it uses the staged pulse width for both.... I reset the counter almost exactly how you describe it. I decide if StgTransitionDone should be set if StgTransitionCnt == StgTransition (StgTransition is the configurable transition count).
For the staging transition period (I'm leaving out the injector opening time here to make it easier to explain), I made the number of ignition events configurable from 0 (old behavior) to 255 (lets use StgTransition as the variable). I also created another variable, which I called pw_staged2...
I allow your normal calculation of pw_staged to complete, and then use the following for the amount of fuel to increase the secondary by and decrease the primary by:
pw_staged2 (during transition) = (pw_staged / StgTransition) * StgTransitionCnt
pw_staged (during transition) = tmp11 - (((tmp11 - pw_staged) / StgTransition) * StgTransitionCnt) where tmp11 is the total pulse width passed into your staged calculation subroutine.
The only thing I have left to do is to add a little code to round up a bit when the divisions end up less than .1 ms (I just realized that part).
After getting pw_staged and pw_staged2, I changed the part of the code that was setting the pulse widths of pwcalc1 and pwcalc2 so that pw_staged and pw_staged2 are used instead of just pw_staged.
I'm sure I've missed a thing or two here or there (like the rounding above in the case of 0 answers with remainders in divisions above), but I think I can get it all working in a satisfactory manner after some testing... If anything with the rounding I plan on doing, during the transition, the AFR will go slightly rich (from being a little too rich by .1 ms or so on the secondaries).
As for your pressure drop stuff, I think the way the stock ECU compensates is by turning off vacuum to the fuel pressure regulator when the secondaries come on... That's also how I plan on tuning my cars.... (letting the MS control the fuel pressure regulator solonoid). I think the pressure drop is most likely a momentary thing when the secondaries first come on... making sure that no vacuum is getting to the FPR will maximize the pressure, getting rid of anything but a temporary pressure drop... besides, from my reading, I believe all 4 injectors fire in batch after the transition on the stock ECU, which is exactly what we do after the transition...
Last edited by muythaibxr; Dec 9, 2005 at 09:58 AM.
Ken,
Your algorithm should work fine. I checked it via spreadsheet, and assuming the injector opening time compensation is applied correctly (scale _active_ pulse widths, not _commanded_ pulse widths), it works out perfectly.
This may be something you want to reconsider. The whole purpose of the regulator is to maintain a constant pressure difference across the injectors (rail pressure vs manifold pressure). If you arbitrarily yank the manifold pressure reference at certain times, other compenstations in code will be needed. This proposed scheme would be devastating in a turbo application, as manifold pressure may be above ambient in that case, so fuel pressure would drop, and a lean condition would result.
[quote]I think the pressure drop is most likely a momentary thing when the secondaries first come on... making sure that no vacuum is getting to the FPR will maximize the pressure, getting rid of anything but a temporary pressure drop... besides, from my reading, I believe all 4 injectors fire in batch after the transition on the stock ECU, which is exactly what we do after the transition...[/qoute]Have you scoped the injectors running on the stock ecu to verify this? If you've got the means to do that, it'd be another 'interesting to know' tidbit.
Your algorithm should work fine. I checked it via spreadsheet, and assuming the injector opening time compensation is applied correctly (scale _active_ pulse widths, not _commanded_ pulse widths), it works out perfectly.
As for your pressure drop stuff, I think the way the stock ECU compensates is by turning off vacuum to the fuel pressure regulator when the secondaries come on... That's also how I plan on tuning my cars.... (letting the MS control the fuel pressure regulator solonoid).
[quote]I think the pressure drop is most likely a momentary thing when the secondaries first come on... making sure that no vacuum is getting to the FPR will maximize the pressure, getting rid of anything but a temporary pressure drop... besides, from my reading, I believe all 4 injectors fire in batch after the transition on the stock ECU, which is exactly what we do after the transition...[/qoute]Have you scoped the injectors running on the stock ecu to verify this? If you've got the means to do that, it'd be another 'interesting to know' tidbit.
Yeah, I hadn't considered the turbo case... on an NA engine, turning off vacuum to the regulator makes perfect sense because that'll maximize the fuel pressure... On a turbo, I would guess that you'd want the pressure going into the regulator to increase the fuel pressure even more... I didn't see anything in the FSM that says how they turn that solonoid on and off on the NA, I'll have to take a look at the turbo to see what they do, or maybe even just have someone drive a stock S4 around, and see what the ecu does and when...
The only thing I noticed with my algorithm is that if you specify too many ignition events for it to transition over, and the original pw_staged is too small, you'll end up rounding up from 0 with a remainder to .1 on the divisions... and then you'll end up reaching the end of the transition a bit sooner than the user specified... So the ignition events setting is really a "max" igntion events setting due to the .1 ms resolution of the megasquirt (due to the fact that we're using a single byte to hold the pulse width). This is fine with me, and can be well documented... Once I add code for a second parameter for staging, it'll be possible to just have staging on when the pulse-widths will be high enough to avoid this problem. (based on rpm/map for example)
The only thing I noticed with my algorithm is that if you specify too many ignition events for it to transition over, and the original pw_staged is too small, you'll end up rounding up from 0 with a remainder to .1 on the divisions... and then you'll end up reaching the end of the transition a bit sooner than the user specified... So the ignition events setting is really a "max" igntion events setting due to the .1 ms resolution of the megasquirt (due to the fact that we're using a single byte to hold the pulse width). This is fine with me, and can be well documented... Once I add code for a second parameter for staging, it'll be possible to just have staging on when the pulse-widths will be high enough to avoid this problem. (based on rpm/map for example)
Last edited by muythaibxr; Dec 9, 2005 at 09:14 AM.
I'm not certain if you guys knew this or not, but there's a thread in the 2nd gen section in regards to how the stock staging works.
Don't know if this helps you guys or not.
Originally Posted by RETed
To go into a little more detail...
Primaries are fired sequentially under ~3,800RPM or so.
They alternate firing front versus rear.
At the fuel injector crossover, the primaries and secondaries are all batch fired.
So the pulsewidth is dropped, and all 4 fuel injectors fire at the same time.
That hesitation is typical grounding problems, as the current requirements are suddenly doubled due to all the fuel injectors are firing at that point.
Bad grounding will cause all kinds of headaches due to the sudden increase in current demand.
Primaries are fired sequentially under ~3,800RPM or so.
They alternate firing front versus rear.
At the fuel injector crossover, the primaries and secondaries are all batch fired.
So the pulsewidth is dropped, and all 4 fuel injectors fire at the same time.
That hesitation is typical grounding problems, as the current requirements are suddenly doubled due to all the fuel injectors are firing at that point.
Bad grounding will cause all kinds of headaches due to the sudden increase in current demand.
in the service manual it says that vacuum is cut from the fuel pressure regulator for above 50 seconds after cranking if coolant temp is above 60C and Iat is above 60C
To prevent percolation of the fuel during idle after the engine is restarted, vacuum is cut to the pressure regulator increasing fuel pressure.
To prevent percolation of the fuel during idle after the engine is restarted, vacuum is cut to the pressure regulator increasing fuel pressure.
Originally Posted by turbosa22c
in the service manual it says that vacuum is cut from the fuel pressure regulator for above 50 seconds after cranking if coolant temp is above 60C and Iat is above 60C
To prevent percolation of the fuel during idle after the engine is restarted, vacuum is cut to the pressure regulator increasing fuel pressure.
To prevent percolation of the fuel during idle after the engine is restarted, vacuum is cut to the pressure regulator increasing fuel pressure.
To prevent percolation of the fuel during idle after the engine is restarted, vacuum is cut to the pressure regulator increasing fuel pressure.
hrmm, don't think there's currently any way to have a single output trip on 2 parameters...
I guess I'll just set it up to be on all the time as long as the engine is running so there's always a vacuum reference for the fuel pump, or users could just eliminate it....
I don't really care as long as it works, so it's really up to users to make it do what they want.
I guess I'll just set it up to be on all the time as long as the engine is running so there's always a vacuum reference for the fuel pump, or users could just eliminate it....
I don't really care as long as it works, so it's really up to users to make it do what they want.
Originally Posted by muythaibxr
hrmm, don't think there's currently any way to have a single output trip on 2 parameters...
I guess I'll just set it up to be on all the time as long as the engine is running so there's always a vacuum reference for the fuel pump, or users could just eliminate it....
I don't really care as long as it works, so it's really up to users to make it do what they want.
I guess I'll just set it up to be on all the time as long as the engine is running so there's always a vacuum reference for the fuel pump, or users could just eliminate it....
I don't really care as long as it works, so it's really up to users to make it do what they want.
In any event, I don't think the mechanics involved with the fuel system could chase a pressure pulse that quick. Remember the FPR is chasing pressure all the time, thats what it does. A single blip of starting the secondaries should be well within the noise of everything else going on.
I'm pretty sure the staging logic you and Roger discussed above will solve the problem.
speaking of this logic... I'm 99% of the way done.... I still have an intermittant case where it will sometimes skip the transition and go straight into the staged pulse-width, but other than that it's looking good... a nice slow transition that I could see on the 'scope and in megatune.
Most likely I will post code tomorrow for jsmcortina on msefi.com to look at, and I'll also try to test in an actual car. Once those things are done, and I'm sure that last little intermittant problem is gone, I'll post it here.
Most likely I will post code tomorrow for jsmcortina on msefi.com to look at, and I'll also try to test in an actual car. Once those things are done, and I'm sure that last little intermittant problem is gone, I'll post it here.
OK, I have code that I'm reasonably confident in.... It worked flawlessly on the oscilloscope, and I believe I accounted for all of the "weird" cases, like accel enrichment is engaged while the transition is in progress, the code should handle it.
I'll post it as soon as it's integrated into msns-extra.
I'll post it as soon as it's integrated into msns-extra.
Originally Posted by muythaibxr
OK, I have code that I'm reasonably confident in.... It worked flawlessly on the oscilloscope, and I believe I accounted for all of the "weird" cases, like accel enrichment is engaged while the transition is in progress, the code should handle it.
I'll post it as soon as it's integrated into msns-extra.
I'll post it as soon as it's integrated into msns-extra.
Thanks Ken
Originally Posted by muythaibxr
OK, I have code that I'm reasonably confident in.... It worked flawlessly on the oscilloscope, and I believe I accounted for all of the "weird" cases, like accel enrichment is engaged while the transition is in progress, the code should handle it.
I'll post it as soon as it's integrated into msns-extra.
I'll post it as soon as it's integrated into msns-extra.
TIA,
Scott
Thread
Thread Starter
Forum
Replies
Last Post
trickster
2nd Generation Specific (1986-1992)
25
Jul 1, 2023 04:40 PM
alphawolff
1st Generation Specific (1979-1985)
17
Nov 17, 2015 05:57 PM




