Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use analogReadMilliVolts for esp32 and update hysteresis #635

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

tyeth
Copy link
Contributor

@tyeth tyeth commented Sep 27, 2024

For CI assets, testing https://github.com/tyeth/Adafruit_Wippersnapper_Arduino/blob/50f17026832ba9a53d0f919a69b8e9106302fe55/src/components/analogIO/Wippersnapper_AnalogIO.cpp#L90

Combined PR including millivolt change and updated hysteresis method:

This PR now switches both periodic and on_change to use the same functions, along with using analogReadMilliVolts for ESP32 based boards.

Also this modifies the on_change event to use a sliding scale of hysteresis. Originally the code awaited a 2% change in the last raw value.
Now the scale is divided into thirds, with the lower third using the default hysteresis value of 2% applied to the whole 16bit max value (65k), which results in less bounce around 0 due to wifi / power fluctuations, the middle third using double that threshold change, and the last third quadruple that default hysteresis (where a 200mV spike was generally observed around 3.1v). There is also a 500ms anti-hammer situation on top of the hysteresis requirement.

Tested with a 10k stemma Potentiometer, and separately with a resistor divider to test stability.

It occurs to me that 500ms might be too long for some people, maybe it can be configurable in the future.

brentru added a commit that referenced this pull request Oct 3, 2024
@tyeth tyeth force-pushed the use_analogReadMilliVolts-for-esp32-scaledAnalogRead-false branch from 50f1702 to f7eebe6 Compare October 11, 2024 16:45
@tyeth tyeth marked this pull request as ready for review October 15, 2024 17:27
@tyeth tyeth force-pushed the use_analogReadMilliVolts-for-esp32-scaledAnalogRead-false branch from 6129e63 to e74fb1b Compare October 15, 2024 17:34
@tyeth tyeth changed the title Use_analogReadMilliVolts-for-esp32-scaledAnalogRead-false Use analogReadMilliVolts for esp32 and update hysteresis Oct 15, 2024
@tyeth tyeth requested a review from brentru October 15, 2024 18:58
@tyeth
Copy link
Contributor Author

tyeth commented Oct 15, 2024

@brentru this is ready for review

analogInputPin pin) {
if (currentTime - pin.prvPeriod > pin.period && pin.period != 0L)
bool Wippersnapper_AnalogIO::timerExpired(long currentTime, analogInputPin pin,
long periodOffset) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we ever pass periodOffset in? When this func. is called on L531, it doesn't seem to include periodOffset.

When would we include periodOffset and why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// note: on-change requires ADC DEFAULT_HYSTERISIS to check against prv
// pin value
uint16_t pinValRaw = getPinValue(_analog_input_pins[i].pinName);

// All boards ADC values scaled to 16bit, in future we may need to
Copy link
Member

Choose a reason for hiding this comment

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

Could you refactor this into a CalculateHysteresis function and call that function here?

@tyeth tyeth force-pushed the use_analogReadMilliVolts-for-esp32-scaledAnalogRead-false branch 2 times, most recently from 07b2512 to 603f0c9 Compare October 21, 2024 13:04
@tyeth tyeth force-pushed the use_analogReadMilliVolts-for-esp32-scaledAnalogRead-false branch from 603f0c9 to 7b10b13 Compare October 25, 2024 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants