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?
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?
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.
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.
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.
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.
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 🙂
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
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
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)
So here are my results.
As you can see it reads 2047 and not 4096 but the counts to ticks function gives me 5V? how is this working?
Not exactly 3.3V but meh close ish..
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.
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
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.
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?
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...
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.