ADC Measuring Wrong Value

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

cross mob
lock attach
Attachments are accessible only for community members.
ToVa_285016
Level 5
Level 5
100 replies posted 50 replies posted 50 questions asked

 Hi,

   

I am guessing this is something simple I am overlooking, but I am unable to get the ADC to correctly read input voltage values.  See the attached project.  For example, my multimeter (and a back up) are reading:

   

ADC 0:  2.368V

   

ADC 2:  2.283V

   

The processor is computing:

   

ADC 0:  2.255V

   

ADC 2:  2.180V

   

Both values are about 5% different - could be a red herring.

   

Any ideas?

   

Thank you,
Tom

0 Likes
23 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Since you are using Vdda as reference: are you sure it is _exactly_ 4.68V as you have specified?

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

At first you should query for an _IsEndOfConversion() before you read the values from ADC.

   

Additionally you may calibrate the ADC by measuring and setting offset and gain.

   

 

   

Bob

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

_IsEndOfConversion() is not needed - the SARSEQ does double buffering of results (see thr PSoC4 TRM, part 19.3.4.3).

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

You could increase the sample average to a higher value.  But using VDD has issues. You could use an extra channel and read the VDD and then use it in your equations instead of the fixed value of 4.68. I would use the internal voltage reference of the ADC and use a voltage divider to make sure you don't over range you readings for each channel.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

When you want to measure Vdd, and have Vdd as reference at the same time, use the ADC to measure a reference voltage instead. Unfortunately that doesn't work in the PSoC4 since the internal reference is not accessible 😞

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Your reference is Vdda, which is typically a low accuracy LDO or regulator

   

output. Use your multimeter to measure Vdda, then scale by the inaccuracy

   

(gain error) you find the SAR readings. If you need more accuracy use the internal refer-

   

ence and R dividers (precision) on inputs to get the CM range you want for

   

the input.

   

 

   

Regards, Dana.

0 Likes
ToVa_285016
Level 5
Level 5
100 replies posted 50 replies posted 50 questions asked

 Thank you all for your input.  Since this is not a high precision application, I am going to use the multimeter scaling method.  It seems to be working reasonably well.

   

Anyone have a good work around for sprintf()?  I am running out of memory with it, and am trying to write float data to an SD card with two decimal points precision.

   

Thank you,
Tom

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Are you running out of heap memeory or out of flash memory? The first one can be increased in the design-wide resources. For the latter one you need to find something else to spare...

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

At top of this page put "PSoC4 sprintf" into the Keyword Search field. Take care that you use Creator 3.1.

   

 

   

Bob

0 Likes
ToVa_285016
Level 5
Level 5
100 replies posted 50 replies posted 50 questions asked

 Hi,

   

I have looked around, and there is not much for floats.  I guess I could break it down into integers and print each of those and recombine with a '.'.

   

One more quesiton - I have sprintf() working...at least compiling, but it does not produce a string.  The code is:

   

sprintf(curSolStr,"%0.2f \r\n",currentSolar);

   

The '/r/n' are showing up in the char array curSolStr, but not the value 'currentSolar' which is '0.246'.  Any thoughts?

   

Thank you,
Tom

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

You have the nano library enabled -

   

 

   

    

   

          http://www.cypress.com/?id=4&rID=87354

   

 

   

Regards, Dana.

0 Likes
ToVa_285016
Level 5
Level 5
100 replies posted 50 replies posted 50 questions asked

 Unfortunately the non-nano library is way too large.  I enabled the -u _printf_float option, and it still overflows.  Deleting the SD card allowed it to process, but I sort of need that for this application...

   

Unless anyone has any other floating point operations, I will have to wait for the new M processor for sprintf() and use tiny print splitting the integer and fraction and recombining them.

   

Thank you,
Tom

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

printf requires to increase the heap size. With Creatior 3.1 the default is just 128 bytes which is way too low. Set it to something 0x400 (in the design-wide resources)

0 Likes
lock attach
Attachments are accessible only for community members.
ToVa_285016
Level 5
Level 5
100 replies posted 50 replies posted 50 questions asked

 I tried to increase heap size to no avail.  See attached.  It seems like the functions that are running me out of memory are the SD card functions.

   

I have come up with a clunkier version that works using tinyprintf, but if I could get sprintf to work, I would.  Like I said, the PSOC Mwill be great for this.

   

Thank you,
Tom

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

Did you set the project build from "Debug" to "Release" having a much stronger optimization level? Debugging is barely possible with that setting, but if that works I can help you further...

   

 

   

Bob

0 Likes
ToVa_285016
Level 5
Level 5
100 replies posted 50 replies posted 50 questions asked

 It worked!  However, now I have the other version working fine using much less memory and debuggable, so I will probably use that for my data logger for now.  

   

Thanks for all the help, once again, I walked away slightly more knowledgeable.

   

Tom

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

There is a (bit time-consuming) way to get all you want: By right-clicking on a generated C-file you may select "Build Settings" from which you can now select for this file the "Release" compile. This will reduce flash usage for all the files you do not need to debug.

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Tom, would you mind posting your "final" working project. I have a

   

son that wants to put a data logger on his Motot Guzzi bike to optimize

   

tuning, and it would be handy if I do not have to re-invent the wheel.

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
ToVa_285016
Level 5
Level 5
100 replies posted 50 replies posted 50 questions asked

 Hi,

   

See the project attached below.  It is full of quesitonable code, I am sure, but it works great, and I just got my results off of the SD card and are working with them in an Excel spreadsheet right now.  The project currently measures some data for a solar powered lighting project I am working on, but it will be nice to have a custom data logger on hand for future projects.

   

Thank  you,

   

Tom

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

The internal reference can be brought out for other uses on the ADC. You just need to select internal reference 1.024V bypassed and I would add a op amp  buffer to prevent loading of the reference.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

But even then its available only on the external pin, not for internal routing.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

If you abandon Vdda as Vref then of course you will need external

   

R dividers to handle the higher Vxin you want to measure. But

   

you would gain a net higher accuracy by using the internal Vref and

   

precision thin film Rdivider.

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Intdernal reference -

   

 

   

   

 

   

Its 2 %, maybe use an accurate external Vref to power Vdd and eliminate R dividers on

   

input pins. 2% is ~ 6 bits, food for thought. Or use ext ref directly on SAR.

   

 

   

Regards, Dana.

0 Likes