element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Cypress Kits
  • Products
  • Dev Tools
  • Cypress Kits
  • More
  • Cancel
Cypress Kits
Forum Measuring VDD (Battery Volts) in PSoC 4
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Cypress Kits to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 0 replies
  • Subscribers 23 subscribers
  • Views 2331 views
  • Users 0 members are here
Related

Measuring VDD (Battery Volts) in PSoC 4

cy.wbz
cy.wbz over 11 years ago

Hello!

I wanted to take a moment to cross post a blog article by one of our lead applications experts, Ganesh Raaja. We will continue to post Ganesh's blog posts to the community as they are written. The link to his post can be found here:


http://www.cypress.com/?rID=93033&cache=0


I have also posted his article in the text below.

 

I hope this example can help you in your design.

Best,

Matt

 

 

 

 

 

 

Measuring VDD (Battery Volts) in PSoC 4 – Author Ganesh Raaja


Usually in battery operated applications, the microcontroller also measures the level of the battery and either displays the percentage of the battery left or generates an alarm when the battery level is getting low.  There are two methods to measure battery voltage.


Method #1: In microcontrollers that have an internal ADC reference, the straightforward approach is to use a potential divider and scale down VDD to the ADC s measurement range.  For example, if the internal VREF of the ADC is 1.024V, and we need to measure VDD which can vary from 3.0V to 4.2V (this is the range of a Lithium Ion battery), the following circuit may be used.


image

 

In the above circuit, R1 and R2 form a potential divider and would develop 1.024V when VDD equals 4.43V.  So, for a 12 bit ADC, VDD may be measured by the following equation.

VDD = (4.43/4095) * ADC Counts


Method #2: In microcontrollers that do not have an internal ADC reference, but use VDD as the reference, we need an external reference to measure VDD.

 

image

 

In the above circuit, an external reference of 1.2V is connected to the ADC input.  As the reference of the ADC is VDD, the ADC counts for VDD would always be 4095 counts.  So, the ADC counts while measuring the external reference would be proportional to VDD.  For a 12 bit ADC, VDD can now be calculated using following formula.

VDD = (1.2V * 4095) / ADC Counts

Both the above methods have a disadvantage that they require external components. We can implement the same VDD measurement in PSoC4 without using any external components.  Let us see how.


PSoC4 Implementation


The diagram below shows the block diagram of the ADC inside PSoC4.


image

 

The input to the SAR ADC can be directly from the SARMUX in Port2 or from the AMUXBUS that can connect any pin to the ADC.  The SARREF block generates the reference to the ADC.  Below picture shows the SARREF block.

 

image

 

The reference to the ADC can be one of three voltages 1.024V, VDD or VDD/2. There is a bypass switch that brings out the output of the reference buffer to P1.7.  The intent of this bypass switch is to reduce noise on the VREF by connecting an external bypass capacitor.  We are going to use this bypass switch and Method #2 described earlier to measure VDD.


Following are the steps to measure VDD:


Connect an external bypass capacitor 1uF to P1[7].

Set the reference of ADC to VREF and enable the bypass switch.  Keep the bypass enabled for a short time, say 25ms. This charges the 1uF capacitor to 1.024V.

Disable the bypass switch. Now the capacitor holds the 1.024V (like a sample and hold circuit)

Change the reference of the ADC to VDD, connect P1[7] as input to the ADC and measure the voltage.

VDD can then be calculated using the formula:

VDD = (1.024 * 2047) / ADC Counts P1[7]

The SAR ADC in PSoC4 is 12 bits. Then why am I using 2047 and not 4095 in the above equation?  With the ADC configured for single ended measurement, the effective resolution of the ADC becomes 11 bits and hence the full scale count of 2047.


Let us now take a look at the project.  Figure below shows the schematic of the project.

 

image

 

Place an OpAmp configured as a buffer.  Place an analog input pin and connect this pin to the input of the buffer.  Assign P1[7] to this pin.  Place an ADC and configure the ADC for a reference of VDDA (we will dynamically change this in code).  Select the Single Ended Negative Input to VSSA.

 

image

 

Following firmware will now take care of the VDD measurement.  The result is availabe in the variable "Vdd" in millivolts.


void main()

{

int16 Vref;

int16 Vdd;

uint32 SARControlReg;

 

/* Start the LCD, OpAmp and ADC */

OpAmp_Buffer_Start();

ADC_Start();

 

for(;;)

{

/* Set the reference to VBG and enable reference bypass */

SARControlReg = CY_GET_REG32(CYREG_SAR_CTRL);

SARControlReg &= ~0x000000F0;

SARControlReg |= 0x000000C0;

CY_SET_REG32(CYREG_SAR_CTRL, SARControlReg);

 

/* 25ms delay for reference capacitor to charge */

CyDelay(25);

 

/* Set the reference to VDD and disable reference bypass */

SARControlReg = CY_GET_REG32(CYREG_SAR_CTRL);

SARControlReg &= ~0x000000F0;

SARControlReg |= 0x00000070;

CY_SET_REG32(CYREG_SAR_CTRL, SARControlReg);

 

/* Perform an ADC conversion */

ADC_StartConvert();

ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);

Vref = ADC_GetResult16(0x00);

 

/* Calculate Vdd */

Vdd = (1024*2047)/Vref;

}

}

Attachments:
images.zip
  • Sign in to reply
  • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube