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

Battery level detect in nRF52832

Hi,

Does nRF52832 use normal ADC input to detect battery level (ex. AIN0, AIN1...)? or nRF52832 have other method to do this job?

Thank you,

Chianglin

Parents Reply Children
  • Hi,

    Please refer to the Proximity Application example in SDK 15.3. There you can see how the SAADC driver is configured for VDD measurement in line 283-297 of  <SDK15.3>\examples\ble_peripheral\ble_app_proximity\main.c. You can refer to the other ADC related code in the file to see a complete example of battery measurement (and even how to use the standard Bluetooth battery service if that is relevant).

  • Hi,

    Thank you for your explain.

    VDD is define in "H7" and "A7" pin of nRF52832, it is used as power input of MCU. Does it also can detect battery level?

    Thank you,

  • chianglin said:
    VDD is define in "H7" and "A7" pin of nRF52832, it is used as power input of MCU. Does it also can detect battery level?

    Yes, but only if you have connected VDD directly to the battery, as mentionned in my initial reply.

  • Hi,

    If I want to use two ADC at the same time, one for "ADC Sensor input", and the other one for "Battery level detect".  How can I modify following source code?

    void saadc_init(void)
    {
        ret_code_t err_code;
    
    	// ---------- Initialize ADC for Pressure-Sensor ----------------
    	// 變更 ADC 的 bit 數
    	nrf_drv_saadc_config_t saadc_config = NRF_DRV_SAADC_DEFAULT_CONFIG;
    	saadc_config.resolution = NRF_SAADC_RESOLUTION_12BIT;
    
        nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);
        // 變更 ADC 倍率 & 參考電壓
    	channel_config.gain = NRF_SAADC_GAIN1_4;
    	channel_config.reference = NRF_SAADC_REFERENCE_VDD4;
    
    	err_code = nrf_drv_saadc_init(&saadc_config, saadc_Sensor_callback);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_saadc_channel_init(0, &channel_config);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0], SAADC_SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1], SAADC_SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
    
    	// ---------- Initialize ADC for Battery detect ----------------
    #if 1
        err_code = nrf_drv_saadc_init(NULL, saadc_Battery_event_handler);
        APP_ERROR_CHECK(err_code);
    
        nrf_saadc_channel_config_t config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_VDD);
        err_code = nrf_drv_saadc_channel_init(0, &config);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_saadc_buffer_convert(m_battery_adc_buf[0], SAADC_SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_saadc_buffer_convert(m_battery_adc_buf[1], SAADC_SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
    #endif
    }

    System will crash when "second nrf_drv_saadc_init() execute".

    Thank you

  • Hi,

    chianglin said:
    System will crash when "second nrf_drv_saadc_init() execute".

    That is expected. You should only initialize the driver once unless you disable it in between (for instance to save power). So you should remove the second call to nrf_drv_saadc_init(), and use a common event handler for both. If you sample either one or the other, you will know which it is based on what you just sampled. If you sample both at the same time, you will know based on the order. (sampling both at the same time may not be that useful since you probably don't need battery information as often as you need sensor input).

    chianglin said:
    If I want to use two ADC at the same time, one for "ADC Sensor input", and the other one for "Battery level detect".  How can I modify following source code?

    To sample both channels in consecutive order, just enable the second channel as well, and make sure the result buffer is a multiple of the number of channels. If you want to sample either one or the other, and both at a low rate, then it is most power-efficient to configure sampling of the first channel (sensor), do that, and then uninitialized the SAADC. Then do the same when it is time to sample the other channel (VDD).

Related