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

Check nRF52 ADC VREF #13

Closed
9 tasks done
microbuilder opened this issue Feb 8, 2017 · 5 comments
Closed
9 tasks done

Check nRF52 ADC VREF #13

microbuilder opened this issue Feb 8, 2017 · 5 comments

Comments

@microbuilder
Copy link
Contributor

microbuilder commented Feb 8, 2017

The nRF52 ADC can be configured to use an internal +/-0.6V ref or external VDD: http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fsaadc.html&cp=2_2_0_36_7&anchor=concept_kxz_4pp_qr

Make sure we can easily switch between references with the ADC code on the Arduino side, and check that the change actually works.

  • Add a reasonably complete ADC example sketch where the user case set:
    • ADC Resolution (via analogReadResolution(14))
    • ADC reference (via analogReference)
  • Add a helper function to wiring_analog_nRF52.c to set the Gain???
  • Add a helper function to wiring_analog_nRF52.c to set the acquisition time?

Also ... set the default ADC parameters to the following:

  • Internal Reference (+/-0.6V)
  • Default gain 1/6 (0..3.6V range)
  • 10-bit output
  • 3us acquisition time

Current defaults aren't useful since the gain is hard coded to '1':

NRF_SAADC->CH[0].CONFIG = ((SAADC_CH_CONFIG_RESP_Bypass   << SAADC_CH_CONFIG_RESP_Pos)   & SAADC_CH_CONFIG_RESP_Msk)
                            | ((SAADC_CH_CONFIG_RESP_Bypass   << SAADC_CH_CONFIG_RESN_Pos)   & SAADC_CH_CONFIG_RESN_Msk)
                            | ((SAADC_CH_CONFIG_GAIN_Gain1    << SAADC_CH_CONFIG_GAIN_Pos)   & SAADC_CH_CONFIG_GAIN_Msk)
                            | ((saadcReference                << SAADC_CH_CONFIG_REFSEL_Pos) & SAADC_CH_CONFIG_REFSEL_Msk)
                            | ((SAADC_CH_CONFIG_TACQ_3us      << SAADC_CH_CONFIG_TACQ_Pos)   & SAADC_CH_CONFIG_TACQ_Msk)
                            | ((SAADC_CH_CONFIG_MODE_SE       << SAADC_CH_CONFIG_MODE_Pos)   & SAADC_CH_CONFIG_MODE_Msk);

See also #14

@microbuilder
Copy link
Contributor Author

Defaults updates via a9e0508

@hathach
Copy link
Member

hathach commented Feb 13, 2017

I don't know much about these analog stuffs, there is also a commit from sandeep repo for this matter sandeepmistry/arduino-nRF5@c98a190

and I made a merge update from original repo df80f2e

Please revise to make sure I does not make any stupid mistakes :)

@microbuilder
Copy link
Contributor Author

I've already fixed this, but thanks for the reference to Sandeep's changed. I might change my own code to stay compatible with that.

@microbuilder
Copy link
Contributor Author

Don't worry about the helper for the VBAT either, I'll take care of that.

@microbuilder
Copy link
Contributor Author

Fixed this with c834c6b and also set the default to 1/6 and internal which is what we'll use as a default, but this keeps it mostly consistent with Sandeep's code as well.

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

No branches or pull requests

2 participants