-
Notifications
You must be signed in to change notification settings - Fork 44
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
base: main
Are you sure you want to change the base?
Use analogReadMilliVolts for esp32 and update hysteresis #635
Conversation
50f1702
to
f7eebe6
Compare
6129e63
to
e74fb1b
Compare
@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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reuse the function / logic check for the on change delay, passing in 500, on line 381 https://github.com/adafruit/Adafruit_Wippersnapper_Arduino/pull/635/files#diff-4e111e8f7d844aa38d092958262d5b77683072105409145224c36ab513c0109cR381
// 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 |
There was a problem hiding this comment.
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?
07b2512
to
603f0c9
Compare
603f0c9
to
7b10b13
Compare
For CI assets, testing https://github.com/tyeth/Adafruit_Wippersnapper_Arduino/blob/50f17026832ba9a53d0f919a69b8e9106302fe55/src/components/analogIO/Wippersnapper_AnalogIO.cpp#L90Combined 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.