cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

Anonymous
Not applicable

I have a custom board with a CYBLE-22410-00 .powered by the cr2032 battery

Could you please help with the following

1. I copied the ADC SAR  component from the BLE_Battery_Level01 project  (attached) into my project  but don't know how to connect the  J3 pin VREF. The  the project doc  says "The Vref analog input pin is locked to P3[0] and "Connect J2 pin P3[0] to J3 pin VREF" - but it has to be project specific

2. What modifications (if any) are required in the sample code to make it work on  CYBLE-22411-00 ? I' m  referring to the MeasureBattery() function and the defines it uses ,i.e ADC_VREF_INTERNAL1024BYPASSED,ADC_SAR_CTRL_REG , etc

3. The comment in the MeasureBattery function says that it converts the battery level voltage to percentage using values specific to the CR2033 battery. I could not find that info for the CR2032 .Any ideas where to find it? Or do these values apply to CR2032 as well?

Thanks

Andy

0 Likes
1 Solution
Roy_Liu
Moderator
Moderator

1. You are right, it should be project/board specific, you can assign that pin properly based on your hardware, the desciption in the project doc is based on the PSoC4 BLE kit.

2. You may just directly use it with CYBLE-22411-00, I remember the ADC of the two chips(the one used in the original project and the CYBLE-22411-00) is same.

3.  I think these values apply to CR2032.

Roy Liu

View solution in original post

0 Likes
30 Replies
Roy_Liu
Moderator
Moderator

1. You are right, it should be project/board specific, you can assign that pin properly based on your hardware, the desciption in the project doc is based on the PSoC4 BLE kit.

2. You may just directly use it with CYBLE-22411-00, I remember the ADC of the two chips(the one used in the original project and the CYBLE-22411-00) is same.

3.  I think these values apply to CR2032.

Roy Liu

View solution in original post

0 Likes
Anonymous
Not applicable

3. The "percent battery charge" is based on the expected SoC for each voltage level for the CR2033 lithium battery. Unless it has different voltage ratings (I can't find the datasheet for the CR2033), then similar voltage and type of battery with only a small difference in the amount of total charge it stores should have a similar SoC to voltage correlation, which means that it should work. Basically, the percentage battery life is estimated from the voltage for the type of battery, and similar batteries will have a similar estimation.

Anonymous
Not applicable

Where can I find information what pin to use? I could not find it in the CYBLE-224110-00 data sheet

Thanks

0 Likes
Anonymous
Not applicable

The Pin P3[0] looks fine when I build your project; Are you expecting a certain pin for use by the ADC to get the Vref?

The example project shows an external Capacitor wired to the Vref pin. If you are wanting to measure the battery voltage without external components, then see here: http://www.cypress.com/blog/psoc-hacker-blog/measuring-vdd-battery-volts-psoc4

(If you directly reference the Vref, then on a comparison between battery voltage and the Vref, it will almost always come back with 100/100%)

0 Likes
Anonymous
Not applicable

I'm a bit confused with the terminology. By "external" do you mean a physical part that has to be connected to the PSoC ? Or is it a logical component? I started reading the article you mentioned and the same question applies. Thank you

0 Likes
Anonymous
Not applicable

When documentation for the PSoC chips uses "external" they generally mean a part or component that is NOT inside of the CYBLE module, or whatever chip you are using, and thus it would be a component that you need to wire to the pins on the cypress module using one of the IO pins, PCB traces, jumper wires, etc.

When they refer to "internal" they are generally referring to something already included, and within the cypress module/chip.

For example, the ADC itself is internal to the cypress module, but the pin it reads from can be external.

In the top design schematics on PSoC schematics, the blue "penned" looking wires, resistors, capacitors, etc. all refer to documentation on externally wired components for the project. Thus, the article referenced is using an external resistor divider bridge to read the ADC values from. That means, that you would need to dedicate a pin for the use of measuring battery voltage level.

Tl;Dr; Yes, external means a physical part that needs to be connected/wired to the PSoC.

0 Likes
Anonymous
Not applicable

Thank you for clarifying, this is very helpful. I'm looking for a solution that does not require any external parts. Is there such a solution?

0 Likes
Anonymous
Not applicable

Not as far as I know, but someone else would probably know better.

Support for an internal VDD battery measurement with the ADC would require a different chip, or manufacturing changes afaik.

Sorry, but good luck

0 Likes
Anonymous
Not applicable

Even more confused.

The article Measuring VDD (Battery Volts) in PSoC4 | Cypress Semiconductor

says

"We can implement the same VDD measurement in PSoC4 without using any external components.  Let us see how.

Note: The resistor and zener combination in the schematic above is just a representation of an external reference voltage."

This implies that no external parts are needed and everything can be set up in PSoC Creator

But then it says

"Following are the steps to measure VDD:

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

Which implies that an external part IS needed.

Could you please clarify?

Thanks

0 Likes
Anonymous
Not applicable

Yeah, hence why I was thinking there is not a good way to measure it without external components. It could be that he is using the OpAmp buffer as replacement for the capacitor to hold the reference voltage for measuring, but without running it, I would not be confident in that. He also still refers to the P1[7] pin in his firmware code below it, so either that pin is used to get the internal reference voltage of 1.024 volts, or he really is using the external capacitor. 😕

I would recommend testing with the OpAmp buffer to see if it replaces the capacitor behavior, but otherwise I don't know

0 Likes
Anonymous
Not applicable

The article is very confusing. In one sentence it says that on MCU's with internal ADC the measurement can be done without any external components , in the other says that it is required.

Can  anyone clarify?

If an external bypass cap is indeed required on CYBLE 224110 , what pin should it be wired to ? There is no P1.7 that the article refers to on the 224110

Thanks

0 Likes
Anonymous
Not applicable

Personally, we used the resistor divider to get the battery voltage reference, and compared it with the internal 1.024V reference on the ADC to get our own battery reading, but that is using external components...

0 Likes
Anonymous
Not applicable

If using external components is a requirement that's ok. But it 's still unclear to me which pin of the CYBLE the external component should be wired to. I don't see P1.7 mentioned in the article in the  CYBLE-22110-00 project "Pins" section

Thanks

0 Likes
Anonymous
Not applicable

I think the intent of the article, is to use the OpAmp to buffer the battery voltage as an "internal capacitor", and then to switch the ADC to use the internal 1.024V reference to calculate the voltage from the OpAmp "capacitor" for measuring the battery voltage. I'm not seeing the P1[1] for the CYBLE-224110-00 device either, but it could be the exact pin doesn't matter?

I tried to mimic/build the project in the article to help you out, but I don't have the board with me to test if it works.

I think, using the internal OpAmp allows you to not need to use an external component; The pin that the board uses for the voltage reference buffering will be in use however.

0 Likes
Anonymous
Not applicable

Some progress!

I modified your project to use 224110 CYBLE board and connected the vref pin to P2[5]

Now I'm getting non zero readings

BUT

The readings are way lower than the actual battery voltage as measured by the multimeter

I tried 2 batteries: one that measures 3.0 and another that measures around 2.934

I also incorporated the code from the battery measurement project mentioned elswhere in the forums,and values are  nowhere near the actual voltage measured by the multimeter.

The values I am getting

From your function which in my code is called MeasureBattery2:

Vdd = 1031,1364,1891,1039,1024,1855

From the function that I found somewhere else on Cypress forums called MeasureBattery()

mvolts = 1899,1909,1911,1911,1913,1913

Any ideas?

Which me

See attached project.

0 Likes
Anonymous
Not applicable

If you have the capability, wiring the battery voltage to a fixed-voltage function generator to be able to manually change the values could be of use.

Otherwise, here's the differences I see:

The CyDelay(1); just before starting the ADC reading

The mvolts calculation uses 2048 instead of 2047 (This would be a difference of a couple millivolts iirc, so not as big of a deal)

All of the other code looks to be achieving the same effect (or written towards that aim)

The code you have in MeasureBattery() looks to be better, but I would try removing the CyDelay(1) as during that 1 ms delay the OpAmp buffer is probably discharging the battery voltage, causing a drop in voltage and the reading to be lower than it is (that would explain why you are getting 1.9 volts instead of 3~.

0 Likes
Anonymous
Not applicable

Getting closer but not quite there yet.

Ran your code without the CyDelay(1)  on my board with a battery that reads 3.012 on a multimeter

The mvolts values I see in the debugger are 2186,2184 , etc but every 1-2 loop iteration it drops to 1000 range (1024, 1032, etc)

I tried to experiment with the length of the delay in this section of the MeasureBattery() function

/* 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);        

ADC_SAR_CTRL_REG = sarControlReg | ADC_VREF_INTERNAL1024BYPASSED;

But it did not make a difference.

My board with the battery is in the  MiniProg3 and the port settings are

Clock speed :1.6 Mhz

Power: External

Active Protocol : SWD

Tried to change the Power source to 3V - no difference.

Any ideas?

Thanks

Andy

0 Likes
Anonymous
Not applicable

Hmmm, I just realized that the ADC is set for a really low sample rate; Change the sample rate to 500,000. That should minimize the time it takes to measure the voltage even further, and hopefully prevent discharge of the capacitor/OpAmp.

I've attached a picture for the sample rate setting that you would want to boost up:

ADC_Max_Sample_Rate_Adjustment.PNG

Otherwise, the only other thing I can think of that would be affecting the values not being at 3000 is the math being wrong somehow, but the math looks right to me

The ADC is also set to 12 bits for measuring/sampling; Possibly that is causing the issue, as I think the examples online might only be using 11 bits of resolution.

0 Likes
Anonymous
Not applicable

When I set up the ADC as above I got a note

"sdb.M0061:Info from component ADC: The actual sample rate (444444 SPS) differs from desired sample rate (500000 SPS) due to clock configuration in the DWR"

Is this signifcant?

Could you please help decipher (ans fix) ??

Still no luck- the mvolts value now is always in 1700 -1800 range

Thanks

0 Likes
Anonymous
Not applicable

Hmmm, that note is just noting that the sample rate will be lower than the specified sample rate due to hardware limitations. I don't think that is significant besides changing what the resulting sample rate actually is.

Try playing around with the sample rate to see if you can get a rate that will give consistent readings, but also readings closer to what you are expecting? (Try setting the clock rate for 1 kHz and see how that impacts results)

Otherwise, the only thing I can think of at this point is to make sure the "Compensation Capacitance" of the OpAmp buffer is set to "High", or try playing with "Low", "Medium" settings for that. Potentially, try changing the "Power/Bandwidth" settings to see if that affects it as well; Setting for "Low" power/bandwidth should be the ideal choice I think.

Otherwise, if there is a way to verify that the mathematical calculations are for sure giving the range/values they are supposed to on another project, then that would be helpful

I've attached the project with the OpAmp Power/Bandwidth changes made, and the sample rate dropped down lower again.

OpAmpSettings.PNG

0 Likes
Anonymous
Not applicable

Changing the compensation capacitance and power bandwidth in the OpAmp buffer did not make a difference.

Changing the clock frequency in the ADC component did have an effect :

With  the clock is set to 1000 kHz the mvolts in MeasureBattery() function  is around 1000:

ADC_StartConvert();

ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);

adcResult = ADC_GetResult16(ADC_BATTERY_CHANNEL);

/* Calculate input voltage by using ratio of ADC counts from reference

*  and ADC Full Scale counts.

    */

mvolts = (1024 * 2048) / adcResult;

When set to 9000 kHz the mvolts  is around 1600

Still nowhere near the actual battery level

Any other ideas?

Thank you

Andy

Anonymous
Not applicable

Hmmmmm; I would put the ADC sample rate back up to maximum speed (or the speed that gives the most accurate values) then, as that seemed to have a positive affect.

Possibly, doubling the CPU clock speed from 24 MHz to 48 MHz might have a positive impact, as it would minimize the time of the CPU instructions for polling are running...

If you add a second OpAmp buffer in parallel with the first one and the same settings, that will increase the capacitance.

If you decrease the acquisition clk times on the second page of the ADC component from 4 to 2 (it won't let you go lower), then you will get a faster acquisition time and less time for the capacitor to drain?

Also, try toggling the ADC channel 0 to use the "ALT" resolution, and then setting the resolution on the first page to 8 or 10 bits. It will give you smaller values, but with less resolution it should also be faster.

0 Likes
Anonymous
Not applicable

There is some progress but still not there yet.

2 Batteries A and B  with multimeter readings

A = 3018

B = 2256

Adjusted the ADC as follows:

-Alternate resolution 8 bits

-Set acquisition times on all 4 clocks to 2

-Enable alternate resolution on channel 0

mvolts readings:

A = 25266

B = 24966

Changed acquisition times back to 4 - no effect.

So the only thing that did have an effect was using alternate resolution of 8 bits.

However the values don't make sense

Tried adding a second OpAmp buffer with ADC configured as above

Both batteries read 27594

I have not  tried upping the clock speed -  worth a try?

See attached project with changes

Thanks

Andy

0 Likes
Anonymous
Not applicable

The alternate resolution will affect the mathematical calculations that the chip is performing on the ADC result; Thus, changing it from 12 to 11/10/9/8 bits of resolution will throw off all of the values.

My guess is that the calculations aren't matching the bits resolution.

Changed the line: mvolts = (1024 * 2048) / adcResult;

To: mvolts = (2 * 1024 * 2048) / adcResult;

And changed the ADC resolution back to the 12 bits. This should fix it I suspect. (The second OpAmp sounds like it is stabilizing the readings, which is good, so I left that as is)

0 Likes
Anonymous
Not applicable

Looks like you attached the project without those changes. Could you please include the updated one?

Thanks

Andy

0 Likes
Anonymous
Not applicable

Getting closer but still no cigar.

Changed the equation to

mvolts = (2 * 1024 * 2048) / adcResult; and ADC resolution to 12 bits

Now getting values in the 3300-3400 range on a battery that measures 2981

0 Likes
Anonymous
Not applicable

Well, the slightly higher than normal value could be caused by the 2-clk acquisition time. Potentially, changing the acquisition time to be longer will help. See attached project:

0 Likes
Anonymous
Not applicable

Ran your project

mvolts value is 7145 with a battery that reads 2532  and 7188 with a battery that reads 2941 on the multimeter

0 Likes
Anonymous
Not applicable

Hmmm, at this point I would think you can work with tweaking the Acq Clk number, ADC Resolution, and the Mathematical calculations on the resulting ADC counts to determine how to make the project more accurate.

I'm out of ideas at this point

(I realized that the mvolts in my project was already multiplied by two, and I had set it to multiply a second time :/)

0 Likes
Anonymous
Not applicable

Oops, sorry; Thought I attached the updated one

0 Likes