Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 3 > Reading a Port Value

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



Reading a Port Value
Moderator:
RKRM

Post Reply
Follow this topic



Reading a Port Value

vgy posted on 26 Feb 2013 1:17 AM PST
Top Contributor
133 Forum Posts

 hi ,

      How can we Read the status Of a particular pin , how do we do this on firmware. The below schematic is i am comparing input voltage to pin with Vdac, if it exceeds comparator will generate a logic 1 at Pin 2 , if pin2 = logic 1  the ADC should stop.so how can we read the status of pin2 in firmware.

Thanks

 

   


Re: Reading a Port Value

srim posted on 26 Feb 2013 03:01 AM PST
Cypress Employee
121 Forum Posts

 Use CyPins_ReadPin() API to read the pin value. Refer to the "Per-Pin APIs" section in pins datasheet for more information



Re: Reading a Port Value

vgy posted on 26 Feb 2013 03:55 AM PST
Top Contributor
133 Forum Posts

Hi ,

     I thank u for your reply sir, here i am pasting the code and schematic, i am able to read the value from port , but here i didnt understand some of things.

1) from the Schematic , ADC should start convert if the Comparator2 value goes high, thats working but after started converting if comparator 1 goes high ADC should stop converting and LCD should clear display, but both are  not happening.

here is my code

-----------------------------------

void main()
{
    uint16 output;
    uint8 Values1;
/* Start the components */
   
    LCD_Start();
   
    VDAC8_1_Start();
   
    Comp_1_Start( );
   
    VDAC8_2_Start();
   
    Comp_2_Start( );
   
    Comp_2_SetSpeed(Comp_2_HIGHSPEED);
   
    /* Set high speed mode */
    Comp_1_SetSpeed(Comp_1_HIGHSPEED);
   
    ADC_DelSig_1_Start();
   
//    /* Start the ADC conversion */

   
    /* Display the value of ADC output on LCD */
    LCD_Position(0, 0);
    LCD_PrintString("ADC_Output");
   
    for(;;)
    {
       
         
        if(ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT))
        {
            output = ADC_DelSig_1_GetResult16();
            LCD_Position(1, 0);
            LCD_PrintInt16(output);   
            Values1 =CyPins_ReadPin(CYREG_PRT12_PC2);
            if(Values1==1)
             {
              ADC_DelSig_1_Stop();
              LCD_ClearDisplay();
         
             }
        }
    }
}
 

 



Re: Reading a Port Value

danaaknight posted on 26 Feb 2013 04:47 AM PST
Top Contributor
1773 Forum Posts

Is your Comp 1 output connected to Port12 pin or Port 1 pin or Port 2 pin ?

Port12 is legit, if thats what you are using.

 

You are reading the output register for the port, should you not be reading -

 

 

 

If HW is designed to only supply ADC values > Vx1, and stop supplying values if

> Vx2, why not let adc run continuously, eliminate both comparators, and do these

tests in code ?

 

Regards, Dana.



Re: Reading a Port Value

vgy posted on 26 Feb 2013 06:37 AM PST
Top Contributor
133 Forum Posts

Hi dana,

i am uploading the bundle.



Re: Reading a Port Value

pavloven posted on 26 Feb 2013 10:45 AM PST
Top Contributor
78 Forum Posts

And what you don't like this option.
if (Comp_1_GetCompare())

Interesting information
Writing to a PSoC3 GPIO – Various options
http://www.cypress.com/?id=2314&StartRow=26&PageNum=6

 

 



Re: Reading a Port Value

pavloven posted on 26 Feb 2013 10:46 AM PST
Top Contributor
78 Forum Posts

CyPins_ReadPin(CYREG_PRT6_PC2)  = 010H  (not 1) 

And what you don't like this option.
if (Comp_1_GetCompare())

Interesting information
Writing to a PSoC3 GPIO – Various options
http://www.cypress.com/?id=2314&StartRow=26&PageNum=6


 



Re: Reading a Port Value

danaaknight posted on 26 Feb 2013 01:24 PM PST
Top Contributor
1773 Forum Posts

 

This might help as well -

 

http://www.cypress.com/?rID=57571

 

Regards, Dana.



Re: Reading a Port Value

danaaknight posted on 26 Feb 2013 01:31 PM PST
Top Contributor
1773 Forum Posts

What may help is for you to describe why you want to start A/D at some

threshold, and stop it at another ? What is it you are trying to accomplish

with the design you posted ?

 

Regards, Dana.



Re: Reading a Port Value

vgy posted on 27 Feb 2013 11:18 PM PST
Top Contributor
133 Forum Posts

Hi dana,

              how to start an ADC if input to is greater than 30 mv and how to stop it if its input reaches 4 v in firmware.I did this logic with comparators, but can we accomplish with code.

Thanks

 



Re: Reading a Port Value

danaaknight posted on 27 Feb 2013 02:26 AM PST
Top Contributor
1773 Forum Posts

Let A/D run continuously, and test it for both conditions with flags

for each condition. So set a flag, call it "lowtrip", if > 30 mV, and

another if > 4V, calling it "high trip". Then use flag status to do what-

ever it is you are doing when these conditions are met.

 

Your may code to be a little more sophisticated, use averaged values

for tests (to reject noise), and/or use hysterisis for setting/clearing the flags............

 

Regards, Dana.



Re: Reading a Port Value

pavloven posted on 27 Feb 2013 10:01 AM PST
Top Contributor
78 Forum Posts


I probably would have done so. ( for CY8CKIT - 030 PSoC3)
Only it is not clear what it is.....

 



Re: Reading a Port Value

danaaknight posted on 27 Feb 2013 01:41 PM PST
Top Contributor
1773 Forum Posts

Attached is a solution w/o using VDACs and Comparators. The A/D reads the

pot on the -030 board, and you must jumper the hole next to LED1 to P12_2.

 

If you are a student I would ask you to continue on your design, as that will work,

with some changes/coding. In other words do not submit this design for student work,

you would not be doing yourself a good deed.

 

Regards, Dana.






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20