I still think that the actual pattern handling MUST be low level and pattern specific.
I now know that the math IS too slow to run inside the ISR, BUT, it's fast enough (so far) to run for every event at most RPMs.
What I thought of a week or two back, and started to clarify more recently is the following :
- Specific code runs to determine if a tooth is valid etc
- That specific code uses a generic array to store the timings inside by tooth count and position
- For each ADC sample, the math code runs, determines if, when and for how long each of the maximum possible 24 pulses occur, calculates which tooth is best to schedule from, calculates the appropriate delay from that tooth, loads the data into a generic array
- For each tooth the scheduler runs through the array and configures required pulse widths to start as pre calculated
As for math etc, there will still be quite a bit done in the ISRs for the purposes of discarding teeth etc. I think for quick reaction for RPM cut effectiveness there should be a "rough" RPM calculation done in the ISR too and no ign and/or fuel scheduled/started if the limits are exceeded etc.
The math code can analyse the tooth timing data recorded by the ISRs to generate an accurate RPM and Delta RPM and Delta Delta RPM to base calcs and timings from.
Fred.
BTW (Off Topic), the HAL is something that is definitely a good thing to have for everything else, I've discussed that in a number of places referring to it as "port configuration code" or similar. I should find/start a thread dedicated to that as it's very important to have that working well for the simplicity of setup and configuration. The only other viable alternative is to have various features hard assigned to various pins which is ugly, but could work for a large enough pin count. If the number of features was less than the number of pins it would be desirable to have no choice about where to put things, just hook it up and turn it on. You can't get more simple than that.