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

I want to measurement Battery level.

(I use nrf51822)

I use two 3V batteries in series.

Therefore Input Voltage of My Circuit is 6V.

My own source was coded as a collection of information.

Oh, by the way, I used a battery is Cr2032 Coin Cell.

Looking for information on a coin cell is found in the link below.

Coin Cell Link

Is there anything wrong with my source?

Um, but uses a lot of battery, the battery is still in 100% condition.

What mistakes did I do?

I need help. please!


  /**< Reference voltage (in milli volts) used by ADC while doing conversion. */

  #define ADC_REF_VOLTAGE_IN_MILLIVOLTS        1200                    
  
  /**< The ADC is configured to use VDD with 1/3 prescaling as input. And hence the result of                       
        conversion is to be multiplied by 3 to get the actual value of the battery voltage.*/
                                
   #define ADC_PRE_SCALING_COMPENSATION         3                                          
  
  /**< Typical forward voltage drop of the diode (Part no: SD103ATW-7-F) that is connected in 
         series with the voltage supply. This is the voltage drop when the forward current is 1mA. 
         Source: Data sheet of 'SURFACE MOUNT SCHOTTKY BARRIER DIODE ARRAY' available at 
         www.diodes.com. */

  #define DIODE_FWD_VOLT_DROP_MILLIVOLTS       270                                        
  #define ADC_RESULT_IN_MILLI_VOLTS(ADC_VALUE)\
        ((((ADC_VALUE) * ADC_REF_VOLTAGE_IN_MILLIVOLTS) / 255) * ADC_PRE_SCALING_COMPENSATION)



static void adc_init(void)
{	
	
	/* Enable interrupt on ADC sample ready event*/		
	NRF_ADC->INTENSET = ADC_INTENSET_END_Msk;   
	sd_nvic_SetPriority(ADC_IRQn, NRF_APP_PRIORITY_LOW);  
	sd_nvic_EnableIRQ(ADC_IRQn);
	
	NRF_ADC->CONFIG	= (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos) /* Bits 17..16 : ADC external reference pin selection. */
									| (ADC_CONFIG_PSEL_Disabled << ADC_CONFIG_PSEL_Pos)					/*!< Use analog input 2 as analog input. */
									| (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos)							/*!< Use internal 1.2V bandgap voltage as reference for conversion. */
									| (ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) /*!< Analog input specified by PSEL with no prescaling used as input for the conversion. */
									| (ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos);									/*!< 8bit ADC resolution. */ 
	
	/* Enable ADC*/
	NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
	
}


void ADC_IRQHandler(void)
{

    uint8_t     adc_result;
    uint16_t    batt_lvl_in_milli_volts;
    int percent;
	
	/* Clear dataready event */
    NRF_ADC->EVENTS_END = 0;	
  
	adc_result = (NRF_ADC->RESULT);
    batt_lvl_in_milli_volts  = ADC_RESULT_IN_MILLI_VOLTS(adc_result);
	percent = battery_level_in_percent(batt_lvl_in_milli_volts);
    NRF_ADC->TASKS_STOP = 1;
	
	//Release the external crystal
	sd_clock_hfclk_release();
}	

#Edit : 2015-04-13

Current connection status is shown in the figure below.

connection status

The battery is connected exactly as shown.

Without resistance, without capacitor

What is wrong with this approach?

Parents Reply Children
No Data
Related