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

PSoC™ 6 Forum Discussions

Anonymous
Not applicable

Dear all,

I am facing a problem while implementing ADC in PSoC. The use of "uint32 ADC_IsEndConversion(uint32 retMode)" gives an error while inserting retMode i.e.,  ADC_RETRUN_STATUS or ADC_WAIT_FOR_RESULT.

The only way forward is to insert "0" as retMode but still, the ADC results are wrong. I am using the following code:

#include "project.h"

#include "math.h"

#include "stdio.h"

float Is;

int main(void)

{

Is=0;  

__enable_irq(); /* Enable global interrupts. */

ADC_Start();

for(;;)

{

ADC_StartConvert();

if(ADC_IsEndConversion(0))

{

Is=ADC_CountsTo_Volts(0, ADC_GetResult32(0));

if (Is<1)   //A simple check for the ADC values

Cy_GPIO_Inv(test_PORT,test_NUM);

}

ADC_StopConvert();

}

}

pastedImage_7.png

0 Likes
1 Solution
Anonymous
Not applicable

Well, somehow it is working now as I have changed the input pin.

View solution in original post

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

ADC_IsEndConversion(0) is wrong, valid values start at 1

You do not wait for a conversion done, you stop before it is done.

Use the given constants ADC_WAIT_FOR_RESULT or ADC_RETURN_STATUS. Maybe a typo in the name? Check in generated file ADC.h

Bob

Anonymous
Not applicable

Thanks, Bob, for your continuous help over the past few years.

I have updated my PSoC creator to 4.2 Beta 2 and came to know that the PDL of the ADC has been changed. So, or CY_SAR_RETURN_STATUS or CY_SAR_WAIT_FOR_RESULT are required as retMode. But the problem still persists with the ADC results i.e., I still get the toggled signal, though I have grounded both input terminals to ADC. Also, how can I watch my variable 'Is' in PSoC Creator?
My updated code is given below and I have also attached my project:

#include "project.h"

#include "math.h"

#include "stdio.h"

float Is;

int main(void)

{

 

Is=0;

__enable_irq(); /* Enable global interrupts. */

ADC_Start();

for(;;)

{

     

ADC_StartConvert();

ADC_IsEndConversion(CY_SAR_WAIT_FOR_RESULT);

Is=ADC_CountsTo_Volts(0, ADC_GetResult32(0));

if (Is>2)   //A check for the ADC values

Cy_GPIO_Inv(test_PORT,test_NUM);

ADC_StopConvert();

}

}

pastedImage_5.png

pastedImage_2.png

0 Likes

I do not want to overload my pc with uneeded programs, Can you lplease use the Creator to make a project archive.

To do so, use

Creator->File->Create Workspace Bundle (minimal)

and attach the resulting file.

Bob

0 Likes
Anonymous
Not applicable

Please find the files in attachments. I have checked 'Is' using the debugger and it doesn't change value when I change 'Iin' externally.

0 Likes
Anonymous
Not applicable

And I even can't find any code example of illustrating Scanning ADC in PSoC 6.

0 Likes

There are two examles listed in the datasheet, whith and without using an interrupt.

Having a look into the board schematics reveils that there is no connection to a port, but to an internal capacitor on port P7_7

Bob

Anonymous
Not applicable

Well, somehow it is working now as I have changed the input pin.

0 Likes