Nice signature ![]()
However I got the point about the done in this case. (in bash I use it to halt or continue script so this case was new to me)
I did some test with the program, added several "timestamps" and at the end of the loop printed them all. (to prevent serial prints to slow down things)
Very disturbing is the fact that reading analog and writing to pwm takes over 200uS, if this delay happens at the wrong point my injection timing will be 5-10 degree to late or even worse if that happens while injecting it can mean 20-30% more diesel which melts my pistons.
400HP+ with a 4 cylinder 2.0l diesel is a bit on the edge, with 200cc diesel per 1000 injections it will run around 1000 degree Celsius and the pistons will melt at 1100... (with 160cc 800 degree)
To wrap it all together; running a loop and take action based on interrupt created flags inside that loop isn't gonna work since injection moment and duration are both time critical give or take 10uS. (20 total)
So back to my first plan (disapproved by every coder around the world ![]()
A loop that checks and set stuff, throttle, pump pressure, idle, rpm limiter etc.
Interrupts that open injector, wait injection time and close it. (during that time the loop is stalled but who cares)
connect timer to throttle so advance is manually controlled. (0 at idle, -45 at full load)
Main thing is that the time critical functions (opening and closing injectors) are interrupt driven, all other stuff can have some delay the only result of that can be that throttle feels a bit sloppy at high rpm (when times between interrupts get shorter) but in that case I was all ready holding on to my wheel and praying...