12 Replies Latest reply on Feb 27, 2013 3:41 PM by user_14586677

    Reading a Port Value

    rajendra.prasad

       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

         

       

         

         

        • 1. Re: Reading a Port Value
          sridhar.m

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

          • 2. Re: Reading a Port Value
            rajendra.prasad

            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();
                     
                         }
                    }
                }
            }
             

            • 3. Re: Reading a Port Value
              user_14586677

              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.

              1 of 1 people found this helpful
              • 4. Re: Reading a Port Value
                rajendra.prasad

                Hi dana,

                   

                i am uploading the bundle.

                • 5. Re: Reading a Port Value
                  user_49271930

                   

                     

                   

                     

                   

                     

                   

                  1 of 1 people found this helpful
                  • 6. Re: Reading a Port Value
                    user_49271930

                    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

                       


                     

                    1 of 1 people found this helpful
                    • 7. Re: Reading a Port Value
                      user_14586677

                      This might help as well -

                         

                       

                         

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

                         

                       

                         

                      Regards, Dana.

                      1 of 1 people found this helpful
                      • 8. Re: Reading a Port Value
                        user_14586677

                        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.

                        1 of 1 people found this helpful
                        • 9. Re: Reading a Port Value
                          rajendra.prasad

                          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

                          • 10. Re: Reading a Port Value
                            user_14586677

                            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.

                            1 of 1 people found this helpful
                            • 11. Re: Reading a Port Value
                              user_49271930


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

                              1 of 1 people found this helpful
                              • 12. Re: Reading a Port Value
                                user_14586677

                                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.

                                1 of 1 people found this helpful