12 Replies Latest reply on Mar 28, 2014 4:16 PM by user_14586677

    PSoC-Dark sensor.

    erkiii.beerg

       Hi

         

          

       

         

      I am making a dark detector sensor on PSoC3.  I am new to PSoC programing, so I need a little bit of help.     

       

         

      If you look at my Topdesign (The attached file), I am using a transimpedans amplifier ( To convert current flow from my photo diode ( SFH213) ) and further more I am using a comparator to compare two voltages.  I want to make it so that, when it is dark (no or little current flow), the comparator output should be high, then I want to run an interrupts which should sets a pin high.  And when it is low, I want to run an interrupts which sets the same pin low.     

       

         

      Info:     

       

         

      When there is light the positive terminal end of comparator is around 2V.     

       

         

      Negative terminal end of the comparator is 1V.

         

      Thank you in advance. 

        • 1. Re: PSoC-Dark sensor.
          user_1377889

          So what is exactly your problem, what do you neet help with?

             

          Do you use a development kit? Which one?

             

          When you start coding, try to upload your complete project here using Creator -> File -> Create Workspace Bundle, so we all can have a looki at.

             

           

             

          Bob

          • 2. Re: PSoC-Dark sensor.
            erkiii.beerg

             Hi

               

                

             

               

            This is the small code I wrote..     

             

               

            The problem is, that the pin is never set high, which probably means that the interupts routine doesn’t work.     

             

               

            I am using a starter kit PSoC3.     

             

               

             

               

            #include <project.h>     

             

               

             

               

             

               

             

               

             

               

            CY_ISR(isr_1_Comp_1)     

             

               

            {     

             

               

            CyPins_SetPin(LED_enable_0); // set pin high.     

             

               

                           

             

               

            }     

             

               

             

               

            void Init()     

             

               

            {     

             

               

            isr_1_StartEx(isr_1_Comp_1);         

             

               

            TIA_2_Start();     

             

               

            Comp_1_Start();     

             

               

            VDAC8_1_Start();          

             

               

            }     

             

               

             

               

            int main()     

             

               

            {     

             

               

                           

             

               

                       Init();     

             

               

             

               

            }    

            • 3. Re: PSoC-Dark sensor.
              user_14586677

              At least one problem is that you enter main(), do the init, then

                 

              fall out of main() into never never land. You need to place an

                 

              infinite loop after the init in main(), something like

                 

              for(;;){ }

                 

              or

                 

              while( 1 ) { }

                 

               

                 

              Also consider posting project for rest to be looked at -

                 

               

                 

                  

                 

                        

                 

              “File”

                 

              “Create Workspace Bundle”

                 

               

                 

              Use firefox or IE, not chrome to post.

                 

               

                 

              Regards, Dana.

              • 4. Re: PSoC-Dark sensor.
                erkiii.beerg
                        Hi again I created a bundle. I do still have the same problem with the interrupt not working, also after adding a while-loop.   
                • 5. Re: PSoC-Dark sensor.
                  user_1377889

                  I would suggest you to add an analog pin to the output of the TIA and measure the voltage. The TIA is inverting, I'm not quite sure if the polarity is right.

                     

                   

                     

                  Bob

                  • 6. Re: PSoC-Dark sensor.
                    user_14586677

                    This seems to work. I changed order of components starts to avoid

                       

                    a spurious ISR. Note once you set LED on with ISR, you have no

                       

                    code to turn it off.

                       

                     

                       

                    CY_ISR( isr_1_Comp_1 )  {

                        CyPins_SetPin( LED_enable_0 );         // set pin high if Compator trips
                    //    LED_enable_Write(1);
                       
                    }

                    void Init( void ) {
                       
                        TIA_2_Start();                        // Start TIA and VDAC8 first, before Comparator,
                        VDAC8_1_Start();                     // to avoid spurious interrupt
                        Comp_1_Start();                     // Start Comparator
                       
                        isr_1_StartEx( isr_1_Comp_1 );        // Start Comparator ISR
                       
                    }

                    int main() {
                       
                        Init();                                // Turn on components and enable comparator ISR
                       
                        CyGlobalIntEnable;                    // Enable global interrupts
                       

                        while(1) {        }                    // Loop forever, processing any ISRs
                       
                    }

                    • 7. Re: PSoC-Dark sensor.
                      erkiii.beerg

                       Hi thanks for the replies

                         

                      I am bit confused if this is going to work.     

                       

                         

                      So if anybody else has some idea, how I could make a simple darksensor , it could be great.      

                       

                      • 8. Re: PSoC-Dark sensor.
                        user_1377889

                        Since you have got a PSoC you are not limited at all. The signal conditioning with a TIA and optional a PGA is the first step.

                           

                        Next you may do a ADC and compare the result to a given treshold.

                           

                        To make the project more comfortable:

                           

                        Design a push-button to tell your device "This is the dark treshold" and remember that in EEProm.

                           

                         

                           

                        Bob

                        • 9. Re: PSoC-Dark sensor.
                          user_14586677

                          The conversion G of the TIA is its fdbk R.                 http://en.wikipedia.org/wiki/Transimpedance_amplifier

                             

                           

                             

                          Are you trying to measure abvsolute light level, or just simply turn something on/off

                             

                          based on a simple sensor like a reverse biased diode ? If the former calibrated

                             

                          sensors are available from Avago, Rohm, Vishay, and others. If latter just a comparator

                             

                          and TIA is generally more than enough. In fact you could eliminate TIA easily by using

                             

                          a R based photocell, like a cadmium type cell controling input level in a divider to

                             

                          comparator. Set the comparator up with hysterisis in this configuration.

                             

                           

                             

                              

                             

                                    http://en.wikipedia.org/wiki/Photoresistor

                             

                           

                             

                          Regards, Dana.

                             

                           

                             

                          Representative example (photo could be cadmium or diode or photo tranistor, shown w/o hysterisis) -

                             

                           

                             

                          • 10. Re: PSoC-Dark sensor.
                            erkiii.beerg

                            I want to implement the whole thing on the PSoC3.  It should be pretty precise, but basically the purpose it turn light on/off.     

                             

                               

                            What about sampling with an ADC?      

                             

                            • 11. Re: PSoC-Dark sensor.
                              user_14586677

                              If by precise is you need a known light level at which it trips, the following

                                 

                              could be used -

                                 

                               

                                 

                              1) Assumptions, you use an uncalibrated cheap sensor, like diode or CDS photocell or

                                 

                              photo transistor. This means you have to calibrate to the trip level you want the product

                                 

                              to ship. A simple test during production test.

                                 

                              2) To sense all you need is a Comparator. But to do cal two approaches -

                                 

                                     a. Use A/D and TIA to develop signal for A/D. Press a button during production test

                                 

                                         and using A/D read a calibrated light source, and store that value in EEPROM.

                                 

                                         Then future readings with A/D will compare current reading to cal reading to make

                                 

                                          determination. You might not need TIA if you use CDS in a simple R divider to

                                 

                                          input into A/D.

                                 

                                     b. Use sensor + comparator + VDAC8. VDAC8 used to provide offset to comparator.

                                 

                                         During production test with calibrated light source slew VDAC8 value until it trips,

                                 

                                         store that in EE, and everytime product is powered on it reads the EE value and

                                 

                                         and writes this to VDAC8 once to offset the comparator trip point.

                                 

                              Regards, Dana.

                              • 12. Re: PSoC-Dark sensor.
                                user_14586677

                                This might be useful as well -

                                   

                                 

                                   

                                    

                                   

                                          

                                   

                                http://www.johnloomis.org/ece445/topics/egginc/tp4.html

                                   

                                http://www.rohm.com/documents/11308/12928/CNA09016_wp.pdf

                                   

                                 

                                   

                                 

                                   

                                Regards, Dana.