speeduino icon indicating copy to clipboard operation
speeduino copied to clipboard

Timers to millis(), tacho to timer2

Open TBAMax opened this issue 2 years ago • 5 comments

Interval timers converted to using only millis(). And now freed timer2 used with compare interrupt for tacho output dwell time on atmega2560. Beautiful tacho timer macros. All other platforms use micros() and function in the main loop for this, with their sub microsecond loop times. Logic analyser waveforms observation promices some jitter reduction. (because of cleaned up interrupts) About 50% jitter reduction for ignition timing on atmega when combined with improved schedulers form PR #804.

TBAMax avatar Mar 02 '22 22:03 TBAMax

I just add here the comments on some concerns regarding this PR.

  1. Overdwell protection is indeed removed as it was from timer2. This is because of hoped that PR #804 is also included. There is better overdwell protection built in for the main scedulers. For the new ignition mode(ignition set in the decoders) it is yet to be determined how safe it is (needs to be adressed in the PR #804). So this is indeed a little safety concern at the moment. 2.More function calls out of the ignition scheduler interrupts. That is setTacho() function is called with the beginCoilcharge() fuctions. Special attention is given to keep setTacho() function as short as possible. Also at some point I checked with the disassembly listing for atmega that this function is automatically inlined and do not produce any exessive jumps in the processor code actually. With the latest version now this needs to be verified again. 3.Flex fuel sensor reading that previously was in the every 1ms interrupt is now moved to the main loop. The current understanding is that as flex fuel sensor pulse width measuring period is 1s then with the current loop speed that has loop times in average close to the 1ms (1000 loops/s). The reading accuracy is close to the 0.1% that should probably be more than enough accurate. Flex sensor code changes actually are not physically tested, as the moment stands. So all this theorethical. Main loop times testing also shows no big fluctuation in main loop speed (some loop taking much longer time), so no problem with that (tested on atmega2560 with flipping a pin once per loop and observing with logic analyser). New timers also spread out the tasks so that for example 100ms 250ms tasks do not run in the same loop with 1000ms tasks, due to the inital offsets for the timing variables.

TBAMax avatar Apr 08 '22 00:04 TBAMax

Currently as of 19.04.2020 this PR status is unmergeable. Due to uncompatibility with other recent changes, that need to be brought up to date, and also some possible problems discovered with flex fuel fuel temperature sensor. Also idle pwm needs checking, it may be that pw value from the table is not used corretly. Just a status update here.

TBAMax avatar Apr 19 '22 15:04 TBAMax

Turns out there is a requirement in the idle.ino that 1Hz and 10Hz timer flags must be on at the same time. This means when 1Hz fires 10Hz must always too. The two must be synchronized. Unclear at the moment weather there is some other syncrhonization requirements between timers at the moment. 4Hz and 1Hz? 4Hz and 10Hz?

TBAMax avatar Apr 20 '22 13:04 TBAMax

Current status here: overwhelmed by merge conflicts. So easily unmergeable at the moment. For reference only.

TBAMax avatar May 03 '22 15:05 TBAMax

Note here for the possible future work on the subject. As on the #972 discussed the nested interrupts make the poor code readability. As at the moment this branch here have collected quite large amount of conflicts that must be resolved, still this may become relevant at some point because it removes the need for nesting the interrupts (indeed removes the use of nested interrupts alltogether).

TBAMax avatar Apr 21 '23 13:04 TBAMax