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

PSoC™ 4

urchc_1533771
Level 5
5 likes given First like received First like given
Level 5

I need code to check battery. I opened "BLE_Battery_Level" example and run it. When I connected input to real pair of 1.5V batteries (2.56V)  it measure 0 voltage. Are this example is working ?

   

Where I can get real working example for check battery ?

0 Likes
1 Solution
rola_264706
Level 8
50 likes received 25 likes received 10 likes received
Level 8

The example should work but you have to remove ADC input  the from Vref to another GPIO pin then apply your batteries to it. I would add a resistor divider to insure you don't exceed the input max of 3.3 Volts.  Also this is a simulate battery reading example and at Main.c  at line 300 the simulated battery part of the code is called and the actual reading code is not called. I am sending you a 6 channel voltmeter program to see how to make a voltmeter. This code is made for a PSoC 4 CY8CKIT-049-42XX so you would need to modify it for the PSOC Ble.  But the ADC  code should work for you.

View solution in original post

0 Likes
26 Replies
rola_264706
Level 8
50 likes received 25 likes received 10 likes received
Level 8

The example should work but you have to remove ADC input  the from Vref to another GPIO pin then apply your batteries to it. I would add a resistor divider to insure you don't exceed the input max of 3.3 Volts.  Also this is a simulate battery reading example and at Main.c  at line 300 the simulated battery part of the code is called and the actual reading code is not called. I am sending you a 6 channel voltmeter program to see how to make a voltmeter. This code is made for a PSoC 4 CY8CKIT-049-42XX so you would need to modify it for the PSOC Ble.  But the ADC  code should work for you.

0 Likes
urchc_1533771
Level 5
5 likes given First like received First like given
Level 5

As I said before "I connected input to real pair of 1.5V batteries" to analog input and voltage was 2.56V ( no need insure resistor).

   

And you can see in main.c real MeasureBattery called too :

   

        if(CyBle_GetState() == CYBLE_STATE_CONNECTED)
        {
            /*******************************************************************
            *  Periodically simulate Battery level charging.
            *******************************************************************/        
            SimulateBattery();
            CyBle_ProcessEvents();

   

            MeasureBattery(); 

   

 

   

In this project exist 2 BAS. One for real measure ( if I connect to VREF it always 100 % ) and simulated (always less 20 %).

   

I used real and it`s not worked. Example you provided very complicated and based on specific hardware so I can`t even run it.

   

And I think that need correct Cypress example because other customers need it too.

0 Likes
rola_264706
Level 8
50 likes received 25 likes received 10 likes received
Level 8
        I gave you that code to show you how to interface to the ADC. What pin did you connect your batteries to? The way this is designed it reads Vref. Please post your code.   
0 Likes
urchc_1533771
Level 5
5 likes given First like received First like given
Level 5

Code exist in c:\Program Files (x86)\Cypress\PSoC Creator\3.3\PSoC Creator\examples\sampleprojects\BLE_Battery_Level\

   

I connected battery  to P3[0] as in example instead of Vref. If you have Pioner kit you can check it yourself.

0 Likes
rola_264706
Level 8
50 likes received 25 likes received 10 likes received
Level 8

Also what kind of batteries are you using?

0 Likes
rola_264706
Level 8
50 likes received 25 likes received 10 likes received
Level 8

You have to jumper pins on the Pioneer board to make this work check this in the instructions. 

   

0 Likes
urchc_1533771
Level 5
5 likes given First like received First like given
Level 5

I used Ni-MH . What a limits to battery exist ? Can you check how it work for you ?

0 Likes
urchc_1533771
Level 5
5 likes given First like received First like given
Level 5

OMG, I told that I made it. I jumper P3(0) to Vref and it display 100 % . Right now everything is OK.

   

After that I removed Vref and connected P3(0) to real battery and it`s not worked. 

rola_264706
Level 8
50 likes received 25 likes received 10 likes received
Level 8
        The 1.2 volt batteries? Two in series correct?   
0 Likes
urchc_1533771
Level 5
5 likes given First like received First like given
Level 5

Yes, Please take Kit and do it too.

0 Likes
rola_264706
Level 8
50 likes received 25 likes received 10 likes received
Level 8

Okay I have tried the program and the first thing I did was to leave the pin open and then it reads about 5% and the blue led is lit that means that the Battery level is less than 10%.  I then jumped the pin to the 3.3 volt pin on J1 on the Pioneer board.  Then it reads 100% and the blue led is not on. If you look at the program code in the bas.c  at lines 133-138 it says that the program is looking for 3V=100% and 2.8 V =29% and less than 2.0V 0%.  As you are using a 2.2V battery in series then your battery level would be 2.4 V max and that would be reading around 0% to 10 %.   The button cell is near discharged at less than 2.8V that is the way it was designed.  You can also look at the raw data with the Ble Dongle.

0 Likes
urchc_1533771
Level 5
5 likes given First like received First like given
Level 5

 I changed it to this :

   

#define MEASURE_BATTERY_MAX         (3000)      /* Use 3V as battery voltage starting */
#define MEASURE_BATTERY_MID         (2000)      /* Use 2.0V as a knee point of discharge curve @ 29% */
#define MEASURE_BATTERY_MID_PERCENT (50)        
#define MEASURE_BATTERY_MIN         (1000)     

   

When I connected battery with 2.8V it was 9% ?? As you explained it must be 70-80 % ...

   

Why you not connected to real battery ? 

0 Likes
rola_264706
Level 8
50 likes received 25 likes received 10 likes received
Level 8

I just needed a voltage supply so I used the one on the board.  I don't have your batteries so That is why I used it.  How are you connecting the battery to the circuit? Also if the battery is 2.2 Volts each  how are you getting 2.8 V?  Is the Blue led on?

0 Likes
urchc_1533771
Level 5
5 likes given First like received First like given
Level 5

One pic better thousand words... See in attachment

0 Likes
rola_264706
Level 8
50 likes received 25 likes received 10 likes received
Level 8
        Your connections are not correct you don't have gnd side of your batteries connected to the power connector J1 pin 2 or 3 marked ground. Look at the schematic for the Pioneer board. It looks like from picture you sent you are connecting the battery from Vref to P3.0 that is not correct.   
0 Likes
urchc_1533771
Level 5
5 likes given First like received First like given
Level 5

Don`t worry about GND . All gnd pins connected to same plain in layer 2 

   

believe me I know about it. 

   

0 Likes
rola_264706
Level 8
50 likes received 25 likes received 10 likes received
Level 8
        In order to read it correctly you have to have the negative side of your battery connected to the system ground and the positive to P3.0. Your connections in the picture are not that way.   
0 Likes
urchc_1533771
Level 5
5 likes given First like received First like given
Level 5

Ok , where is right pin ?

0 Likes
rola_264706
Level 8
50 likes received 25 likes received 10 likes received
Level 8

Okay you can also use J3-7 which is gnd.  Have you pressed the Read on the CySmart App? Also did you start with a Green led where it is looking for the CYSmart app.  Also you don't have a blue LED in the picture so you are not below 10%.Battery level. If you where using a 3 Volt battery it would be reading 100%. Please send your code so I can check it on my boards.

0 Likes
urchc_1533771
Level 5
5 likes given First like received First like given
Level 5

I told you before but again : this is not my code but standard example exist in c:\Program Files (x86)\Cypress\PSoC Creator\3.3\PSoC Creator\examples\sampleprojects\BLE_Battery_Level. 

   

If you don`t have it I attached it. And instead of  explain what I didn`t right just make yourself this example with real battery. I mean that less then 3V . In  datasheet I see :"The PSoC 4XX7_BLE device can be supplied from batteries with a voltage range of 1.9 V to 5.5 V".

   

So range of battery need be on minimum 2V. 

0 Likes
Bob_Marlowe
Level 10
50 questions asked 10 questions asked 1000 solutions authored
Level 10

"So range of battery need be on minimum 2V"

   

This is not what normally is done. A battery, rechargeable or not, can be destroyed when discharged too deep. A revert current flow (due to differences in the cell characterization) with one cell of a multi-cell battery as you have got might set the device on fire.

   

What is done in industry with battery design:

   

Dependent on the battery type used there is a correlation between Ubatt and charge level. In the above example, that correlation is expressed by a linear curve and a safe low discharge level is taken as the minimum. This will operate the battery cells in safe range, although it does not use the complete charge of the cells.

   

 

   

Bob

0 Likes
urchc_1533771
Level 5
5 likes given First like received First like given
Level 5

May be you forget that rechargeable batteries is not destroyed when it`s fully empty. BTW in cellular phone it`s recommendation on new batteries use it to empty for help to controller understand minimum.

   

Battery voltage ~ 1.2 -1.5 V  so if we limit to 2V for couple of batteries ( 1V to each) - it very far from full empty ...

0 Likes
rola_264706
Level 8
50 likes received 25 likes received 10 likes received
Level 8

I want you to send your program.  I have the example.

0 Likes
urchc_1533771
Level 5
5 likes given First like received First like given
Level 5

I think I found a problem. We can argue about values and percent but all decision made from measured voltage.

   

I added print value string : 

   

mvolts = (1024 * 2048) / adcResult;
         DBG_PRINTF("mvolts: %2ld \r\n",mvolts);

   

and received this values :

   

   

As you can see first I connected to VREF pin and we see 3.3V and 100% of battery but when I just unconnected pin we see that value about 1.3 V !  I see in ADC settings and it need measure from 0 to 3.3 V :

   

   

Something wrong with voltage measuring.

   

Can you provide some example of voltmeter with ADC on BLE chips.

   

 

   

   

0 Likes
rola_264706
Level 8
50 likes received 25 likes received 10 likes received
Level 8
        I sent that code to you in the Psoc 4 program 6 channel voltmeter. That code reads full range. All you have to do is copy it into your program and check it as you just did.   
0 Likes
rola_264706
Level 8
50 likes received 25 likes received 10 likes received
Level 8
        What does the adcResult read. That will show you what is being read by the Adc.   
0 Likes