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

Battery Voltage Calculation on pins Other than analog pins.

Hello

I am working on nrf52382,sdk11,softdevice 2.0.

/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-fd3fce63fa6d4ddfa73158194e4d87c3/battery_5F00_pins.pdf

/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-fd3fce63fa6d4ddfa73158194e4d87c3/battery_5F00_protection_5F00_circuit.pdf

/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-fd3fce63fa6d4ddfa73158194e4d87c3/battery_5F00_pins_5F00_connection.pdf

 

Schematics for connection of battery with a protection circuit are in these links, Not allowed to share whole Schematics.

Using  SAADC I tried to get battery voltage on BAT_MON_EN pin with Single Ended, 10-bit resolution, internal reference and gain 1/6, observe that a constant value 02DB(784) which according to calculation gives 3.0 v

Calculation : batt_voltage = saadc_reading/((1023*(1/6))/0.6)

With the same configuration on analogs free pins AIN0 and AIN1, I was getting 96,95 as saadc_reading.

I changed the configuration to  Differential Taking BAT_MON_EN pin as positive and BATTERY pin as negative I got the result like 400 around.

Please look at the battery schematics and explain how can I get readings out of it.Which pins I need to consider.

My code snippet:

void saadc_callback(nrf_drv_saadc_evt_t const * p_event{

    if (p_event->type == NRF_DRV_SAADC_EVT_DONE)

    {

        ret_code_t err_code;

        err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);

        APP_ERROR_CHECK(err_code);

       // printf("ADC event number: %d\r\n",(int)m_adc_evt_counter);

        for (int i = 0; i < SAMPLES_IN_BUFFER; i++)

        {

        test_c.number = p_event->data.done.p_buffer[i];

        string_send(test_c.ch,4);

            //printf("%d\r\n", p_event->data.done.p_buffer[i]);

        }

//        m_adc_evt_counter++;

nrf_drv_saadc_uninit();

        NRF_SAADC->INTENCLR = (SAADC_INTENCLR_END_Clear << SAADC_INTENCLR_END_Pos);

        NVIC_ClearPendingIRQ(SAADC_IRQn);

    }

}

void saadc_init(void){

    ret_code_t err_code;

    nrf_saadc_channel_config_t channel_config =

     NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(TX_PIN_NUMBER);

    err_code = nrf_drv_saadc_init(NULL, saadc_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],SAMPLES_IN_BUFFER);

    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1],SAMPLES_IN_BUFFER);

    APP_ERROR_CHECK(err_code);

}

Calling of these are done when ever required with 

saadc_init();

nrf_drv_saadc_sample();

Parents Reply Children
No Data
Related