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
[Hardware Issue] Noise on knob values and analogue inputs #209
Comments
I propose to implement a deadzone percent() function of the Knob class like this: |
Note that a deadzone would be needed for both knobs and the analogue input. As the analogue input never truly reads the min or max value (in the same way as the knobs), due to the averaging done in _sample_adc(). |
I think the analogue input should be able to return values even larger than 1.0 if calibrated because of this code: def percent(self, samples=None):
"""Current voltage as a relative percentage of the component's range."""
# Determine the percent value from the max calibration value.
reading = self._sample_adc(samples)
max_value = max(reading, INPUT_CALIBRATION_VALUES[-1])
return reading / max_value since you divide by 'max_value', that will be larger than 'reading' if calibrated, it should return 1.0 without reaching 'MAX_UINT16' |
An alternative method would be to mask this problem at a lower level in the _sample_adc function using something like the example below. One benefit of doing this is that it would mask the problem in all higher level functions for both the knobs and the analogue input. def _sample_adc(self, samples=None, low_dead_zone=190, high_dead_zone=65500):
# Over-samples the ADC and returns the average.
values = []
for _ in range(samples or self._samples):
values.append(self.pin.read_u16())
#return round(sum(values) / len(values))
val = round(sum(values) / len(values))
if val < low_dead_zone: # This is just noise, remove it by setting to 0
return 0
elif val > high_dead_zone: # probably noise, set to highest value
return 65535
else:
return val |
I just updated my suggested code. The deadzones are now again in the percent() function of the AnalogueReader class and could be used by knobs and the analog input. But I am still not convinced you get that problem with the analog input in a calibrated module. At least not for 1.0. There might be an issue for 0.0, but it would make more sense to rework how the calibration works to fix this. Using a deadzone with the analog input would likely any attempt to quantize input to V/O harder. |
I was a little concerned that in our haste to develop a fix, we perhaps had not correctly defined the problem, how to test for it and how to test that any change had fixed it lol! :) ... so I created a simple test script that displays the following:
test code: https://github.com/gamecat69/EuroPiApps/blob/pot-test/software/contrib/noise_test.py When running the test, I believe the problem is present if any low value is greater than 0 and any high value is less than 1.0. I ran this test twice, once using the suggested fix to _sample_adc and once using the suggested by @redoxcode. The _sample_adc update fixed the problem for both the knobs and ain. |
I don't think this should be a implemented in _sample_adc as it returns an in from 0 to MAX_UINT16 that is the direct average of the samples that are in this range them self. Especially with sample size 1 this would result in a strange mapping. _sample_adc should do what everyone expects it to do. |
Good point around calibration for ain. I was thinking that might be a possibility and I didn't realize that your change hadn't implemented the fix for ain too.
Actually thinking about it.... once a fix has been implemented we could probably extend the calibration routine to include upper and lower limit calibration for the knobs. The calibration could also come with default best-guess values for the knobs like it does for the other calibration fields.
|
Yes, it could be included in the calibration how large deadzones should be for the calibrated unit. But I don't think it's necessary. It will be hardly noticeable if you need to turn the knob 0.1° further on one unit than the other to get the same result. However for ain it can make a great difference if you have any script that needs precision, since it needs to work with the voltages provided by other modules. |
Closed? |
Has the analogue input noise issue been fixed or was a fix only developed
for k1 and K2? If the aim issue is still present, then I guess this issue
is still open.
…On Mon, 27 Mar 2023, 18:52 redoxcode, ***@***.***> wrote:
Closed?
—
Reply to this email directly, view it on GitHub
<#209 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACKZSUJ4MDBFVQGY72NBVH3W6HAVDANCNFSM6AAAAAATHASK2A>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
There was a PR that fixed 2 point calibration (#232) |
@redoxcode: I am interested to hear what results you get when you run the test script I provided above. |
@gamecat69 I just made a fresh setup with the firmware 0.8.1 (not calibrated) and your script and I get 0.0 and 1.0 for both knobs and 0.0 for ain. I tested with and without usb power (always with eurorack power). Also I tested to have something constant connected to ain and that shows up as some value > 0.0 as expected. |
Thanks for performing the test @redoxcode. I just did the same test on two modules using two different power supplies. |
@gamecat69 can you try to do the 2 point calibration and see if that helps?
|
Closed? As OP hasn't answered and #211 (comment) is closed as well? |
Sorry for the delayed replies. I will test this with the latest firmware
and report back.
Kind Regards,
Nik
…On Tue, Aug 15, 2023 at 10:43 AM redoxcode ***@***.***> wrote:
Closed? As OP hasn't answered and #211 (comment)
<#211 (comment)>
is closed as well?
—
Reply to this email directly, view it on GitHub
<#209 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACKZSUMY5PO2LTJHBGR2TSDXVNACZANCNFSM6AAAAAATHASK2A>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I have done some testing, but TBH I got lost in PRs and sorta duplicate
issues in the repo :(.
I think that Issue #209 (
#209) should still be open
(see test results below).
However, the other PRs and issues etc that branched off from the original
issue may possibly be closed, but I guess this might be open to
interpretation.
Testing (issue 209)
I calibrated a module running firmware 0.10 and micropython 0.19. I used
the high-precision calibration routine.
My test script (
https://raw.githubusercontent.com/gamecat69/EuroPiApps/pot-test/software/contrib/noise_test.py)
resulted in a pass for the knobs and a very small amount of noise on the
ain (0.000562). I believe for this issue to be resolved the ain should read
0.0 because nothing is connected it should not be providing a non-zero
value.
Kind Regards,
Nik
…On Tue, Aug 15, 2023 at 10:43 AM redoxcode ***@***.***> wrote:
Closed? As OP hasn't answered and #211 (comment)
<#211 (comment)>
is closed as well?
—
Reply to this email directly, view it on GitHub
<#209 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACKZSUMY5PO2LTJHBGR2TSDXVNACZANCNFSM6AAAAAATHASK2A>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Out of interest, what happens if you use the same precision for the calibration? i.e. change |
I've just run your noise script on an uncalibrated europi and got exactly 0.0 on ain, haven't yet tried with a calibrated one |
I calibrated using 4096 samples and ran the noise_test.py script again.
The results were interesting.... If I calibrate using 4096 samples I get
higher noise (0.03nnn). If I calibrate using 256 samples I get lower noise
(0.00002n).
I also did the test using different cases and I learned that the noise is
slightly different between cases... I therefore suspect that the noise in
my setup might be coming from the power rail, either from the power supply
or from other modules on the same rail....
Either way though.... my original suggestion was for the firmware to make
sure ain reads 0.0 even if the actual value reads as low as 0.00002), thus
eliminating any noise.
If this is not desired though, it is not a major problem. I will simply
continue to make sure that any scripts attempting to detect 0 on ain do
some rounding and the issue can be closed.
Kind Regards,
Nik
…On Mon, Aug 21, 2023 at 2:15 PM Rory Allen ***@***.***> wrote:
Out of interest, what happens if you use the same precision for the
calibration? i.e. change calibrate.py to use 4096 samples rather than 256
for each analogue input read. It is good that we're so so close to 0V, and
almost any use of ain will naturally round that down to 0 (6 decimal places
would let ain select between far more values than the specification of the
EuroPi states based on the bit depth of the ADC), so this small discrepancy
could just be down to using a lower number of samples when determining the
zero point
—
Reply to this email directly, view it on GitHub
<#209 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACKZSUITLOW27OKKKPO5BI3XWNNOZANCNFSM6AAAAAATHASK2A>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
That is interesting, it does lean towards some kind of spiked noise then rather than a consistent noise floor, and that would explain more samples having higher noise as it picks up more of the spikes. Either way, I think that this level of noise is acceptable as noise will be different in every system like you say, so any solution would be imperfect: if we find the average user noise at 256 samples and introduce firmware rounding to make sure that's zero, users with noisy cases will still experience noise at zero, and users with clean cases will have every |
With no realistic solution possible for this issue which doesn't sacrifice the experience of users with lower noise cases, and with the EuroPi-X development in progress which will fix these noise issues using higher quality ADCs and filtering, I'm going to mark this one closed unless any significant findings or solutions are found. |
Hardware Issue
Describe the bug
There is noise present when sampling the analogue inputs or knob values. This noise offsets the value read at the extremities of the readings, e.g 0 will never read 0 and the max value will never read the max value.
This issue causes the the percent() value to never read 100% on some modules. The issue also causes the analogue input to never read 0 Volts.
To Reproduce
Steps to reproduce the behavior:
Read any value from k1 or ain to more than 1 decimal place several times.
Expected behavior
It would be great if something like a deadzone was implemented. e.g. if really close to 0 the value returned is 0 or of close to the max the value returned is the max value.
The text was updated successfully, but these errors were encountered: