I have now implemented more accurate ignition timing control which is based on degrees before top dead centre rather than a fixed time period.
I’ve also implemented a simple fuel map with the ability to store new values, display the map and save the map over serial from the Arduino.
I have made the fuel duration and ignition timing variable using potentiometers and the Arduino analogue inputs. Since the Stellaris launchpad PWM outputs are 3.3v I have had to tie a 3.3v reference to the Arduino aref pin and set the analogReference to EXTERNAL. I have also added a simple low pass RC filter between the PWM pin and the analog input to help smooth it, since otherwise, the analog input will only ever read 0 or 1024, depending on the part of the cycle that the PWM is in. An alternative to this is to implement a low pass filter in software. I’m sure that there are a number of ways to do this, but a common one is to create an array which you push elements on to and discard the oldest measurement, then average that array. This should work, but always seems a not memory and processor intensive for me. Another trick is to use the formula
val = 0.999*val + 0.001*newVal
This has the are effect, what is is effectively doing is to say take most of the old value and a little of the new value and that’s your average. This would be placed inside the measurement loop. The problem with it is that it uses floating point calculations, which may be more processor and memory intensive than the array method depending on your hardware. I would have to perform tests to see which is best for the Arduino (which doesn’t have dedicated floating point hardware).
I’m currently having a problem with the Stellaris Launchpad where writing a new capture and compare value to the timer is taking a long time or in some way causing the timer to reset and hence this messes up the missing tooth generation algorithm. I also don’t seem to be able to set this timer value from any interrupt routines, but only from the main loop.
Thinking about it, I have a feeling that when I write a new value to the timer capture register, it also resets the current time count which hence causes the timer to take longer than it would have done to lapse and trigger the interrupt. I will have to look into this.