speeduino
speeduino copied to clipboard
Faster better ADC reads
- New non-blocking analog digital converter functions for STM32 and atmega2560. Each board have its own functions in the board definition files.
- ADC_sequencer state machine to accomodate non blocking ADC reading in proper sequence, and at required intervals for reads that are not done very often.
- in sensors.ino update all getXXX() functions to accommodate new style of read.
- Separate EMAP read from MAP read becasue we can not do two conversions at the same time with non blocking manner.
- Fix various initializations for analog reads: baro, etc.
- Lowered(non overclocked) ADC frequency for atmega to get more accurate reads. ADC clock 125kHz (vs. 1MHz overclocked)
- Increased sampling time for STM32, this gives more stable and accurate reads.
- TPSdot calculations moved to readTPSdot() and it is called only when there is new data. Also TPSdot sampling frequency matched(40Hz) to the integer calculations. Increased loop speed from that about 50 more loops/s on atmega2560.
- Loops/s on stm32 jump form 6000loops/s to 17000loops/s
- Loops/s on atmega no big change. Only more steady analog readings because of lowered AD converter clock.
- No increase in RAM or flash usage.
- Increased reading frequency for IAT,O2,O2_2,BAT (30Hz)
- Increased reading frequency for TPS (40Hz)
- ADC timing checked with logic analyser on atmega2560 by flipping a spare pin for each ADC read. Timing was found to be correct. The optimized timing timing scheme is working as expected.
Also conversation about that and some history of development is in the issue #778 .
So, I was reading this yesterday and come with some questions. Why did you remove the timer flags and use a millis() pull, subtraction and comparisons to the same rates? That takes a lot more time than checking a bit. Isn't a way to make it clear in a way to be easily added or changed the readings rates in the future?
@VitorBoss good question actually. I went for the standard millis() timing just for simplicity reasons. Otherwise when trying to use the timer flags with this scheme there would need to be some temporary copy of the flags inside the sequencer, to grab the flags when they are set, and store until needed conversions done for each flag. Maybe that can be done if it is determined that it is worth the effort... indeed. So far the millis() scheme has been very convenient when changing the reading intervals.
Ok, now I think it is ready.
Int is 32 bit on stm32. Computation results default to int. So when using computation inside the if statment the rollover do not occure as usual and the thing do not work. All comparisons must be ensured to be between firmly defined types to work on all platforms. Fixed now in d1b57e7
Just a note here. Currently has become to the notice that TPS default filter settings probably need to be changed also due to the TPS reading frequency increased. Currently this PR have some merge conflicts that I have not managed to remove here. The testable version with most merge conflicts removed from this but also includes new fuel and ignition schedules and timers change PRs for testing is here:https://github.com/TBAMax/speeduino/tree/mainbranch As the new merge conflicts continue to accumulate here, maintainig here is on request only at the moment, I can bring the tested changes over. I just leave this as is here for now.
Hi, This PR looks great, also fixes the initalisation problems I saw with my PR https://github.com/noisymime/speeduino/pull/670
Would you consider also merging the replacement for FILTER_ADC that I put #670 which fixes the non-convergence when using heavy filter values into this PR? If you want to update this PR I will pull it into my own branch which I am working on. https://github.com/HWright9/speeduino/tree/Speeduino_PowerSports