Problems with SAR ADC

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.
Anonymous
Not applicable

Hi,

   

I'm new into PSoC and PSoC BLE.
I decided to design a PSoC Fart-O-Meter.
So far the project is quite simple: A methane sensor, powered with 5 volts, is measures the concentration of methane in the air.
The output is a voltage between 0-5 volts.
I want to convert this output value to an integer by using the SAR ADC. Using this value I want to set a servo, that is  showing the concentration on a sign.
Later I want to send the value via BLE to another PSoC BLE, as mobile display.

   

Unfortunately it doesn't work, I'm saving the value in a variable but when reading this variable, e.g. in debugging, it's everytime empty(0x00000000).

   

I added my project to this post.

   

I hope you can help me!

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

You just start one conversion. And then you never wait for it to finish.

View solution in original post

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

You just start one conversion. And then you never wait for it to finish.

0 Likes
Anonymous
Not applicable

Sorry I don't get you! Thats my first post in the forum!?

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

What hli wants to say: There is a function ADC_IsEndConversion() which you should use to wait for a conversion done. Look into datasheet, there is a parameter for the function.

   

 

   

Bob

   

Are we opening a pure German thread here?

0 Likes
Anonymous
Not applicable

Ah ok!
I will look it up!

   

A pure German thread would be perfect!

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

hli is located in Magdeburg and I live near Bremen. Where are you seated?

   

 

   

Bob

0 Likes
Anonymous
Not applicable

In der Nähe von Freiburg, genauer Emmendingen!

D.h. ich muss, bevor ich den Wert in die Variable schreibe, prüfen, ob eine Konvertierung beendet wurde, indem ich davor ACD_IsEndConversion(ADC_WAIT_FOR_RESULT) setze?

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

I been to Freiburg nice place.  I lived in Ramstein for 3 years back in the late 1970's.

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

Forum language is English, silvan wrote:

   

Namely I have before I write the value in the variable, check whether conversion was terminated by ACD_IsEndConversion (ADC_WAIT_FOR_RESULT) I place in front of it?

   

Yes, that's quite right!

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Oops sorry!
My next question is there any possibility to view the value of  my variable "gas"?
When debugging the code, the overlay of "gas"shows 0x0000... .
Or is there a way to discover the max and min value that "gas" could assume?

   

I attach my latest code.

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

I used a modification as

   

int16 MaxValue = 0;
int16 MinValue = 32767;

   

 

   

        value = ADC_GetResult16(0);
        if(value > MaxValue) MaxValue = value;
        if(value < MinValue) MinValue = value;

   

and I got different values for Min amd Max.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Ok, but I can I read out the actual value of the ADC?

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

but I can I read out the actual value of the ADC? According to my experiences: Yes

   

A tip: when debugging and a breakpoint (BP) is reached the CPU halts. That's quite normal so far.

   

But the internal hardware keeps on running, so generating interrupts, overflowing counters, keeping PWM outputs running and so on. This means that the next result of an ADC conversion after a BP will be wrong. So in your case I would set a BP at the IsEndConversion() line and so observing the previous result.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

My problem is, that I can't check, which value is actually written in the variable...
Like I wrote before, I want to read out the value of "value"
 

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

Set a breakpoint. When reached, hover with the mouse cursor over your variable. A window will pop-up that shows value and address as long as the variable is not optimized-out into a register. In that case you will have to open the disassembly window and inspect the registers.

   

I cannot see any reason why you weren't able to watch a variable.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I did this and the value of my variable was always 0x0000... .
To check it I put 5 volts at the port of the ADC, in my case 2(4).

   

I would appreciate if you could check, if I set up the ADC correctly?
My current project was uploaded a few posts before.

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

See attached.

   

 

   

Bob

0 Likes