Nick Gammon has written an example of an spark plug ISR interrupt (thanks Nick) "Ignition timing with timers and interrupts" about halfway down the page
which I would like to try and use, but would like to have 4 spark plugs with the delay and on times like he has built in for 1 spark plug all referenced to the one incoming pulse . Hope this makes sense
Unfortunately I am not clever enough to fully understand Nicks code to expand it to 4 spark plugs
I have a 2560 board
any pointers/help appreciated, thanks in advance
That is not easy at all.
Nick Gammon writes: "It's an interesting example of pin interrupts, timers and timer interrupts". That means it is for advanced users. Extending that for 4 is very hard, perhaps it has to be rewritten from scratch. At least I can't see in a glance how to extend that for 4, since TIMER1 is completely used for just one spark plug and there are not enough timers to do that with 4.
I'm interested in what modifications you think are needed. If you know the timing between plug 1 firing once, and plug 1 firing again, you know the timing for plugs 2, 3, and 4.
What are you doing with the timing information, and why do you think you need to do something different for the other 3 plugs?
Depending on the current ignition system, I don't see a problem. You have 5 external interrupt lines on a Mega. How is the ignition timing circuit set up now? Can you determine which cylinder is firing, or is there a distributor?
My 6 cylinder Ford Explorer has a transistor ignition with a three input coil (no distributor) that fires two spark plugs at once. The spark plug fires in each cylinder every revolution.
edit: Many new engines use a missing tooth ignition timing system. My Ford does. Do a Google search for "missing tooth ignition" and select images.
4 cylinder engines fire at 180 degrees. (2 input coil)
6 cylinder engines fire at 120 degrees. (3 input coil)
8 cylinder engines fire at 90 degrees. (4 input coil)
. My apologies I should have stated in my post that it was not for a vehicle my requirements, just Nicks spark plug example fitted my needs if it could be expanded to 4 out put pulses. I think Peter has answered my question as I couldnt see an easy way to expand Nicks example to 4.changeable out pulses
I would like to receive an input pulse on an arduino interrupt pin which would then initiate a timed delay then a pulse out on a digital out pin for a set time like you have done in your example but have another 3 digital out pins also with the abilities to time delay from the original interrupt with the possibility to vary all four time delays separately.
I was using the term "spark plug" because that is what you used in the example , sorry for the confusion.
What is your required precision? (ie. how much jitter can you tolerate?)
A simple solution would just be to check in the main loop() function for the required timing intervals.
A more complex solution would be to have the initial interrupt start a timer for the first required pin toggle. Then calculate when the next one is needed and so on.
Or you could have four timers running (well the processor only has 3 but with the same prescaler you could count them as six).
Personally I go for the simple solutions if they will work. If you are feeding fish, microseconds won't matter. With spark plugs they might.
Two views to 4 VS 1
The sequence of four is just a repeat four times one occurrence, therefore four single spark sequences in program series with time spacing related to the cyclic degree would make the change work.
Or opt for a single spark sequence and fire all four spark lines from the single trigger but establish gated windows for each plug on separate quadrant counts.
What is your required precision? (ie. how much jitter can you tolerate?)
The pulses arriving on the incoming interrupt pin on the Arduino at a range from 80 milli seconds to 500 milli seconds. I guess to be able to have the adjust the time delay in micro seconds would be nice
Are you saying the interrupts are 80 mS apart, or that they are (say) 10 seconds apart, but once you get one you want to pulse four other pins at intervals of (say) 80, 200, 300, 400 mS (from the interrupt point)?
What happens if another interrupt occurs (ie. another triggering pulse) but all four pins have not yet been toggled?
Depending on how fast the machine running feeding the pulses to interrupt pin on the Arduino, the range is 80 Milli seconds to 500 Milli seconds, so the delay to be set would be nice in micro seconds for granularity .
I would like to experiment correcting some timing issues in a production environment that has four lanes where at the moment all four lanes receive the pulse at the same time.
Possibly due to "chain stretch" on 1 or 2 lanes, I would like the Arduino to interface and correct this. When I saw your example on your web page I thought it sounded like what I wanted to do, just that I wanted to do it with 4 time delay changeable outputs from the 1 incoming interrupt pin instead of 1 output.
magic_smoke:
Depending on how fast the machine running feeding the pulses to interrupt pin on the Arduino, the range is 80 Milli seconds to 500 Milli seconds, so the delay to be set would be nice in micro seconds for granularity .
Well nanoseconds would be nice, but for a machine with things trundling along a belt, more realistically you can probably tolerate a few milliseconds error.
Let me put it this way: Even using interrupts you will probably have jitter of around 3 µS because of the time it takes the interrupt to kick in. So hoping the pulse will have 1 µS of jitter is a bit optimistic.
Outline the requirements before engineering.
4 Cylinders you have stated is the desired use.
OK now four stroke or two stroke which results in one spark per cylinder every four revolutions or every two.
What is your peak RPM, such as if for a car then street say a max of 6000 RPM vs strip or track. maxing at 10K RPM or more.
Automotive distributors run a 1/2 engine speed, so example a 8000 RPM engine will have the a distributor speed at 4000 RPM. Any single cylinder will receive two sparks for the four strokes needed. So if one eliminated the unneeded sparks that occur, sparks will occur at 1/4 speed or RPM or 2000 RPM. Equated to 33.33 pulses per second actually needed for the typical 8000 RPM 4 stroke engine or 66.66 pulses per second on a typical engine.
You can not set the requirements for pulses per second, PW, duration, etc. till max case is set.
If RPM is to high for a single case processor then using four processors one per plug will reduce the timing strain.
The automotive industry has already made this step.