cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

New Contributor II

I am having loads of trouble getting the ADC working on my PSoC 4 Pioneer board..

   

The values coming out of it are all wrong.. I am feeding in 3.9V and I am getting out 2047.. or sometimes  other values..

   

3.9 if my calulation is right should be

   

3.9/(5V/4096) = 3194..

   

I have noticed that if I feed in about 2.5V and below that my 2047 value starts changing and it gets lower and lower the lower voltage I put in so it is tracking the input.. but as soon as I go over 2.5V it locks on at 2047.. I have checked and I have the channel set up for single input, and it says 0-5V on the ADC config page..

   

I really would like just the absolute most bare bones basic project which has a single input and an ADC which is set up to give 4096 for 5V (12 bits) and 0 for 0V..

   

All of the example ADC stuff supplied by Cypress is 0-1.024V which is useless for me..

   

Does anyone have an example project pretty please?

0 Likes
Reply
18 Replies
Anonymous
Not applicable

 I am going to ask some questions that may help (or provide laughter).

   

 

   

1) What voltage are you running the PSoC Pioneer Kit at - on the PSoC 4 processor? It is jumper configurable to run at either 3.3V and 5V - and comes default at 3.3V. If you are running at 3.3V - could that cause the issues you have?

   

 

   

2) In the Creator 3.0 - the tab with the .cydr extension - there is the processor setup. (I don't know the technical terms - bear with me). At the bottom are another set of tabs. One is labeled 'System'. The last set of information is 'Operating Conditions'. I believe this is defaulted to 3.3V for Vddd & Vdda. If you change this to 5.0V - does this help?

   

 

   

Regards,

   

 

   

James

0 Likes
Reply
Anonymous
Not applicable

 Oops - (fingers typing too fast...) in the above the .cydr should be .cydwr. 

0 Likes
Reply
Esteemed Contributor II

Creating a "Workspace Bundle" and upload the resulting file will help us to find any settings that will hinder the precise AD-conversion. The hint with the supply voltage is probably the cause, settings of the ADC usermodule might be another one.

   

Setting the voltage in the .cywr-file will only affect the calculation for ADC-counts to volts by the appropiate APIs.

   

 

   

Bob

0 Likes
Reply
New Contributor II
        Hi I have uploaded my workspace bundle.. Thanks for the quick replies, hopefully someone will be able to spot my mistake.. The board as powered with 5V and VDD was set to 5V already in the system config..   
0 Likes
Reply
Honored Contributor II

Just a guess: you run with Vcc=5V, have configured the ADC to use Vdda/2 as Vref, and the result format is signed? Then you would get exactly what you described. The ADC datasheet explains nicely on pages 6+7 why.

   

Otherwise, when you cannot post the complete project, please explain at least how you configured the ADC.

0 Likes
Reply
Honored Contributor II

Oh, I should check for replies before answering a post which sits open in a tab for one hour 😞

0 Likes
Reply
Esteemed Contributor

Some thoughts -

   

 

   

1) You do not observe the needed delay for reference startup discussed in datasheet.

   

2) In your tight for() loop you do not test each time for end of conversion.

   

 

   

Regards, Dana.

0 Likes
Reply
Honored Contributor II

OK, after looking at the project: I'm right about the signed result format - that explains why you get at most 2047 as result. Change that to unsigned and you should get 4095.

   

Looking at your external circuit: try and drop R3. The input resistance of the ADC is specified as 2.2k (4200 family data sheet, page 20), so you have a nice voltage divider there... Or you add an OpAmp as voltage follower to get high input impedance.

0 Likes
Reply
Honored Contributor II

Regarding the need to wait for EOC: the SAR ADC on the PSoC4 use double buffering for the result, so one should not get invalid / intermediate values. (Just have read the whole section on the TRM 🙂

0 Likes
Reply
Esteemed Contributor

The EOC insures you are not re-reading an old value. In some applications

   

where sample values in real time are importent the non-relevant result is to be

   

avoided.

   

 

   

Of course in these cases an ISR driven read probably more effective.

   

 

   

But I suspect in most applications double buffering is preferred, simply not a cure all

   

for everything.

   

 

   

Regards, Dana.

0 Likes
Reply
New Contributor II

Okay so I am back with further findings.. the values I am getting from the ADC still look messed up but the interesting thing is that if I use the ADC_CountsTo_Volts(0, ADCResult); function then it reads the correct voltage.

   

I am going to give you every bit of info I have, hopefully someone can point where I am going wrong..

   

So I ditched the LDR and decided to just wire a jumper from the ADC pin to the 5V,3.3V,0V lines on the PSOC 4 pioneer itself as can be seen in this photo (note the jumper J9 in the 5V position)

   

http://i.imgur.com/3ga1EuS.jpg

   

So here are my results.

   

5V i.imgur.com/YuQA00o.png

   

As you can see it reads 2047 and not 4096 but the counts to ticks function gives me 5V? how is this working?

   

3.3V i.imgur.com/rhaxcvg.png

   

Not exactly 3.3V but meh close ish..

   

0V i.imgur.com/DjsF8VW.png

   

This one confused me a lot.. as you can see it is reading 65535 for 0V.. not ...0.

   

This couldn't get any more basic, I am wiring a wire from the voltage rail straight into the ADC pin.

   

You guys have been so helpful up to now, hopefully someone can put me right. I have attached my project too.

0 Likes
Reply
New Contributor II

Just some further information on things I have changed.

   

i.imgur.com/KrEhBHX.png  <<This is my source code, I added a delay in as someone said that I could be reading too fast.

   

i.imgur.com/6kt0IOH.png << This is my system config file, I have changed both to 5V now.

   

i.imgur.com/C0YVPZT.png << My Shematic.. now the most simple schematic in the world

   

and finally i.imgur.com/yDOb3TP.png << my ADC config, now has UNSIGNED as the data type..

   

 

   

You could have seen all of this yourselves obviously but I thought if someone has hover zoom they might be able to quickly spot the mistake if I gave you loads of images

0 Likes
Reply
Honored Contributor II

As I already said: since you set the ADC result to be 12bit, signed, its maximum value is 2047. The conversion routines know about that, and give you the proper voltage. If you want better resolution, set it to unsigned (then the maximum value is 4095).

   

For the zero value: the ADC actually measured a negative value. This can happen due to noise. Since the result is signed, it really is a -2 in that case. But you did convert it to an unsigned value, and therefore see its twos-complement.

   

Please read the ADC data sheet about how the ranges and the result can be configured, and what these settings affect.

0 Likes
Reply
New Contributor II

 Hi, Thanks for the insight but in my last image I have shown my ADC config and it is set to "unsigned"? is there somewhere else you are talking about?

0 Likes
Reply
Honored Contributor II

I answered before I saw your second post 🙂 IIRC from your project, you are using 'single ended mode'. With that said, look at the configuration dialog again...

0 Likes
Reply
Honored Contributor II

Oh, and after that read the SAR ADC data sheet, page 8, right at the top. (This answers also your second question)

0 Likes
Reply
New Contributor II

Thankyou so much for your help it was there all along right under my nose.. I just didn't think that there would be another option right under the unsigned/signed.

   

Just for future reference I solved the problem by changing to a differerential input. Single input can be 11bits signed ONLY.

   

As always I should have just read over the datasheet!! so glad I solved it now.

0 Likes
Reply
Honored Contributor II

Rule of thumb: When nothing else works, read the manual. If this doesn't help, read it again.

0 Likes
Reply