1 2 Previous Next 17 Replies Latest reply on Nov 27, 2011 11:37 PM by udayan.umapathi

    Read data from input pin

    abhishek.joshi

      Hello !! I am beginner in psoc. i am having a simple problem that i want to assign any pin as a input and when the input to that particular pin is given logic high then it should perform the desired looping operation. Plz help abt how to keep tht pin as input and how to read data from it..

        • 1. Re: Read data from input pin
          user_1377889

          Hi,

             

          first download and install PSoC Creator software.

             

          Then drop an Input Pin component on the schematic and adjust the number of pins you like to experiment with.

             

          In your main() program you read the pins with

             

          uint8 Values;
          Values = PinName_Read()

             

          Happy coding

             

          Bob

          • 2. Re: Read data from input pin
            abhishek.joshi

            thnx for quick reply.. :) but if i want to use p1[7] as input pin then how should i go forward with it ?? tht means how to initialise it and how to get data from it ??

            • 3. Re: Read data from input pin
              gautam.das.g

              Hi blueblood,

                 

               

                 

              You can drag and place a Digital Input Pin component from the component catalog onto the schematic.

                 

              You can double click on the component to open the Configuration Window where you can select its Drive Mode (if you want to alter).

                 

              The schematic will look like this

              • 4. Re: Read data from input pin
                gautam.das.g

                Once you save the project, open the .cydwr file from the Workspace Explorer.

                   

                In the Pins tab select the Port Pin to which you want to assign this pin (in this case it's P1[7]).

                   

                 

                   

                 

                   

                 

                   

                Once you select the required pin, you can build the project. APIs will be generated for this Pin.

                • 5. Re: Read data from input pin
                  gautam.das.g

                  As Bob Marlowe has already mentioned, the Pin value can be ready by simply using the API <PinName>_Read( ) in the main.

                     

                  The default Drive Mode of Digital Input Pin is High Impedance Digital. However, you can select other drive modes, if the situation demands, to Resistive Pull-up, Resistive Pull-down, etc.

                  • 6. Re: Read data from input pin
                    abhishek.joshi

                    thnx all.. i made following connections as mentioned above.. but it is giving errors.. i have attached the screenshot for verification.. have i done wrong intialization ??

                    • 7. Re: Read data from input pin
                      ki.leung

                       You should put the line 

                         

                      uint8 Values;

                         

                      at the bdginning  of you function before any opertions. EG

                         

                      void main (void)

                         

                      {

                         

                      /* all variable declare first */

                         

                      uint8 a;

                         

                      uint16 b;

                         

                      ...

                         

                       

                         

                      /* Then  the c program here */

                         

                      ..

                         

                      ..

                         

                       

                         

                       

                         

                      }

                      • 8. Re: Read data from input pin
                        ki.leung

                          You should put the line 

                           

                        uint8 Values;

                           

                        at the bdginning  of you function before any opertions. EG

                           

                        void main (void)

                           

                        {

                           

                        /* all variable declare first */

                           

                        uint8 a;

                           

                        uint16 b;

                           

                        uint8 Values;

                           

                        ...

                           

                         

                           

                        /* Then  the c program here */

                           

                        ..

                           

                        ..

                           

                        pga_start();

                           

                        values = PIN_2_Read();

                           

                        ...

                           

                         

                           

                         

                           

                        }

                        • 9. Re: Read data from input pin
                          gautam.das.g

                          Yes, as lleung has already mentioned, declare all the variables used in the code before calling the component APIs.

                             

                          Rearranging the declarations should eliminate the error.

                          • 10. Re: Read data from input pin
                            abhishek.joshi

                            thank you everyone for the help.. :) the method worked !! i also found other technique of using "CyPins_ReadPin(Pin_2_0)" which simply does the reading of the port pin without initialization..

                            • 11. Re: Read data from input pin
                              user_1377889

                              http://publications.gbdirect.co.uk/c_book/ is a pretty good C-Syntax description.

                                 

                              C is not easy or simple, there are lots(!!!) of pitfalls and misunderstandings you will experience, so don't get frustrated.

                                 

                              Happy coding

                                 

                              Bob

                              • 12. Re: Read data from input pin
                                user_1377889

                                I am a professional programmer (for about 40 years now) and I would like to put you on the right track.

                                   

                                The main goal for a good program is not "It Works!". If it doesn't work, its not a program at all, a piece of wood doesn't work eather.

                                   

                                So what are the kriteria for a "good" program?

                                   

                                Here are some of mine:

                                   

                                Cheap - Programmed and tested in a short time

                                   

                                Cheap - Re-usable code from former projects

                                   

                                Cheap - Flexible programming adopts easily to different hardware

                                   

                                Cheap - Make the program human readable as much as possible

                                   

                                You can add yours here...

                                   

                                 

                                   

                                Reading directly in your program from a specific pin violates some of the above kriteria, saving the initialization part has the downgrade that there IS NO initialization part. HAVING an initialization part makes it easy to pre-check some external situations before the program really runs (or deny the running with an error-message.

                                   

                                All my PSoC-programs have the following structure which make it easy to look up, control or change the appropiate part:

                                   

                                Title of the Program, date, version and what it should perform

                                   

                                #includes

                                   

                                #defines

                                   

                                Global Variables (but only a few!)

                                   

                                void InitializeHardvare(void

                                   

                                {

                                   

                                   Yes, exactly that, nomen est omen...

                                   

                                }

                                   

                                void main(void)

                                   

                                {

                                   

                                 InitializeHardware();

                                   

                                Here goes the initialization of the software

                                   

                                while(forever) // #define forever 1 helps readability

                                   

                                {

                                   

                                The main task, normally calling some functions defined in other files

                                   

                                }

                                   

                                // NO FINALIZATION, forever is forever, this code will never be reached

                                   

                                 

                                   

                                Happy coding

                                   

                                Bob

                                • 13. Re: Read data from input pin
                                  user_1377889

                                  Ooops, forgot a ")" here are some spare, insert where requred "(())){{{}}}[[]];;;"

                                     

                                  Bob

                                  • 14. Re: Read data from input pin
                                    abhishek.joshi

                                    thanx bob for the suggestions !! it was my first experience with psoc.. i must say it is great piece of software.. very easy to use !! Just one simple query that i have made my sub modules individually.. tht means in different projects.. but when i combine them, one of the sub modules doesn't work.. any idea why this is happening ??

                                    1 2 Previous Next