1 2 Previous Next 19 Replies Latest reply on Sep 13, 2016 1:24 AM by prabhu05fe_1711731

    How to configure button / timer for 2 sec and 5 sec interrupt in PSOC3

    prabhu05fe_1711731

      Hello Everyone,

         

       

         

      I am started working on the PSOSC 3 EVB i would like to configure timer for 2sec and 5 sec interrupt (button press detection) so i cant able to execute both logic in an simple way so i request can anyone provide me some suggestions or ideas or examples how to configure the timer to detect the button pressed for 2 sec follwed by the interrupt exection and then 5 sec button press followed by timer interrupt  execution any hlep will be greatly aprreciated

         

       

         

      Thank you

         

      prabhu

         

        • 1. Re: How to configure button / timer for 2 sec and 5 sec interrupt in PSOC3
          user_1377889

          Welcome in the forum prabhu!

             

          Easiest would be to use 2 timer components, one for 2 seconds delay, the other for 5 seconds.

             

           

             

          Bob

          • 2. Re: How to configure button / timer for 2 sec and 5 sec interrupt in PSOC3
            prabhu05fe_1711731

            Hello Bob

               

             

               

            Thnak you so much for your kind reply i have attached the picture of my timer and switch top design schematics but i didnot able to configure properly 

               

            psoc creator3.0 am using to design the top design,

               

            in the timer there is period section which accepts max of 256 only but  i did not understand where should i place 2 seconds in the timer component and also do i suppose to use terminal count TC or nothing? where shiould i connect the output from switch? interrupt output should be connected to switch or tc ? please provide me some reference designs or suggestions to do the simple 2 seconds timer example so that i can able to cofigure 5 seconds timer by myself and also i can learn how to configure timer component by your help

               

             

               

            Looking forward for your reply

               

             

               

            Thank you

               

            prabhu

            • 3. Re: How to configure button / timer for 2 sec and 5 sec interrupt in PSOC3
              user_1377889

              prabhu, can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
              Creator->File->Create Workspace Bundle (minimal)
              and attach the resulting file.

                 

               

                 

              Bob

              • 4. Re: How to configure button / timer for 2 sec and 5 sec interrupt in PSOC3
                prabhu05fe_1711731

                Hello Bob

                   

                Thank you for your kind reply actually what am trying to do in thsi project press the button for 2 seconds and it will turn on the device and then press the button four times whent he button press the reached the fifth press and then it will reset the device could you please chack my project and let me know what should i modify or to do to achieve this specificatiosn

                   

                 

                   

                Thank you

                   

                prabhu

                • 5. Re: How to configure button / timer for 2 sec and 5 sec interrupt in PSOC3
                  user_1377889

                  Yes, I understood, but where is your project bundle?

                     

                   

                     

                  Bob

                  • 6. Re: How to configure button / timer for 2 sec and 5 sec interrupt in PSOC3
                    prabhu05fe_1711731

                    yes i have already attached in my top question please check it anyhow i have uploaded once again

                       

                    prabhu

                    • 7. Re: How to configure button / timer for 2 sec and 5 sec interrupt in PSOC3
                      user_1377889

                      Avoid lengthy code in interrupt handlers. Especially for the 8051 core this will not work.

                         

                      Use code as I outlined it. Better do not make changes in the generated files. Use _StartEx() instead or the newer macro callback feature.

                         

                      Do not forget to clear the interrupts: The timer needs a status register read to reset the tc flag.

                         

                      Your components are a bit outdated. Use latest Creator 3.3 CP3 and update your components (under Project -> Update...)

                         

                      You may set all your SCREEN_DBn to use one port. Then you can save the control register and write to the port at once.

                         

                       

                         

                      Happy coding

                         

                      Bob

                      • 8. Re: How to configure button / timer for 2 sec and 5 sec interrupt in PSOC3
                        prabhu05fe_1711731

                        Hello Bob

                           

                         

                           

                        Thank you so much for your kind reply i did not quite  able to understand your topdesign especially timer 

                           

                        in the timer configuration you set TC bu the TC is not not connected to either switch or anything else and also in the period section it is mentioned 200(unknown source what does it meant by 200?) could you please tell me exact functionality of the timer that you ahve added in the top design because i would like to add the timer for 2 seconds

                           

                        I have modified my program and also the interrupt section  reduce the amount of codes

                           

                        STEP1)while during the switch press it is displaying name in the LCD and during the first time button release it is displaying the LOGO

                           

                        STEP2) while pressing the switch second time it is searching for UMTS and further switch press thirs time started searching the 2G/GSM

                           

                        but the real issue is when i press the switch for thr fourth time it is still searching only 2G networks but i wanted to change the 3G network what is going wrong on my design?

                           

                        mainly the fourth switch press suppose to happen within 5 seconds that is i would like make interrupt function to change from 3G to 2G or 2g/3g within 5 seconds what amm doing wrong in my top design or in my source code could you please cross check and provide me some necessary guidance?

                           

                        i have attached my updated code

                           

                        Thank you

                           

                        prabhu

                        • 9. Re: How to configure button / timer for 2 sec and 5 sec interrupt in PSOC3
                          user_1377889

                          In the timer configuration you set TC bu the TC is not not connected

                             

                          I set the generating of an interrupt to terminal count (TC)

                             

                          The clock for the timer is your 100ms clock. Period is 200, so this will be 100ms*200 = 2s

                             

                           

                             

                          Switches tend to bounce. Best would be to wait after a switch interrupt happened for 100ms and see if the input is still low. Do not wait in the interrupt handler!!!

                             

                           

                             

                          I do not understand your 2G/3G mimic, this you will need to solve yourself. Sounds a bit like a state machine which is solved best using a switch statement with cases.

                             

                           

                             

                          Bob

                          • 10. Re: How to configure button / timer for 2 sec and 5 sec interrupt in PSOC3
                            prabhu05fe_1711731

                            Hello Bob 

                               

                            Could you please suggest me some possible best ways to handle the button press based on your guidance i am continuing to proceed further in my project 

                               

                            my questions about switch handling are:
                            int main()
                            {
                                InitializeSystem();
                                for(;;)
                                {
                                        
                                   if(SwitchPressed)   
                                    {   
                                        HandleSwitch();
                                        SwitchPressed = 0;
                                    }
                                            
                                }
                            }

                               

                            Initialized the switch press  like above in the main function  during the switch press  for the first time it is getting executed properly calling the handleswitch() but after the first time i dont want my switch press to call the handleswitch() fucntion  rather i would like call another function so what should i do to handle the switch in this way can you suggest me some ideas? please

                               

                             

                               

                            Thank you

                               

                            prabhu

                            • 11. Re: How to configure button / timer for 2 sec and 5 sec interrupt in PSOC3
                              user_1377889

                              Program a state machine in HandleSwitch as

                                 

                              static uint SwitchState = 0;

                                 

                                  switch(++SwitchState)

                                 

                                  {

                                 

                                  case 1: Dothis();

                                 

                                      break;

                                 

                                  case 2: DoThat()

                                 

                                      break;

                                 

                                 case 3: DoNothing();

                                 

                                      SwitchState = 0;   // Begin new cycle

                                 

                                  default:

                                 

                                      SwitchState = 0;    //  Recover from unknown state

                                 

                                  }

                                 

                               

                                 

                               

                                 

                              Bob

                              • 12. Re: How to configure button / timer for 2 sec and 5 sec interrupt in PSOC3
                                prabhu05fe_1711731

                                Thank you for your reply actually i have did already exactly the same logic as you told but i would like to add the timer for 5 sec when the timer reaches the 5 sec then it should call the interrupt and verify  whether am i case 1 or case 2 (handle switch)then if i am in case 1 or case 2 it should call another function(like yesterday 2g/3g functions)and then clear the timer interrupt in order to that could you propose me some ideas or could you please verify my above attached code please help me am blocked completely

                                   

                                 

                                   

                                thank you

                                   

                                prabhu

                                   

                                after the first

                                • 13. Re: How to configure button / timer for 2 sec and 5 sec interrupt in PSOC3
                                  user_1377889

                                  After a timer is initialized (Enable() API) there are two points of interest:

                                     

                                  The starting point and the point where the timer is stopped. Stopping can be done in the interrupt handler where additionally the count value should be set to its initial value. So it can be started again. The clearing of the timer interrupt always should be the first thing to do in the handler.

                                     

                                  In your special case:

                                     

                                  Make the state variable a volatile global one, so that it can be checked and set by different functions. When you determine "if i am in case 1 or case 2 it should call another function" set the state variable to indicate this situation and react accordingly in HandleSwitch to the new state (take care, in my example I am adding 1 to the state before checking it!)

                                     

                                   

                                     

                                  Bob

                                  • 14. Re: How to configure button / timer for 2 sec and 5 sec interrupt in PSOC3
                                    prabhu05fe_1711731

                                    Hello Bob

                                       

                                    Thank you for your kind reply since yesterday  i have been working on to implement the logic of 5 Sec Timer and button handler my button is working as expected but the Timer 5sec is not functioning anymore  it is not detecting at the end of 5 sec which case am i either case 1 or case2? could you please verify my timer configuration and my updated program i have added comment on each section it could help you to understand my program please check my timer 5 sec configuration and program 

                                       

                                    looking forward for your reply 

                                       

                                    thank you

                                       

                                    prabhu

                                    1 2 Previous Next