New and Improved ADC + EMA#186
Merged
anthony9975 merged 121 commits intomainfrom Jan 30, 2026
Merged
Conversation
…ialize the ADC groups
Signed-off-by: Daniel Hansen <105574022+dchansen06@users.noreply.github.com>
Contributor
|
Please fix conflicts prior to marking as ready for review |
Signed-off-by: Anthony Ma <anthony497@ucsb.edu>
dchansen06
previously requested changes
Jan 27, 2026
Contributor
dchansen06
left a comment
There was a problem hiding this comment.
Please make your changes to the ECU in a separate branch off of StateMachineImplementation, please keep the ADC changes here; thanks!
dchansen06
requested changes
Jan 30, 2026
Shrav816
approved these changes
Jan 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ADC
Problem and Scope
A classic sliding window function needs to track a certain number of previous ADC frame values for various different signals. This uses unnecessary memory, so we can fix this by using an exponential moving average. This directly smooths the ADC output based on an exponential output and the current frame.
Description
We implemented
ADC_UpdateAnalogValues_EMA(volatile uint16_t *new_values, int num_signals, double alpha, uint16_t *weighted_output)following https://en.wikipedia.org/wiki/Exponential_smoothing#Basic_(simple)_exponential_smoothing.
It returns the exponential moving average instead of a sliding window function to reduce memory usage (due to the window of previous ADC values).
Gotchas and Limitations
If the data are correlated in some way (i.e. a linear function), a simple exponential smoothing function will always lag behind and never reach the true value of the signal.
A solution would be to use Holt double exponential smoothing, which attempts to estimate the trend. This operation is still much faster than the sliding window function since we are again only looking at previous and new values and does not require more memory.
Testing
Testing Details
We tested this on a G4 board and played around with the weights.
Larger Impact
A working ADC with a customizable smoothing function and weight is essential for all other signals to be smoothed.
Additional Context and Ticket
#170