This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Sensing 12V battery voltage

Hello,

I am using nrf51822 SDK11 S130. I am using my custom design board which is powered by 12V. The nrf51822 is provided with 3.3V. I used 27k and 9.53K resistors in potential divider configuration and the node voltage between potential divider is provided to AIN6, so the range of voltage is from 0-3.13V for 0-12V.

Below is the code snippet:

void my_analogin_init(void)
{
    NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
    NRF_ADC->CONFIG = (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos) |
                      (ADC_CONFIG_INPSEL_AnalogInputNoPrescaling << ADC_CONFIG_INPSEL_Pos) |
                      (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) |
                      (ADC_CONFIG_PSEL_AnalogInput6  << ADC_CONFIG_PSEL_Pos) |
                      (ADC_CONFIG_EXTREFSEL_AnalogReference1 << ADC_CONFIG_EXTREFSEL_Pos);
}
 
uint16_t my_analogin_read_u16(void)
{
    NRF_ADC->CONFIG     &= ~ADC_CONFIG_PSEL_Msk;
    NRF_ADC->CONFIG     |= ADC_CONFIG_PSEL_AnalogInput6 << ADC_CONFIG_PSEL_Pos;
    NRF_ADC->TASKS_START = 1;
    while (((NRF_ADC->BUSY & ADC_BUSY_BUSY_Msk) >> ADC_BUSY_BUSY_Pos) == ADC_BUSY_BUSY_Busy) {};
    return (uint16_t)NRF_ADC->RESULT; // 10 bit
}

Queries: What should reference voltage to measure battery voltage? I connected an external reference voltage on pin AIN7/AREF1 which is 3.3V. Is it correct?

When I use VBG as reference voltage with input from analogpin6, the nrf51822 reads Vcc. For example when battery is 12V-4V, the Vcc to nrf51822 is 3.3V, so nrf51822 reads 3.3V. When the battery voltage drops below 3.3V say 2.5V, the nrf51822 reads the 2.5V voltage which corresponding to battery voltage. How can I measure the voltage range from 12V-4V?

reference :devzone.nordicsemi.com/.../ devzone.nordicsemi.com/.../09f26967213e15129f3c423cc1995ab8

Awaiting for your reply.

  • With 27k - 9.53k divider: Vain6 = 3.131V @12V. Using internal VBG 1.2V together with 1/3 prescaler should work (1.044V max at ADC input/range 0 .. 1.2V):image description

    3.3V AREF1 is out of spec.

  • Thanks alot testy :) It worked well.

    This is code snippet: void my_analogin_init(void) { NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled; NRF_ADC->CONFIG = (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos) | (ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) | (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) | (ADC_CONFIG_PSEL_AnalogInput6 << ADC_CONFIG_PSEL_Pos) | (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos); }

    uint16_t my_analogin_read_u16(void) { NRF_ADC->CONFIG &= ~ADC_CONFIG_PSEL_Msk; NRF_ADC->CONFIG |= ADC_CONFIG_PSEL_AnalogInput6 << ADC_CONFIG_PSEL_Pos; NRF_ADC->TASKS_START = 1; while (((NRF_ADC->BUSY & ADC_BUSY_BUSY_Msk) >> ADC_BUSY_BUSY_Pos) == ADC_BUSY_BUSY_Busy) {}; return (uint16_t)NRF_ADC->RESULT; // 10 bit }

Related