Variable Spark Timing

Ok Veeky Forums. Software engineer here and I'm really curious about the learning algorithm that modern cars have to compensate for spark knock.

Lets say you have a car that recommends premium from the factory. You put in 87. The car knocks under load and it retards the timing.

When does it try to advanced the timing again in order to take advantage of what may be higher octane fuel? Under load does the vehicle always attempt advancing the spark?

So the effect of low octane in a premium car should be as follows:
>detects throttle is wide open or the car is under load
>advances timing to get moar torque
>detects spark
>retards
>later down road you hit hill and increase throttle
>tries to advanced spark
>detects knock
>retards timing
>rinse repeat

Now! The algorithm should only take place with low octane fuel. Lets say you did put 93 in the car, if the vehicle kept trying to advanced the timing past what 93 could handle you would always be going through this cycle of "increase timing advanced, detect knock, retard timing". This would help the vehicle constantly find the most aggressive timing advanced possible, BUT the process of advance, knock, retard, takes away power and is a bit abusive on the engine.

So naturally the algorithm should have an upper range of timing advanced that is set to what should be possible under 93 octane right? So that it only knocks and retards when low octane fuel is used and it never tries to "over advanced" the spark under what should be 93 octane fuel usage.

My particular car is a BRZ but this question applies to all modern cars.

tl;dr
Is my cars variable timing advance as smart as it should be, or is the algorithm more likely poorly designed?

Other urls found in this thread:

openflashtablet.com/shop/oftofh2-combo/
perrin.com/shop/engine/lightweight-crank-pulley-for-fr-s-brz
perrin.com/shop/vehicle/subaru-brz?
perrin.com/shop/air-induction/inlet-hose-for-fr-s-brz
knfilters.com/air_filter/2015/subaru/brz/2.0l?ad_id=5387&gclid=EAIaIQobChMIrtTQwd602QIVVZ7ACh3f3gnzEAQYASABEgKHBPD_BwE
tirerack.com/wheels/WheelCloseUpServlet?target=runWheelSearch&initialPartNumber=4927806545B&wheelMake=Enkei Tuning&wheelModel=TS9&wheelFinish=Black Painted&autoMake=Subaru&autoModel=WRX&autoYear=2015&autoModClar=
perrin.com/shop/engine/accessory-pulley-kit
ft86club.com/forums/showthread.php?t=66505&page=3
ft86club.com/forums/showthread.php?t=56341
youtube.com/watch?v=jUUPcNPGm3k
ls1tech.com/forums/generation-iii-internal-engine/372791-piston-slap-explaination-gm-engineer.html
twitter.com/NSFWRedditImage

Depends on the manufacturer.

On Mercs (the company I work for), its rather intuitive. Kinda, common sense programming really. If it repeatedly finds a knock, it will become more and more cautious, while storing a code (no CEL trigger) for the dealership to find upon the next service, so we can decide what needs to be done.

Most engines though will retry every few seconds, the timing is retarded to a pre-set known safe degree (pre-set by manufacturer) for about 3 seconds and then it will try advancing again, over and over and over with no limit to the attempts, never actually warning the driver or technician of any issues.

To add, best way to understand it is to actually watch it happen.

Connect to the diag port, pull up the realtime data for the timing, and then tap on the valve cover with something metal. It will consider that to be an engine knock and retard the timing, you'll see it back off for a few seconds then go back to normal.

Do it again and again to see how it responds differently over time, if it adapts at all depending on manufacturer.

(not op) but how does this affect wear and tear on the engine?

Repeated (detonation) can eventually cause severe damage to the piston itself. In worst cases, holes can be blown right through the piston head.

Retarding the timing is the engines attempt at minimizing the chance of this happening when noticed.

However, timing isn't everything. Hot carbon deposits will also unintentionally detonate the fuel/air mix, in which case it doesn't matter how much you adapt the timing, bad things are going to happen.

here's something from google

damn, I bet my mustangs pistons are fucked then.

From your implication, I certainly wouldn't buy it off you.

Fucking neet. Damn Veeky Forums has some smart mother fuckers. There must be a counter in the loop that is inversely proportionate to the spark advanced attempt frequency. Does this counter reset with key off? What if you get the counter so high it "learns" to run off 87? Obviously this will vary with the engineer who wrote the code but what about your case? Is there an upper limit to the spark timing advanced frequency decrease?

Damn I'm fucking excited to try this. Open Flash sells a tablet that plugs into the OBD2 and lets you see live stats.

Yeah premium fuel cars are different from normal cars in more ways than the sticker on the fuel door.

i mean technically it's only minor pinging when in highway/OD gear and only if its at

OP here, you're not off topic. Engine ping and machine learning are the general topics. If I pose anything about code in /g/ they usually say something along the lines of "we aren't here to help you with your homework piss off".

Yeah it's not a surprise /g/ is worthless

I wonder how I could figure out the learning algorithm used in my BRZ. Other than an educated guess using a tablet and artificial spark knock like you suggested.

Knock sucks but it has to be pretty bad to wreck an engine. Forged pistons knock until they’re warmed up usually

Typical misfires, or knock, iare detected by crankshaft acceleration numbers, not so much the knock sensor. The knock sensor is designed to help fine tune timing numbers, and catch OMG extreme knock. The average misfire is all crank position calculated.

The knock sensor is "piezoelectric", meaning vibration causes it to produce AC voltage. AC voltage signal is interpreted as "% Knock" by the ECU. Learned knock values function identically to long term/short term fuel trims. Long term moves to keep short term hovering around 0%. If long term/learned knock deviates above a certain percent, or cannot bring short term/knock % within spec, a code is set.


FWIW: Hondas and Mazda 4 cyl in the 90s had a crank position sensor, only used for misfire detection. All of the true cam/crank/tdc numbers were from the dizzy/CAS respectively. The belt drive lowers the resolution such that the dizzy/CAS couldn't detect minor, but catalyst damaging, misfires.

Shit thats genius. Because piston suffering from knock will accelerate differently during the compression stroke from normal. Well do you know how often vehicles check and adjust spark advance? Is it possible for a car to “learn” to run on 87 because it repeatedly has spark knock and the algorithm tries to avoid it as it happens frequently? Or is that stupid and it always tries to achieve maximum spark advance on engine startup and under load?

I understand it will develop some sort of “long term” tune. But hypothetically this means i could put 87 in a car long enough for the engine in a premium car to not attempt spark advance.

How often? Fast enough you need to graph it to watch the movement. Most modern cars have a 32 tooth trigger wheel system on the crank (at least stuff that still had an exposed crank sensor). So, 32 reference points per rotation, 4 stroke cycle is 2 rotations, realistically 16 points of reference through the power stroke on one cyl.
I hate the word "learn", for cars. The car adapts, and although the adaptations are "learned" they can be reset by a scanner or battery disconnect, and also be fooled into giving incorrect data.


There's also a big misconception about when the car adjusts timing/fuel/spark. Open/Closed loop refer to the feedback cycle, where the computer makes a change, sees that change, and reacts again. This is closed loop, the full cycle of change/response. During open loop, the engine relies solely on the pre-programed maps, wide open throttle is one of these times. As cars have gotten hit with increasing standard for emissions, closed loop almost all the time is becoming the norm. The modern stuff has a MUCH higher tolerance for octane variation.

Yes, the ECU will always run as much timing as it can get away with, within the parameters set for it. The ECU has guidelines, adjusts timing and "learned timing", to maximize not just performance but MPG and emissions as well. The ECU is absolutely checking several times a second for misfires, and trying to advance timing if it can. Remember though, outside of wide open throttle, and peak cyl pressure situations, the octane rating is somewhat irrelevant. 1/4 throttle, flat road, 45mph likely only requires 80 octane or less. You only need 40hp or so to do that.

It may "learn" for the 87, but it is going to try its hardest to bump the timing. The ECU is just waiting for the second 91/93 squirts from the injectors, so it can run more timing. Like I said, constant feedback and tuning. The ECU is running at a much higher speed than most people consider.

1000rpm idle, 16rev/sec. 8 full 4 stroke cycles per second, and the ECU isn't trying for ALL THE TIMING here, but floor it, and it wants to give the best it can, and get closest to the "ideal".

Should note, open loop at WOT isn't the norm anymore; emissions regs tightened down on that.

Damn. Thanks for the reply. What the fuck do you do for a living user?

>Depends on the manufacturer
Indeed. This doesn't answer OPs question but is kinda relevant:

>Trionic is an innovative engine management system developed by Saab Automobile, consisting of an engine control unit (ECU) that controls 3 engine aspects:

>Ignition timing,
>Fuel injection
>Acts as a boost controller.

>Hence the numerical prefix 'tri-' in Trionic. 'Ion' comes from the fact that it uses ion current measured by the spark plugs between combustion events as a sensor for knock, misfire and synchronization detection. With the ion sensing system, the ion current stream developed due to combustion can be deduced by monitoring the secondary current of the ignition coil. Using the value and wave shape of the current, after the actual spark event, the quality of the actual combustion process is determined, thus allowing the engine control unit to optimize the timing of the spark for the best engine performance while keeping emissions low on a much wider range of rpms.

>Many people around the world are working on reverse engineering the Trionic engine management system, by way of various open source communities. The work involves understanding the binary files stored in the ECU itself, and what changes affect the car's hardware and operation of the vehicle

I'm a mechanic; and have some experience tuning my own car with Megasquirt. I basically have my hobby as my career.

So it has a built in oscilloscope? THAT is very cool, as someone who finds spark wave forms fascinating.

Damn user. Lemme get you a business loan and get you your own shop. I hate seeing underutilized mechanics.

Wanna talk about car builds because I wanted to tweak some things on my BRZ? I simply want 200 at the wheel (170 is base).

Also, when you tune... what are you actually altering? Lets say the vehicle has its machine code thats installed... you can't overwrite that, as far as I know. So you simply change the baseline of the various sensors (so the man sensor would read x amount of airflow as x+2). Well can you alter things like the algorithms handling things like detonation or is tuning simply, "sensor spoofing"?

Thank you sir.


"Tuning" means several things depending on make and era the ECU was designed.

The first level of early 90s tuning was crystal swaps (overclocking the ECU) and piggy=backs (which lied to the ECU to maximize power). Usually cheating the intake air temp, trying to pick up a degree of timing or two, mess with the mixture a bit.

Then stand-alone ECUs became a thing, Megasquirt, AEM, Hydra, Motec, etc. 100% open slate. The interface is pre-designed, but you must develop spark/fuel tables, A/C idle up behavior, cold start settings and idle air control duty cycle. It's a steep learning curve, beyond what most people want to do. I have a megasquirt3. I would not have one if the car wasn't a motor swapped toy. NOT daily drive friendly until you get it sorted out. For instance, cold start, you get 2 tries per day. It takes a while to start well at 30*, and now you're late to work.


Nowadays, the ECUs have been "cracked", and actually have native "write" capacity. I know "chipped" hondas were a thing in the early 2000s, basically a chip was soldered onto the ECU board, allowing writing of the ECU tables.

The cracking of the ECU code, along with native write capacity, opened the door for a LOT more; and also created the "tune in a can" stage 1/2/3 stuff. You can just email someone $300 or whatever, they mail you a cable with a box attached, you plug it in, it flashes the ECU, more power.

With the tuned ECUs, you usually alter only what you want, so cruise/cold start/AC can be untouched, but it makes a bit more power.
I won't claim to be an expert on the BRZ motor (it's a bit newer than my hobby cars), but IMO 30whp will be a significant change. Full exhaust (removing cats in manifolds if possible, keep at least the rear cat, accept the 1whp at 7000rpm loss to be a responsible adult), and a tune would be my starting point, knowing basically nothing about the platform.

There is no set change to make, even across identical engines. For instance, setting idle should be the timing value that produces maximum vacuum. 2 engines that came off the assembly line right after each other may require 0.25* of idle timing change to be "perfect".


Most of what we give up in the US, is for emissions. So when tuning, you want to maximize peak power, safely, within a given RPM/load range.

So the engine flows whatever grams/second of air, at 1/2 throttle, that is a fixed value, keeping temp and pressure constant. So we bump fuel a bit at a time, until it makes less power, the revert. We bump timing until it knocks or makes less power, then revert. The fuel/timing tables look like a topographical map. You want smooth curves with no sudden peaks or valleys. These will be driveability problems. So you can add 2% unnecessary fuel around a certain area to smooth it out, even if those load cells don't "need" that fuel.

Something a lot of people neglect, is that "tuned" cars should still have decent mpg, and good emissions output. My miata makes approx 30whp over stock, and I cruise at 14.7/1. MPG went down a bit, only because it gets driven harder now, and my warm up is still a bit rich. Fuel injection means the best of everything.

Well Open Flash Tablet has unequal length catless headers and an ecu tuner. They show +10whp from a tune with the headers installed. I figured I'd put a k&n drop in filter and better inlet tube for good measure that way my airflow sensor gets less turbulent readings. Perrin sells a nice set of lighter pulleys, plus I have lighter wheels on the car. I was hoping headers, intake, and tune would get me +10-15whp, and lighter wheels and pulleys would account for +5whp. Is this too wishful? I do not want a full exhaust.

The stock inlet tube has this goofy noise maker thing that runs under the dash on the passenger side. Fuckn stupid.

The "build" for lack of a better work.

openflashtablet.com/shop/oftofh2-combo/
perrin.com/shop/engine/lightweight-crank-pulley-for-fr-s-brz
perrin.com/shop/vehicle/subaru-brz?
perrin.com/shop/air-induction/inlet-hose-for-fr-s-brz
knfilters.com/air_filter/2015/subaru/brz/2.0l?ad_id=5387&gclid=EAIaIQobChMIrtTQwd602QIVVZ7ACh3f3gnzEAQYASABEgKHBPD_BwE
tirerack.com/wheels/WheelCloseUpServlet?target=runWheelSearch&initialPartNumber=4927806545B&wheelMake=Enkei Tuning&wheelModel=TS9&wheelFinish=Black Painted&autoMake=Subaru&autoModel=WRX&autoYear=2015&autoModClar=

>he doesn't do an italian tune every drive
555-come-on-now

MAF doesn't care about turbulence, it's all about air resonance frequency and flow dynamics.

Avoid lightweight crank pulley at all costs. Most don't function as harmonic dampers and transmit that force into the bearings and oil pump. No thank you.


The header and the tune are reasonable, what are the 3 dyno runs? Call that 10whp.

The intake tube looks like it is better designed against heat soak than OEM plastic, that and K&N are likely 1 whp.
I don't have much knowledge about the platform, but what parts make the most area under the curve? I built my VVT miata choosing parts for area under the curve, in the mid rpm.

And are all these dynos running 91/93? That's one way to get the most out of the car, every little bit helps with N/A 4 cyl.

I'm guessing the three dyno runs are stock, 93 with headers and tun, and 85 with headers and tune. I can't discern which though. The guys who made that website didn't pay attention in technical communications 1.

The car is "93" from the factory but tuning for the headers and a better air filter should achieve better results. The "out of the box" tune is good but conservative as it has to account for variables between each engine. So a custom tune on a dyno with all the sensors should get me better results... I hope.

Couldn't I hope that the boxer is well balanced on its own, and hope that the crank pulley doesn't balance it much at all? kek

Well does that rule out getting the alternator and water pump pulley?

perrin.com/shop/engine/accessory-pulley-kit

If it is balanced (that appears so), no big deal. Just accept it's a for fun/looks mod over most else. A lightweight flywheel can make a feel much zipper. I have a hard time believing the crank pulley will help much with a stock clutch/PP/FW.


I'd guess a custom tune would get you the 15+whp you want with all the other stuff. Ideally do a same day baseline with stock ECU vs. tuned. It's about HP gained, not the number. Some dynos are heartbreakers, others wild optimists.

Alt and WP have no bearing on balance. I was just worried about those shady "underdrive" pullies they sold online for years.


No balance, spins accessories more slowly, all to save 3lbs.

Harmonic balance =/= different from vibration balance. A four cylinder is FAR from being perfectly balanced on that front, you'd need a 10 or 12 cylinder for a minimum of power cycle overlap.

Not that a 4 cylinder boxer is perfectly balanced, it's better than an inline 4 but it still does twist back and forth because the left back is slightly behind or ahead of the right bank, it isn't a perfect symmetry.

Such split opinions. For the gains in engine performance... I'll pass. Juice is not worth the squeeze. Perhaps I can look into the lightweight flywheel and drive shaft options?

I read a huge thread from a guy who apparently called Subaru and asked a tech support guy.

Note post #30
ft86club.com/forums/showthread.php?t=66505&page=3

And the reason the crank pulley looks more complicated than a simple pulley is because that same crank assembly is used on other cars. Other than serving multiple vehicles Subaru apparently claims its a simple pulley.

Again though. The Juice gained from the squeeze ect. The alternator and pump pulley might look cool and satisfy my current unreasonable desire to eliminate spinning weight but I'll sit on it a few moar weeks.

ft86club.com/forums/showthread.php?t=56341

Shows a few hp just from the filter and silicon inlet tube. Neat.

Lol, you're thinking of something else entirely. Forged pistons expand much more than hypereutectic pistons so they will slap against the cylinder walls in some cases when cold. It sounds like death but isn't necessarily broken.

Check out the Haltech Elite ECUs for an understanding of how these long term trims work. They have a nice video here: youtube.com/watch?v=jUUPcNPGm3k

A lot of ECUs will try every so often to advance the timing slowly until it starts to see light knock before backing off until it reaches base values, which are often best case (good quality 93 octane or 91 octane for premium cars).

The Haltech Elite ECUs don't add timing back in if you screw up and do something like add 87 octane right now but theoretically they're working on adding that feature in for a future software build. Hard to say if it's ever showing up though.

/r/ing more info on how pistons slap cylinders sometimes without it causing a catastrophic malfunction... I'm sincerely intrigued.

Not gunna lie I ran 87 in my BRZ for 27,000 miles straight. Wonder if I did any damage, kek. I wonder if it will properly advance the timing now that I'm putting 93 in it. Should I disconnect my battery for a bit?

ls1tech.com/forums/generation-iii-internal-engine/372791-piston-slap-explaination-gm-engineer.html

It's the sound of the piston rocking, but the rings are still making proper contact with the cylinder bore. Once the engine warms up it goes away.

As long as you ran the stock ECU and you didn't get a shit-tier tune that fucked with the knock control, it's fine to run 87 on your car. It'll just lose appreciable amounts of power and fuel economy. Stock ECU settings are conservative because they know that people like you are out there.

>people like you
keked again

The BRZ is bone stock. Commuting in and out of the city. Other than the 87 I take decent care of it. Getting the tranny and diff fluid flushed by the dealer next month to keep it fresh. City driving is pretty demanding on the clutch I'm sure.

87 octane poor cuck detected

Fun fact, with the next gen Mazda3 (2020) they found that 80 octane gasoline is best for maximizing HCCI operation. So you should run the lowest octane you can buy for max MPG or the highest octane for max power.

My $20,000 car better have decent enough engine management to handle anything out of a pump but 85. As a Computer Science major, Id say anyone who put a car on the road without a decent enough algorithm to Adapt the engine to lower octane ( at the cost of mpg and hp) should die. This is why we cant have nice things.