5 Replies Latest reply on Feb 17, 2011 1:00 AM by gautam.das.g

    Getting hibernate figured out


       Hey all,


      I'm building a system that should be able to hibernate for hours/days/weeks at a time and wake up on a low-voltage input from a sensor, and given the example project "Enter Hibernate Mode and Wakeup Using PICU" it looks like I should be able to do that. I've even changed the example project pinout to interface with my sensors, and I can get it to enter/exit hibernate mode with them.

      My only problem is that I just CANNOT figure out how this code works. I'm pretty good with C, less so with this entire embedded system IDE. In the example project, FLAG_HIBERNATE is initially set to 0, and then in the project's while(1) loop, it will enter hibernate mode if FLAG_HIBERNATE is non-zero. But I just don't see where that happens. Can someone explain this?

      Curiously, when I just copy-pasted everything from the example project into a new one, *BOTH* of my pins -- the one I have assigned to the hibernate pin connected to the hibernate interrupt, as well as the one assigned to the wakeup pin connected to the wakeup interrupt -- seem to put the device into hibernate mode, and neither will wake it up. I'm sure there's some interrupt target configuration, or something, somewhere, that I'm missing, but I can't find it.

      Any help would be greatly appreciated!

      Edit: and a bonus question; when I program the example project onto a CY8CKIT-001, the "PSoC development kit," it works as intended. However, when I program it onto a 
      CY8CKIT-014 PSoC 5 FirstTouch Starter Kit, and change the hibernate pin to line up with the FirstTouch's lone button (15_3 or something, I believe), it won't register the hibernate button press. My assumption is that this is because the FirstTouch's button uses a slightly different system (maybe a voltage drop instead of voltage spike? I don't know; I don't have a circuits background), but can anyone tell me how it is different and what I would need to do to overcome that? OR even better, could someone point me towards where I can find the specifications for the buttons on each board? I've looked through the documentation that came with them and can't seem to find anything pertinent.

        • 1. Re: Getting hibernate figured out

          If you open Hibernate.c (ISR file) & Wakeup.c files, you can find that in the Interrupt Service Routine section "FLAG_HIBERNATE" is being set to 1 and 0 respectively.




          What are all the things you copy pasted into another project? It would be better if we could debug the new project.







          • 2. Re: Getting hibernate figured out

            Regarding your question on difference between Switch configurations of CY8CKIT-001 & CY8CKIT-014, yes they both are different.




            In CY8CKIT-001, if you press the switch, Pin will be connected to Ground. So we need to pull it up internally. In CY8CKIT-014, if you press the switch, Pin will be connected to Vdd (3.3V). So we need to pull it down internally.




            If you change the configuration of the GPIOs to Pull downs, it should work.





            • 3. Re: Getting hibernate figured out

              You can refer to the Schematics in the following links:


              CY8CKIT-014 -> http://www.cypress.com/?docID=27015


              CY8CKIT-001 -> http://www.cypress.com/?docID=26945







              • 4. Re: Getting hibernate figured out

                 Hello Kishore,


                Thank you very much for your help. I KNEW there was some sort of interrupt configuration I was missing, and now I see where it is. Before, I had only copied over the main.c file and everything in the TopDesign.cysch; I hadn't thought that components could have useful configurations in their .c files. Now that I have the relevant code in my program's Hibernate.c and Wakeup.c files, it's working just like the example.


                Now here's a follow-up question:


                It looks to me like the way this works is:
                when there's a voltage on either of the pins configured for interrupts, TWO THINGS HAPPEN. First the board wakes up from hibernate (if it was in hibernate) and next, the corresponding Hibernate_Interrupt function runs. This seems right because when the board is in hibernate mode, and you press the button associated with the Hibernate interrupt, the board gets woken up and the FLAG_HIBERNATE integer is set (again) to 1. It runs through the program's while loop once and enters the if (FLAG_HIBERNATE) branch and puts itself to sleep again.


                So first of all, am I correct in that assumption? And second of all, is it possible to configure the board such that only CERTAIN interrupt pins will wake it from hibernate?




                As for my other question, thank you for your explanation -- in the past couple days I've done a bit of research as to how these buttons are actually working, so your answers make sense, and those links were quite helpful.





                • 5. Re: Getting hibernate figured out

                  Hi Jeff,




                  There are 2 interrupts used in the project. One to put the PSoC to Hibernate, and the other for Wakeup.


                  In the ISR associated with Hibernate, the flag FLAG_HIBERNATE is set to 1 upon interrupt.


                  In the ISR associated with Wakeup, the flag FLAG_HIBERNATE is reset (set to 0) upon interrupt.




                  The interrupts are set to falling edge. This is because the pins are set to Resistive pull up and will be High by default. When the switch is pressed, the pin is connected to ground, hence there is a falling edge detected (from high to low). The flag is set to 1 in ISR if Hibernate pin is pressed, resulting in the device going to hibernate. This is done in the main.c .  When the device is already in hibernate, if Hibernate pin is pressed again, the flag is still set to 1, hence the LED will toggle only once and then go back to hibernate.


                  To wake up the PSoC, the Wakeup pin must be pressed. This will reset the flag and the device will be in active mode till the hibernate pin is pressed again.


                  In First touch kit, set the "Interrupt type" in the Pin configuration box to "falling edge" and the "Drive Mode" to "Resistive pull down".




                  You can use PICU by configuring "any" pin available in PSoC to wake up the system from hibernate. There is Sleep mode available too which will wake up from several other sources apart from PICU like Slave Address match in I2C, Sleep Timer, etc.