-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Implement analogReadResolution #39
Conversation
I'd rather "remap" the value obtained via zephyr API to Arduino range (something like this 96ad455#diff-0f72c528133d0264d72e0dc51520d88b17cf1c6b548d08f661591ba87dc53cb9R301-R326 ) . |
Can do it either way. I see pros/cons on both approaches. The way I did it, could do as you mentioned, maybe give a runtime error. I am assuming that the hardware driver won't simply The approach you mention, using either a map function or scaling like:
With current setup on GIGA, I believe the hardware was initialized to 12 bits and Arduino default is 10 bits. Now we probably can change the device tree to always ask for 16 bits. But my guess is, that will cause all I am only guessing here as I have not done that much analog stuff on STM and other boards. Other than we did let me know the way you wish to go. |
I'd go for this route; in case the user want to go faster using a lower resolution they can write another lib based on the underlying zephyr code (the difference should be unnoticeable unless you do very fast acquisition as in https://github.com/arduino-libraries/Arduino_AdvancedAnalog ) |
c26ac3c
to
26e0823
Compare
I updated the code along the line you mentioned, I only updated the GIGA overlay so far. Thought about doing Portenta |
88b7ab2
to
8064e6a
Compare
I refactored the commits a bit to keep the history clean, will merge as soon as the CI turns green 🙂 |
resolves #36
The current released version was always reading with 12 bits of resolution. The Arduino analogRead web page said that by default it should default to 10 bits.
The updated code is now ignoring the arduino_adc[idx].resolution field as this is setup for 12 and you can not change it run time.
Like the MBED version, this version is using the static variable read_resolution to hold the current resolution. Which we then pass through to zephyr when we do the reads.
I also changed the parameter buf that we pass through to zephyr from in16_t to uint16_t as if you choose resolution of 16 bits it was returning negative values.