11 Replies Latest reply on Aug 9, 2017 12:42 AM by JoMe_264151

    Combining two programs

    userc_38467

      I have 2 programs (attached),

         

      One is an on/off program end the other one is an alarm simulation with capsense

         

      on the psoc4 kit.

         

      Now I want to combine these programs.

         

      I've allready tried several combinations, but so far unsuccessfully.

         

      Maybe someone can help me with it?

         

      Some words are in dutch like:

         

      huidigestand means current state

         

      vorigestand means   previous state

         

      TOETS1 means button1

        • 1. Re: Combining two programs
          helic_263931

          Do you want to have a selection (at powerup) which program should run? Or do you want to have a new program combining their functionality?

          • 2. Re: Combining two programs
            userc_38467

            I want to have a new program combining their functionality.

            • 3. Re: Combining two programs
              JoMe_264151

              Part your two projects into functions:

                 

              Initialization() // As the name says

                 

              Perform()  / do the stuff that was in the for(;;) loop

                 

              Check and rename global variables

                 

              Open a new project with two topdesign pages, then copy & paste all the stuff.

                 

              the new main() now will look like

                 

              Initialization1();

                 

              Initialization2();

                 

              for(;;)

                 

              {

                 

              Perform1();

                 

              Perform2();

                 

              }

                 

               

                 

              Bob

              • 4. Re: Combining two programs
                userc_38467

                I have combined the two programs like you suggested.

                   

                The "aan/uit" (on/off) program seems to function OK but when I switch on capsense it keeps on working.

                   

                It's supposed to switch off.

                   

                What did I do wrong?

                • 5. Re: Combining two programs
                  JoMe_264151

                  You didn't the combine as I suggested. I told about different functions, so that one (me) could see what belonged to the first project and what to the other. This makes changes and debugging quite more easier.

                     

                  I strongly suggest to update to Creator 4.1. And following an update of the components.

                     

                  There is an error (flagged as warning) in line 250. You forgot parentheses following the "!"

                     

                   

                     

                  Bob

                  • 6. Re: Combining two programs
                    userc_38467

                    I have made some changes in the program to make it more clear what project 1 and -2 is.

                       

                    Also I have attached a word document of the program and visualized program 1 and -2 with colours.

                       

                    I hope you can identify project 1 and -2 now.

                       

                    By the way I have no warnings on my computer when building and running the program.

                       

                    Leo

                    • 7. Re: Combining two programs
                      JoMe_264151

                      Regarding the warning: Did you already upgrade to Creator 4.1?

                         

                       

                         

                      Bob

                      • 8. Re: Combining two programs
                        userc_38467

                        I did upgrade to Creator 4.1 following an  update of the components.

                           

                        As regarding to warnings , there are none on my computer.

                        • 9. Re: Combining two programs
                          userc_38467

                          I have combined the two programs.

                             

                          The "aan/uit" (on/off) program seems to function OK but when I switch on capsense it keeps on working.

                             

                          It's supposed to switch off.

                             

                          Maybe someone can help me with it?

                             

                          Some words are in dutch like:

                             

                          huidigestand means current state

                             

                          vorigestand means   previous state

                             

                          TOETS1 means button1

                             

                          What did I do wrong?

                          • 10. Re: Combining two programs
                            userc_38467

                            To make the problem I have more clear I have made a new program (attached).

                               

                            There are 2 buttons (S1/S2) and 3 LED's.

                               

                            Button S1 has a memory state, in order to switch LED2 and LED3.

                               

                            Button S2 switches LED1.

                               

                            My problem: How do I get round the memory state of Button S1.

                               

                            Whenever I try to switch on LED1 with S2 , LED2/LED3 have to go off but they don't.

                               

                            Maybe someone can help me with it?

                            • 11. Re: Combining two programs
                              JoMe_264151

                              I am afraid that the error is more of a basic way: You did not write a single line of comment. How do you think you will be able to understand your program or find any bugs when it is not commented!

                                 

                              Your indentation is not following the program flow.

                                 

                              There is still a warning which you could suppress by placing parentheses

                                 

                              Your pins for the switches are floating with high z input. You better declare them as resistor pull up and initially drive high.

                                 

                              I would (personally) get away from the 0xffs and other values and use boolean variables and logic throughout that project. You will need to
                              #define FALSE 0
                              #define TRUE !FALSE

                                 

                              Who will know that writing 0xff to an LED will switch it on or off. In 3 months even you will not be able to tell that ;-) use a #define LEDON and LEDOFF

                                 

                               

                                 

                              Bob