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

cross mob
SeTa_2234986
Level 1
Level 1
5 replies posted 5 sign-ins First reply posted

I have a simple project to do followings with CY8CKIT-147 eval board.

 

1. Read analog voltage through ADC

2. UART out to another MCU

3. Receive the output from above 2 in the second eval board.

4. DAC to analog voltage

 

I made each function to certain level except the ADC portion by observing followings

2. I can see expecting UART output on PC through Tera Term.

3. I can send a character to the eval board from Tera Term and see expecting actions.

4. I can see the analog voltage from DAC output as I programmed.

 

But for some reason, ADC does not read the voltage.  I have successfully used PSoC ADC in earlier version 2.x in PSoC Creator 4.2.  Now I use ADC version 3.10 in PSoC Creator 4.4.  PSoC symbol and APIs are not identical but I'm trying to do the same or the similar, but the SAR ADC does not return proper value. I have tried both "Continuous" and "Single Shot" sample mode, but did not see any improvement.  Are there anything that I need to pay attention in the latest version?  

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Actual voltage at the pin is changing from 0 ~ 5V range, but the reading stays around 3.74V.

This suggested me something.

I checked the function init_hardware() 

void init_hardware(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    UART_Start() ;
    ADC_Start() ;
}

May be we (you) need "Opamp_1_Start()" here.

So how about modifying this to

void init_hardware(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    UART_Start() ;
    Opamp_1_Start() ;
    ADC_Start() ;
}

moto

View solution in original post

11 Replies
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Since I don't have CY8CKIT-147 with me right now I can not test it,

but I wrote an ADC test program for it a couple of years ago.

And I think that it was working then.

So would you test attached sample to test if it works?

Meantime, please check the KitGuide and/or the schematic of CY8CKIT-147 to check if the pin you are using is used for other purpose or connected to some other component(s) on the board.

moto

SeTa_2234986
Level 1
Level 1
5 replies posted 5 sign-ins First reply posted

Hi Motoo

 

First of all, thank you for supplying me the sample code.  I could build your project in Creator 4.4 and run on my eval kit, CY8CKIT-147.  Voltage change at the analog input was observed in Tera Term on my PC.

 

But when I copied your code into "the existing project" and adjusted some settings like instance names and analog input pin, voltage was not read correctly and the behavior was same as with my code.  I compared 2 projects and they are the same as much as I could investigate. 

 

Then at one point, I thought the way to create the projects might be different.  Since I downloaded CY8CKIT147Setup_RevSS.exe, I chose “Target kit” in below dialog.

SeTa_2234986_0-1627926787818.png

 

 

I tried both “Target kit” and “Target device” to create new projects from scratch, and found that ADC works fine when I choose “Target device”, but does not work when I choose “Target kit”.  Can you think of possible reason of this observation?

0 Likes

Hi

 

I was inaccurate in my last e-mail.  I thought I did the same in both “Target kit” and “Target device”, but I had a different PSoC HW setting.  After fixing this part, the project that I created with “Target kit” started working.  (FYI, I was using the same pin for analog input as yours.)

 

What I had in “Target kit” configuration was that I had OPAMP as “follower”. 

SeTa_2234986_0-1627946462372.png

 

 

This is actually the configuration I had when I could not make ADC work and posted my question.  I think it is logically the same as without the follower, and I saw many examples have an OPAMP as follower like this.  But with this configuration, ADC does not read the value correctly.  Is there any reason that this configuration does not work?  I have tried several settings in Opeamp setting, but I could not make ADC work.

SeTa_2234986_1-1627946462379.png

 

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

If you are using  P3[4] for the analog input, it has a direct path to the ADC,

but for an OpAmp to work between the input and ADC,

using this pin may not be a good idea.

 

How about trying the green marked pin(s) for the OpAmp(Follower),

such as P1[0], P1[1], P1[4], P1[5], P2[0], P2[1], P2[4], P2[5] ?

001-pin-candidates.JPG

But if this makes the situation better, I would think that PSoC Creator should have warned it...

moto

 

lock attach
Attachments are accessible only for community members.

Hi Motoo

 

Thank you for your advice.  As you suggested, I was using the green marked pin(s) when I assigned input pin to OPAMP, so I assigned OPAMP input to P2[4] even before I posted my question.  

 

I tried OPAMP input to the same pin P3[4] as in your sample project though it was yellow marked, but no luck.  Then I tried to another P2 pin such as P2[5], then another port such as P1[4] and other pins, but no luck.  As you stated, I would expect warnings if I assign pins to unsuitable pins, but I did not see or at least did not notice such warnings or errors.

 

I attach the project archive.  If you find something, please advise me.

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I downloaded and opened your project.

I could not find something strange around the OpAmp (follower)

nor in the ADC settings.

But when I opened the ADC.h, I noticed an unfamiliar function

int16 ADC_RawCounts2Counts(uint32 chan, int16 adcCounts)

May be we need to call it before calling 

int16 ADC_CountsTo_mVolts(uint32 chan, int16 adcCounts);

So how about modifying the function measure() as below?

int16_t measure(void)
{
    int16_t raw_counts ;
    int16_t counts ;
    int16_t value ;
    ADC_StartConvert() ;
    ADC_IsEndConversion(ADC_WAIT_FOR_RESULT) ;
    raw_counts = ADC_GetResult16(0) ;
    counts = ADC_RawCounts2Counts(0, raw_counts);
    value = ADC_CountsTo_mVolts(0, counts);
    return(value) ;
}

And now the returned value is mV, how about changing the sprintf statement to

        snprintf(str, 128, "%d: %d.%03dV\n",
            ivalue,
            (int) (ivalue / 1000),
            (int) (ivalue % 1000)) ;

 

attached is your project with the modifications above.

moto

Hi Motoo

 

Thank you for providing the modified project.  But ADC still does not read correct value though the project was built and complied with no warnings and no errors in Creator 4.4.  Below is the screen capture of my Tera Term window.  Readings changes moment to moment by noise.  Actual voltage at the pin is changing from 0 ~ 5V range, but the reading stays around 3.74V.

 

SeTa_2234986_0-1628036261572.png

 

 

If there is anything you want me to try, please let me know.  Thank you for your support.

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Actual voltage at the pin is changing from 0 ~ 5V range, but the reading stays around 3.74V.

This suggested me something.

I checked the function init_hardware() 

void init_hardware(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    UART_Start() ;
    ADC_Start() ;
}

May be we (you) need "Opamp_1_Start()" here.

So how about modifying this to

void init_hardware(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    UART_Start() ;
    Opamp_1_Start() ;
    ADC_Start() ;
}

moto

Hi Motoo

 

You are correct.  When I added "Opamp_1_Start()", it started getting correct voltage.  I never expected that we need to “start” Opamp.  Thank you very much for your support.

 

Today, I am trying to use UART RX interrupt.  Before trying to use interrupt, I was polling the RX buffer with UART_CAM_UartGetByte() in for(;;) loop, and it was reading the expected values.  I thought of utilizing “RX FIFO not empty” interrupt to start reading the buffer, so in PSoC UART, I set as following.  (“UART_CAM” is my instance name.)

SeTa_2234986_0-1628104725058.png

 

 

In my main(), I have followings before the main loop.

    UART_CAM_SetRxInterruptMode(UART_CAM_INTR_RX_NOT_EMPTY);

    UART_CAM_EnableInt();

    UART_CAM_Start();

 

And inside the main loop, I have following.

if (UART_CAM_GetRxInterruptSource() == UART_CAM_INTR_RX_NOT_EMPTY)

        { //Start reading RX FIFO }

 

But the process never gets through this if statement.  Can you advise me what I am missing?

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I'm glad hearing that finally your can acquire the correct voltage 😉

Please make the response as "Correct Answer" if it solved your problem.

 

Meantime, about UART, please keep a discussion one question and one answer,

so that others can find the problem and the answer.

Probably no one will expect to find an answer for UART in a discussion titled "PSoC4 ADC API."

 

Having written above, I have written and posted a sample using UART with interrupt in the following "Code Examples" discussion. Hopefully it can be some hint for you.

But in case you still find some difficulties to accomplish what you want to do,

please create a new discussion with appropriate title and ask your question there.

https://community.cypress.com/t5/Code-Examples/tty-utils-a-utility-sample-for-CLI-type-program/m-p/7...

moto

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

At least it's a very good news that both my sample and your project created with "Target device" are working.

This means that the hardware is fine and your environment seems to be fine, too.

Then the remaining problem is "What" is wrong with creating a project with 'Target kit".

And I wonder which pin you are using for the analog input for ADC?

I have some questions/suggestions for you.

(1) Can you create a simple project which reproduce the problem and make an archive file of it and post it in this discussion, so that we can take a look at to search what is the problem?

(2) Can you copy my sample project and change the analog input pin to the pin you are using in your project,

and see if it works or not?

(3) Since both your project created with "Target device" and my sample are working,

can you proceed with either of the project to fulfill your application?

 

 Can you think of possible reason of this observation?

If you are using same pin (hardware) configurations in both "Target device" project and "Target kit" project,

there can be a chance that the template of "Target kit" project has some problem (aka bug).

If you are using different pin (hardware) configurations, the difference may be the root cause.

 

moto

 

0 Likes