This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SAADC Configuration

Hi All,

I am developing one project and there we are using ADC (i.e., SAADC in nRF). I have designed the hardware where I am using Capacitor ( C14, 2.2µF) which is connected to Analog pin and my requirement is I have to read the voltage level.

Here I am attaching details and image,

The voltage level of the input capacitor C14, 2.2µF / 400V to the Step-Down controller must be monitored. A voltage divider is used across the capacitor from R2, 3M3, and R3, 24k. The tapped voltage is measured at pin port P0.04 / AIN2 of the nRF52840. The expected voltage at the input of the controller is between 2.35V and 0V. The voltage at the capacitor must not fall below the value of 100V.

This is my requirement can anyone help how to configure SAADC with respect to my requirement.

Thanks in advance

Rohit R

Parents
  • Hello Rohit R,

    Have you seen the formulas for calculating SAADC input range in the SAADC documentation?

    The expected voltage at the input of the controller is between 2.35V and 0V.
    This is my requirement can anyone help how to configure SAADC with respect to my requirement.

    How is your nRF52840 supplies with power, are you using the coin cell battery, USB or external power?
    In the case of USB / 3 V power:
    If you would like your SAADC to have a the input range 0 - 2.35 V, you could either use reference VDD/4 and gain 1/3, which yields the input range 0 - 2.27 V, or you could use VDD/4 and gain 1/4 and get 0 - 3 V.
    Have you seen the SAADC Example from the SDK? It demonstrates how to setup and use the SAADC - then you could just input your own configuration, and you should start seeing your measurements.

    Please let me know if anything should be unclear with the forumlas, or how to go about doing the configuration.

    Best regards,
    Karl

  • Hi Karl,

    Yes, I have seen the document and SDK examples too.

    I am modifying SDK example as per my requirement, I have shared the changes in the previous post.

    How is your nRF52840 supplies with power, are you using the coin cell battery, USB or external power?
    In the case of USB / 3 V power:

    - It is basically a light Dimming control circuit we are using 230V and then using the voltage regulator and divider we are powering up MCU with 3.3V. If you make this ticket private then I can share the schematic file here as it confidential.

    If you would like your SAADC to have a the input range 0 - 2.35 V, you could either use reference VDD/4 and gain 1/3, which yields the input range 0 - 2.27 V, or you could use VDD/4 and gain 1/4 and get 0 - 3 V.

    - Okay, let me try this configuration related Gain and check the result.

    - One more question, I am using P0.04 / AIN2, with respect to SDK example as per my understanding AIN2 means the channel 2 and to configure this we need to call,

    nrf_saadc_channel_config_t channel_config =
            NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN2);  //single shot and channel config

    I am correct in configuring pin or did I miss something.

    Correct me If i am doing anything wrong.

    Thanks and Regards

    Rohit R

  • Hello Rohit,

    Rohit Rajapure said:
    sorry for the late response, I was not well so could not check any messages or notification.

    It is no problem at all, do not worry. I am glad to hear that you are back to health!

    Rohit Rajapure said:
    I tried, I am getting same result -3 and 1023. I think I am still making any mistake or i did not understand it clear.

    With the SAADC at 10-bit resolution, 1023 = VDD, and -3 = GND. I would at least expect the LSB to fluctuate on your measurements.

    Rohit Rajapure said:
    Is this correct or not? asap.

    Well, it is hard to say really - you have not told me what your goal is, so it is hard for me to confirm if this is the right approach.
    If you are trying to measure one VDD pin and one GND pin, then you are correct.

    I would also recommend that you make use of the nrfx_saadc driver rather than the legacy nrf_drv driver. Additionally, I would advise you to use the PPI peripheral to connect your SAMPLE_STARt task to a timer event ( like demonstrated in the SAADC example from the SDK ) rather than having a given delay and manually having the CPU start each conversion ( with the call to nrf_drv_saadc_sample. I would not recommend the current approach, as it uses excess CPU resources, and is generally inaccurate and not power optimized at all.
    On a general note, I would also mention that it is less-than-ideal for you to provide the code as you have done here. The large chunks of commented out code should not be included, because it takes the focus away from what you actually would like me to take a look at and provide feedback for.

    In conclusion, I would recommend that you revert to the general setup and approach of the SAADC example from the SDK ( which uses PPI ), instead of the implementation you have now. However, since I do not know exactly what you are trying to achieve, then the current approach that you have implemented might very well suit your purpose.

    If you would like to have the measurements displayed in millivolts ( mV ) instead of raw SAADC outputs then you need to convert them using the formula I referenced in my earlier comment. If you would like to see how battery measurement is implemented in another example, please have a look at the BLE Proximity Example from the SDK.

    Best regards,
    Karl

  • Hi Karl,

    Thanks for the feedback,

    I will note your suggestion and look into it.

    Also, I am sharing my end requirement and image below,

    The voltage level of the input capacitor C14, 2.2µF / 400V to the Step-Down controller must be monitored. A voltage divider is used across the capacitor from R2, 3M3, and R3, 24k. The tapped voltage is measured at pin port P0.04 / AIN2 of the nRF52840. The expected voltage at the input of the controller is between 2.35V and 0V. The voltage at the capacitor must not fall below the value of 100V.

    Capacitor ( C14, 2.2µF) which is connected to Analog pin and my requirement is I have to read the voltage level.

    I hope this helps you understand my requirement.

    Looking forward to your reply on this.

    Thanks and Regards

    Rohit R

  • Hello Rohit,

    Rohit Rajapure said:
    I will note your suggestion and look into it.

    Great! Please do not hesitate to let me know if anything should be unclear.

    Rohit Rajapure said:

    The voltage level of the input capacitor C14, 2.2µF / 400V to the Step-Down controller must be monitored. A voltage divider is used across the capacitor from R2, 3M3, and R3, 24k. The tapped voltage is measured at pin port P0.04 / AIN2 of the nRF52840. The expected voltage at the input of the controller is between 2.35V and 0V. The voltage at the capacitor must not fall below the value of 100V.

    Capacitor ( C14, 2.2µF) which is connected to Analog pin and my requirement is I have to read the voltage level.

    Yes, like mentioned in the original ticket, but what is your required resolution and sampling frequency?
    If you only need to know when the voltage crosses a certain threshold then you might want to look into using the SAADC limits feature. 

    Best regards,
    Karl

  • Hi Karl,

    As you suggested I tried configuring my custom requirement in SDK example.

    My configurations,

        nrf_saadc_channel_config_t channel_config =
            NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN2);  //singale shot and channel config 
            
       channel_config.gain = NRF_SAADC_GAIN1_4;
       channel_config.reference = NRF_SAADC_REFERENCE_VDD4;
       channel_config.mode = NRF_SAADC_MODE_SINGLE_ENDED;
       channel_config.pin_n = NRF_SAADC_INPUT_DISABLED; 
       channel_config.pin_p = NRF_SAADC_INPUT_AIN2;
       channel_config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;
       channel_config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;

    After making changes in SDK example with the above configuration. When I followed the testing steps suggested for SDK example by Connecting pin to VDD and GND, I am still getting 10bit raw value. But I have configured for 12bit.

    Once I get exact raw values then I can apply voltage converter calculation as mentioned by you in the previous post.

    And one more thing I would like share is, my end device is Zigbee based Dimming control hardware. The selection of intensity levels is depended on the ADC values of the capacitor. More details you check mine below ticket where I have shared my schematic and details. This hardware is basically powered by 230V then using internal voltage converter we make 3V to power up nRF MCU.

    Please go through schematic also and let me know if I am making any mistakes in configuring SAADC.

    ticket link - https://devzone.nordicsemi.com/support/255201

    Thanks in advance

    Rohit R

  • Hello Rohit R,

    Rohit Rajapure said:
    My configurations,

    This is fine, with your code, you configure AIN2 channel to have 1/4 gain, VDD/4 reference and 10 us TAQ.
    Be advised that the NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE is a macro for setting up the default channel configurations. You may then change those that you do not want to be default. In your case, you are changing some things to the value that they already hold, which is why I am mentioning this.

    Rohit Rajapure said:
    After making changes in SDK example with the above configuration. When I followed the testing steps suggested for SDK example by Connecting pin to VDD and GND, I am still getting 10bit raw value. But I have configured for 12bit.

     The SAADC example is using 10 bit resolution as default. Could you show me where you have changed this to 12 bit? Also, this is not done as part of the channel configuration, but rather as part of the SAADC configuration.

    Rohit Rajapure said:
    Once I get exact raw values then I can apply voltage converter calculation as mentioned by you in the previous post.

    Yes, lets ensure that you are getting the correct raw SAADC output values first. This is a good approach.

    Rohit Rajapure said:
    Please go through schematic also and let me know if I am making any mistakes in configuring SAADC.

    What specifically would you like me to take a look at in your schematics / in your other ticket?
    It seems to me that you are getting good help by my colleague Jørgen in the other ticket.

    As for the SAADC configuration, you still have not told me what your required resolution for the project is, and what your intended sampling frequency is.

    Best regards,
    Karl

Reply
  • Hello Rohit R,

    Rohit Rajapure said:
    My configurations,

    This is fine, with your code, you configure AIN2 channel to have 1/4 gain, VDD/4 reference and 10 us TAQ.
    Be advised that the NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE is a macro for setting up the default channel configurations. You may then change those that you do not want to be default. In your case, you are changing some things to the value that they already hold, which is why I am mentioning this.

    Rohit Rajapure said:
    After making changes in SDK example with the above configuration. When I followed the testing steps suggested for SDK example by Connecting pin to VDD and GND, I am still getting 10bit raw value. But I have configured for 12bit.

     The SAADC example is using 10 bit resolution as default. Could you show me where you have changed this to 12 bit? Also, this is not done as part of the channel configuration, but rather as part of the SAADC configuration.

    Rohit Rajapure said:
    Once I get exact raw values then I can apply voltage converter calculation as mentioned by you in the previous post.

    Yes, lets ensure that you are getting the correct raw SAADC output values first. This is a good approach.

    Rohit Rajapure said:
    Please go through schematic also and let me know if I am making any mistakes in configuring SAADC.

    What specifically would you like me to take a look at in your schematics / in your other ticket?
    It seems to me that you are getting good help by my colleague Jørgen in the other ticket.

    As for the SAADC configuration, you still have not told me what your required resolution for the project is, and what your intended sampling frequency is.

    Best regards,
    Karl

Children
  • Hi,

    Be advised that the NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE is a macro for setting up the default channel configurations. You may then change those that you do not want to be default. In your case, you are changing some things to the value that they already hold, which is why I am mentioning this.

    - I did configuration as below,

      nrf_saadc_channel_config_t channel_config;     
       channel_config.gain = NRF_SAADC_GAIN1_4;
       channel_config.reference = NRF_SAADC_REFERENCE_VDD4;
       channel_config.mode = NRF_SAADC_MODE_SINGLE_ENDED;
       channel_config.pin_n = NRF_SAADC_INPUT_DISABLED; 
       channel_config.pin_p = NRF_SAADC_INPUT_AIN2;
       channel_config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;
       channel_config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;
    

     The SAADC example is using 10 bit resolution as default. Could you show me where you have changed this to 12 bit? Also, this is not done as part of the channel configuration, but rather as part of the SAADC configuration.

    - I set resolution here and in sdk_config.h file to

        nrf_drv_saadc_config_t saadc_config;
        saadc_config.resolution = NRF_SAADC_RESOLUTION_12BIT;   //12 bit resolution

    // <0=> 8 bit 
    // <1=> 10 bit 
    // <2=> 12 bit 
    // <3=> 14 bit 
    
    #ifndef NRFX_SAADC_CONFIG_RESOLUTION
    #define NRFX_SAADC_CONFIG_RESOLUTION 2
    #endif
    

    What specifically would you like me to take a look at in your schematics / in your other ticket?
    It seems to me that you are getting good help by my colleague Jørgen in the other ticket.

    - In the previous post, you had asked for the powering procedure of the device. So I shared this ticket and asked to go through the schematic more clear picture about powering MCU and ADC input pin related details.

    As for the SAADC configuration, you still have not told me what your required resolution for the project is, and what your intended sampling frequency is.

    - What I was informed is by a customer about capacitor voltage should be as below,

    "a voltage of capacitor<100V  (This corresponds to a voltage of 0.72V on

      Analog input of the nRF528)"

    - So I need an 8bit resolution sufficient for me but I was trying with 12bit and sampling frequency 50Hz.

    - In both 8bit and 12bit resolution also I am getting 10bit values 1023 when connecting to VDD.

    Please correct If am doing wrong, As my capacitor pin is connected to AIN2/P0_4 so I have to short P0_4 to VDD/GND to check values correct?

    As mentioned above snippet, I set the resolution as 12bit in both files still I am getting 1023 raw values when I connect to VDD.

    Can you let me know your views on this?

    Thanks and Regards

    Rohit R

  • Hi Karl,

    It's my fault. I have resolved the resolution issue.

    I am getting 8bit raw values and able to print on putty.

    Now, my next step is to convert  into voltage range.

        err_code = nrf_drv_saadc_init(&saadc_config, saadc_callback);
        APP_ERROR_CHECK(err_code);

    - I have forgot to call saadc_config parameter in init function. I kept it NULL.

    it's my fault.

    Thanks and Regards

    Rohit R

  • Hello Rohit,

    Rohit Rajapure said:
    I have resolved the resolution issue.

    I am happy to hear that you were able to resolve your issue!

    Rohit Rajapure said:
    I am getting 8bit raw values and able to print on putty.

    As I had understood it, you needed 12 bit resolution. Are you able to reconfigure to 12 bit resolution now?

    Rohit Rajapure said:
    - I have forgot to call saadc_config parameter in init function. I kept it NULL.

    I see. To avoid this in the future, I would advise that you remove obsolete code from your project instead of commenting it out - this increases readability tenfold.
    If you are worried that you will need the commented out code later, place it in a temporary work file.

    Please do not hesitate to open a new ticket if you should encounter any other issues or questions in the future.

    Good luck with your development!

    Best regards,
    Karl

  • Hi Karl,

    Yes, I am able to read all resolution values.

    8bit resolution is sufficient for me so I am going ahead with an 8bit resolution.

    Thank you so much for your constant help.

    Thanks and Regards

    Rohit R

  • Hello Rohit,

    Rohit Rajapure said:
    Yes, I am able to read all resolution values.

    Great, I am glad to hear that! 

    Rohit Rajapure said:
    8bit resolution is sufficient for me so I am going ahead with an 8bit resolution.

    All right, that is great! Please keep in mind that you might loose some LSB to noise in your measurements.
    So, if you need 8 NOEB, then I would suggest that you use 10 bit resolution.

    Rohit Rajapure said:
    Thank you so much for your constant help.

    It is no problem at all, I am happy to help!

    Please do not hesitate to open a new ticket if you should encounter any issues or questions in the future.

    Good luck with your development!

    Best regards,
    Karl

Related