PSoC 5 Battery Measurements

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello.

   

In the  past, I've used the PSoC 4 BLE battery measure example to make battery measurements on a device.

   

 

   

I am now trying to do the same for a new project, using the PSoC 5lp.

   

However, since there is no example, I am struggling to all of the necessary features.

   

 

   

First off, the PSoC 4 has an external pin labeled VREF that is used for this.  Would one of the VCCD pins be the PSoC 5 equivalent?

   

 

   

2ndly, there is a visible change in the macros for the PSoC 4 SAR ADC and the PSoC 5 SAR adc. 

   

I am struggeling to convert the following macros:

   

ADC_VREF_INTERNAL1024BYPASSED

   

ADC_VREF_VDDA

   

 

   

The macros and control registers seem to be different between the PSoC 4 and PSoC 5, which makes sense, I'm just struggeling to conver them.

   

Any help or advice is appreciated.

   

 

   

The following is the entire code piece I am trying to convert:

   

/* Set the reference to VBG and enable reference bypass */
        sarControlReg = ADC_SAR_CTRL_REG & ~ADC_VREF_MASK;
        ADC_SAR_CTRL_REG = sarControlReg | ADC_VREF_INTERNAL1024BYPASSED;

   

        /* 25 ms delay for reference capacitor to charge */
        CyDelay(25);
        
        /* Set the reference to VDD and disable reference bypass */
        sarControlReg = ADC_SAR_CTRL_REG & ~ADC_VREF_MASK;
        ADC_SAR_CTRL_REG = sarControlReg | ADC_VREF_VDDA;

   

        /* Perform a measurement. Store this value in Vref. */
        CyDelay(1);
        ADC_StartConvert();
        ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);

   

        adcResult = ADC_GetResult16();
        /* Calculate input voltage by using ratio of ADC counts from reference
        *  and ADC Full Scale counts.
        */
        mvolts = (1.024 * 2048) / adcResult;

0 Likes
3 Replies
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is a program that measures up to 6 volts. It could be modified to measure higher voltages with resistor dividers.

0 Likes
Anonymous
Not applicable

Is the ADC_DelSig_1_CountsTo_mVolts()   actually trusted to be relatively accurate,  assuming the VCC decreases as a battery drains?

   

 

   

Thanks for the advice.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

It all depends on your selected reference voltage. Most precise would be an internal ref (buffered). Might require do divide with R/R network the battery voltage. Have a look into the specs of the ADC, the accuracy is defined over the whole voltage range.

   

 

   

Bob

0 Likes