Skip to content

New and Improved ADC + EMA#186

Merged
anthony9975 merged 121 commits intomainfrom
ADC
Jan 30, 2026
Merged

New and Improved ADC + EMA#186
anthony9975 merged 121 commits intomainfrom
ADC

Conversation

@anthony9975
Copy link
Copy Markdown
Contributor

@anthony9975 anthony9975 commented Jan 23, 2026

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

  • HOOTL testing
  • HITL testing
  • Human tested

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

ManasijaBhargavan and others added 30 commits November 4, 2025 09:57
Signed-off-by: Daniel Hansen <105574022+dchansen06@users.noreply.github.com>
@dchansen06 dchansen06 added Enhancement New feature or request 2 PRIORITY Important and a priority, but less than URGENT Sensors Something involved with or related to sensors Peripheral Related to or involving a peripheral including abstractions labels Jan 23, 2026
@dchansen06 dchansen06 marked this pull request as ready for review January 23, 2026 10:17
@dchansen06 dchansen06 self-requested a review as a code owner January 23, 2026 10:17
@dchansen06 dchansen06 marked this pull request as draft January 23, 2026 10:17
@dchansen06
Copy link
Copy Markdown
Contributor

Please fix conflicts prior to marking as ready for review

@anthony9975 anthony9975 marked this pull request as ready for review January 27, 2026 04:25
Copy link
Copy Markdown
Contributor

@dchansen06 dchansen06 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make your changes to the ECU in a separate branch off of StateMachineImplementation, please keep the ADC changes here; thanks!

Comment thread BLINKY/G4BLINKY/Core/Src/main.c
Comment thread CMakeLists.txt
Comment thread ECU/ADC.ioc Outdated
@dchansen06 dchansen06 marked this pull request as draft January 27, 2026 06:52
@anthony9975 anthony9975 marked this pull request as ready for review January 30, 2026 04:11
@anthony9975 anthony9975 dismissed dchansen06’s stale review January 30, 2026 04:12

He said it was fine

Copy link
Copy Markdown
Contributor

@dchansen06 dchansen06 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two file fixes

Comment thread ECU/Core/Src/adc.c
Comment thread ECU/Core/Inc/adc.h
Copy link
Copy Markdown
Contributor

@dchansen06 dchansen06 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@anthony9975 anthony9975 requested a review from Shrav816 January 30, 2026 04:25
@anthony9975 anthony9975 merged commit 6f76fbb into main Jan 30, 2026
1 check passed
@anthony9975 anthony9975 deleted the ADC branch January 30, 2026 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 PRIORITY Important and a priority, but less than URGENT Enhancement New feature or request Peripheral Related to or involving a peripheral including abstractions Sensors Something involved with or related to sensors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ADC Smoothing

7 participants