7 Replies Latest reply on Jul 2, 2020 5:41 PM by NoriakiT_91

    Understanding interrupts

    LaAd_4048266

      I am trying to understand interrupts for PSoC 5LP, using Kit-059.

      AN54460 shows the architecture of the interrupt, and is reasonably clear.

       

      For interrupt project 2, section 4.2 PICU Interrupt Project, there are two interrupts:

      PICU interrupt that occurs when a button is pushed thereby changing the port register value

      Tick interrupt that occurs to accomplish de-bouncing (at 1 kHz).

       

      If I understand what's happening:

      the Tick interrupt happens at a 1 kHz rate  (1 ms).

      when a switch is pressed, the PICU interrupt appears to set a countdown variable

      counted down by the Tick interrupt

       

      so, my questions:

      1) please correct my view of what's happening

      2) where do i put my code to be executed when a switch is pressed?

      3) can variables be passed back and forth between the interrupt routines and the main routine? if so, how?

      (or, maybe better, can the interrupt set a flag or value, so that the code can be executed in main, instead of in the interrupt routine?

      4) i am not following the turning on and off of interrupts or maybe i'm not distinguishing between on and off vs set and clear functions

      5) what is the sequence of events (by line number??) before a switch is pushed, when a switch is pushed, and after a switch is pushed?

       

      thank you for your help and patience

        • 1. Re: Understanding interrupts
          MoTa_728816

          Hi,

           

          I wonder if a similar sample of mine can be some hint.

           

          Measuring time interval using SysTick (CY8CKIT-059/CY8CKIT-044)

           

          moto

          • 2. Re: Understanding interrupts
            NoriakiT_91

            Hi,

             

            Please let me answer to your questions.

             

            1) please correct my view of what's happening

            Your understanding is correct.  There are independent interrupt sources Tick and PICU.  Tick is periodically invoked and PICU is invoked when one of the switches is pushed.

             

            2) where do i put my code to be executed when a switch is pressed?

            You can put your code in the Tick_ISR to detect the switch is surely pushed.  Put your code instead of the LEDx_Write() function.

             

            3) can variables be passed back and forth between the interrupt routines and the main routine? if so, how?

            (or, maybe better, can the interrupt set a flag or value, so that the code can be executed in main, instead of in the interrupt routine?

            You can set a flag in the Tick_ISR to indicate a switch is pushed and the flag can be polled in the main loop.  Please note that the flag should be cleared in the main-loop when the flag is processed like

            if (flag) {
                flag = 0;
                // Process something
            }
            

            It is not recommended to write a code consuming long time in the ISR.  If possible, it is better to set a flag in the ISR and the processing is put in the main-loop.

             

            4) i am not following the turning on and off of interrupts or maybe i'm not distinguishing between on and off vs set and clear functions

            I am not clear what your are saying as "on and off"  Do you mean "enable and disable" of interrupts?

             

            5) what is the sequence of events (by line number??) before a switch is pushed, when a switch is pushed, and after a switch is pushed?

            Normally, CPU executes the infinite loop in the main() function.

            When a periodic pulse is received by the isr_2 component, the Tick_ISR is invoked.  This is constant behavior regardless of the switch status.

            When a switch is pushed, the PICU_ISR is invoked to reload the down counter.

            There is no sequence between these ISRs because the interrupt requests are independent.

             

            Regards,

            Noriaki

            2 of 2 people found this helpful
            • 3. Re: Understanding interrupts
              LaAd_4048266

              okay - lets get down to brass tacks

              B_PICU main.c sets up the branching vectors and initializes whatever parameters the interrupts need (which are things PSoC Creator generally takes care of) and enables the interrupts so if whatever condition causes the interrupt happens, the interrupt is executed, for both interrupts,  PICU_ISR and Tick_ISR

              main.c then enables all interrupts via CyGlobalIntEnable.

              it then enters an infinite loop to wait for something to happen to cause an interrupt

               

              Tick_ISR in InterruptRoutines.c looks at the switch timeouts for both switches

              for a switch that was pressed, each time the Tick_ISR is executed (1 kHz repetition rate per the schematic),

              the pressed switch timeout is decremented. when the switch timeout reaches 0, the LED it toggled

              the Tick_isr accomplishes de-bounce by requiring the switch to still be pressed when the timeout has been reached

               

              PICU_ISR in InterruptRoutines.c creates a local variable temp-stat

              temp_stat is loaded with the switch register status when the clear interrupt function is called,

              temp_stat is and-ed with the switch masks to see which of the two switches was pressed AND it must be timed out

              if it is timed out - meaning that the switch was just pressed, the timeout value is set and the ISR is exited

              if it is not timed out, the ISR is exited

               

              so normal operation is the tick routine is executed every millisecond and generally nothing happens

              when a switch is pressed, time out variable is set

              then the tick routine decrements the time out variable to zero, and if the switch is still pressed, the switch has been de-bounced and the LED is toggled

               

              repeat for ever

               

              the de-bounce time is defined in InterruptRoutines.h,

              as are the prototypes of the two interrupt routines

               

              because the goal is to toggle the LEDs when the switch is pressed, there is no need for any code in main.c

              if the purpose of the switch was to change a setting to change the operation of the main program, then either some flags would be set in the ISR, which would be acted upon in main, OR the changes would be made in the ISR, and acted upon in main, depending on ones preferred view of how things should work

               

              did i get the operation of B_PICU correct?

               

              what is the function of CYDATA in PICU_ISR in InterruptRoutines.c?

               

              Thank you

              • 4. Re: Understanding interrupts
                NoriakiT_91

                Your understanding is perfect.

                 

                The MACROs like CYDATA were prepared for a compatibility to the PSoC 3 devices using 8051 CPU.  Some directive keywords are declared in the cytypes.h header file.  Following snapshot is a description of the "PSoC® Creator™ PSoC 3/PSoC 5LP System Reference Guide, Document Number: 002-20976"

                GS004794.png

                 

                Regards,

                Noriaki

                1 of 1 people found this helpful
                • 5. Re: Understanding interrupts
                  LaAd_4048266

                  Thank you

                   

                  As a new, separate issue, I put "PSoC® Creator™ PSoC 3/PSoC 5LP System Reference Guide, Document Number: 002-20976" into the search window of the Cypress home page. There were 5958 results. I stopped looking for the desired document after3 pages.

                   

                  I then put various subsets thereof (PSoC® Creator™ PSoC 3/PSoC 5LP System Reference Guide and PSoC 3/PSoC 5LP System Reference Guide)  into the search window of the Cypress home page. I again got thousands of results.

                  I stopped looking for the document specified after 3 or 4 pages of results for each subset.

                   

                  I put it onto google, and the first result was the cypress page with the document you posted an excerpt from and various prior versions of the CYBOOT document.

                   

                  Thank you

                  • 6. Re: Understanding interrupts
                    BoTa_264741

                    LaAd,

                    If the purpose of this is to detect button press/release events, there is a custom Component available that handles this task:

                    ButtonSw32: button switch debouncer component

                    /odissey1

                    ButtonSw_basic_1b.png

                    • 7. Re: Understanding interrupts
                      NoriakiT_91

                      The System Reference Guides documents are installed with the PSoC Creator.

                      Please select the menu item "Help>System Reference Guides"

                      GS004798.png

                       

                      A local HTML document will open on your browser and guide you to the document.

                      GS004799.png

                       

                      Regards,

                      Noriaki