1 2 3 Previous Next 41 Replies Latest reply on Oct 26, 2012 3:19 AM by cathal.ferry

    PSoC and key fob

    cathal.ferry

      Hi guys,

         

      Ive been playing around with my 2 button key fob and receiver, and i thought wouldnt it be great to interface it to my Psoc 1.

         

      conected to my psoc are 2 ir beam breakers i made, they currently work with a simple bit of code. I was wanting to make a  simple alarm. it shoud be like this. system on> wait till armed (button 1 of key fob) > armed> do alarm stuff (already done). button 2 of the fob should disarm the alarm whether the alarm was activated or just to disable it even if it wasnt activated.

         

      so do i need to declare something like:

         

      buttonarm==0;

         

      buttondisarm==0;

         

      while buttonarm is not pressed, dont do anything, if it is arm alarm activated

         

      {

         

      do alarm stuff, have this done to monitor ir beam breakers

         

      if the alarm goes off for any reason and buttondisarm is pressed, disable alarm output

         

      }

         

      im 100% sure on how to implement the keyfob

         

      any help is always greatly appreciated.

         

      thanks

        • 1. Re: PSoC and key fob
          cathal.ferry

          Hi, Ive been goign through some old college projects we did and ive come across this code which used capsense, PWM, LCD etc. I cut out the LCD, capasense etc below but could i not modify the code to do something like below?

             

          void main (void) {

             

          int AlarmArmed=FALSE;
           int SystemOn=TRUE;
           int AlarmActive=FALSE;

             

          while(1) {

             

          if (AlarmActive==FALSE) {

             

          if(SystemOn==TRUE) {

             

          SystemOn=FALSE;

             

          AlarmArmed=FALSE;

             

           }

             

          Else if (SystemOn==FALSE) {

             

          SystemOn=True }

             

          }

             

          if ((SystemOn==TRUE)&&(AlarmActive==FALSE))

             

          if (AlarmActivated==FALSE)

             

          {

             

          AlarmArmed=TRUE;

             

          }

             

          else if (AlarmArmed==TRUE) {

             

          AlarmArmed=FALSE;

             

          }

             

          }

             

          if ((SystemOn==TRUE) && (AlarmActivated==TRUE))

             

          {

             

          AlarmActive=TRUE;

             

          }

          • 2. Re: PSoC and key fob
            ki.leung

            1. I would add a key debounce function, and name two variables armKey and disarmKey which were debounced inputs.

               

            2. I would add two variable called systemState (ARMED or DISARMED) and alarmState (ALARM_ON or ALARM_NOT_ON)

               

            You can try to use these to develope your program.

            • 3. Re: PSoC and key fob
              ki.leung

               OK, I am too slow to reponse. :-(

                 

              Shall check your program now.

              • 4. Re: PSoC and key fob
                ki.leung
                1. For others to understand your code, it would be better tto state what are those variables, which are the key inputs? int AlarmArmed=FALSE; /* Key inpput? */ int SystemOn=TRUE; /* TRUE if ....? */  int AlarmActive=FALSE; /* IR broken? */ 2. what is AlarmActivated? 
                   

                     

                 

                • 5. Re: PSoC and key fob
                  cathal.ferry

                  HI,

                     

                  Yes, you are quite right, i basically just opened the project and typed it into the reply page here. Sorry for the misunderstanding,

                     

                  ok I see that code i sent in, is just adding to the confusion,

                     

                  yeah basically i think it would probably be best to work from the requirements in my first post, and ignore the code sent in.

                  • 6. Re: PSoC and key fob
                    ki.leung

                    WE NEED AN EDIT FUNCTION !!!!!!

                       

                    Your program is close to what i suggested. It just need to put comments in so otherS can see what you mean to do.

                       

                    Once you add those comments in , people can see if there are errors or not.

                       

                    But I definely would add the debounce function for the keys.

                       

                    And do you need some kinds of debounce for your IR beam sensor?

                    • 7. Re: PSoC and key fob
                      cathal.ferry

                      hiya Lleung,

                         

                      If it helps i could give you the project files for that code im quoting from.

                         

                      im a little glad that my digging turned somethin up lol.

                         

                      for the moment the IR beam breakers im using are just there as they are neat, i could put anything there, switch etc to provide a high or low signal. debounce might not be neededfor the moment.

                         

                      thanks for replying

                      • 8. Re: PSoC and key fob
                        ki.leung

                        Sure,

                           

                        You can upload your modified project here, doesn't need to be 100% correct.

                           

                        Put your comments there first, people can make suggestion for errors/improvement.

                           

                        Happy coding.

                        • 9. Re: PSoC and key fob
                          cathal.ferry

                          the code i was thinking of uploading has all the capsense, lcd stuff in it and is a good bit more complicated that what im trying to do. all i want to do  is have the code run when i press button a of the fob and stop on button b,

                             

                          the code i have simply checks inputs, using our friend the shadow register and writes and output to port 1.0 which is an led, indicating an output or alarmed state. 

                          • 10. Re: PSoC and key fob
                            cathal.ferry

                            what if i tried to do it this way, could it work?

                               

                            i have a fob input connected to port 1.7, the one i want to disable the alarm with

                               

                            void main(void)

                               

                            while ( PRT1 != 0x80)  // checks fob button isnt pressed, if it is dont run rest of code? effectively not arming device?

                               

                            {

                               

                            code for alarm inputs, simply checks to see if certain ports are high, if not sound alarm

                               

                            }

                               

                             

                               

                            could something like this be implemented?

                            • 11. Re: PSoC and key fob
                              user_1377889

                              An alarm system is a pretty good example for a state-machine and is often used as an example to introduce the "how to"s.

                                 

                              From your former posts I can see that you intentionally are approaching to such a design, so I suggest you to complete it:

                                 

                              Use a variable for the current state and have an enum for all possible states + an unknown state.

                                 

                              Define for each state under which circumstances (one or more signals) another state is reached.

                                 

                              Program a loop which

                                 

                              1st. Gathers all input signals and sets corresponding vars (this isolation makes the system independent from sensor-types and similar differences)

                                 

                               

                                 

                              2nd. enter a switch () block with all possible states and decide in each state which state comes next.

                                 

                               

                                 

                              That's it

                                 

                               

                                 

                              Happy coding

                                 

                              Bob

                              • 12. Re: PSoC and key fob
                                ki.leung

                                Bob's idea is good.

                                   

                                Since this is a simple project, you can start a new project without all other bits and pieces.

                                   

                                I still think you need the debounce for your key, you can use the debouncer component with the latest creator component pack.

                                   

                                Sometime it is much easier to start fresh.

                                • 13. Re: PSoC and key fob
                                  cathal.ferry

                                  using switch and case,

                                     

                                  ive used this with visual basic and console run programs but not using a microcontroller,

                                     

                                  It kind of goes, i think:

                                     
                                  int count0;
                                  int count1;
                                  int count2;
                                  int count3;
                                  int count4;



                                  switch(input) {
                                  case 0: ++count0; break;
                                  case 1: ++count1; break;
                                  case 2: ++count2; break;
                                  case 3: ++count3; break
                                  case 4: ++count4; break; im sure this is really obvious to anyone whos done this but im a little confused about adapting it to my code

                                  • 14. Re: PSoC and key fob
                                    ki.leung

                                    here is the hint:

                                       

                                    switch (systemState)

                                       

                                    {

                                       

                                                case DISARMD:

                                       

                                                        check keys;

                                       

                                                        if armKey presssed

                                       

                                                                clear all outputs;

                                       

                                                                change systemState to ARMED

                                       

                                                        break; 

                                       

                                               case ARMED:

                                       

                                              /* FILLL in what it should be done here */

                                       

                                                       break;

                                       

                                             default:

                                       

                                                       /* FILLL in what it should be done here */

                                       

                                    }

                                    1 2 3 Previous Next