DEBUG Sleep ISR with ICE CUBE

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

 Hi everyone,

   


I'm debugging the Sleep ISR code I implement for knowing if it runs well!I'm using a ICE cube...
I would like to do that the PSoC 1 sleeps during X time (20 seconds for example) and wakes up after this time to do an interruption rutine (1 Hz, choosen) to get data from ADC and save it in the eeprom. After the interruption, sleep another time...

As I could see with the debugger is when the program starts goes to MC8 to sleep, when I pressed f5, goes to the interruption and when its has done, return to sleep MC8. In this moment, the ICE cube appears disconnect, but the board CY3215-DK (miniboard) was turning up the 4 leds like a random way.

I don't know if is possible to do what I want and if is possible to debugger too. I use the function "SleepTimer_SetTimer(bticks)" where bticks=20.

Is it possible to debug a Sleep ISR in real time? How can I know that all runs well and do what I want?


Thanks for your feedbacks!

0 Likes
1 Solution
Anonymous
Not applicable

 Hi Graa,

   

Thanks for your fast response, again!

   

I did similar as you told me, but I implemented an ISR SleepTimer.

   

My code is similar as:

   

#pragma interrupt_handler SleepISR

   

void SleepISR(void)

   

{

   

//here I putted the code I would like to do the PSoC when the interrup is produced

   

M8C_ClearWDTAndSleep;

   

return;

   

}

   

void main(void)

   

{

   

int bticks=20;

   

M8C_EnableIntMask(INT_MSK0, INT_MSK0_SLEEP);

   

M8C_EnableGInt;

   

SleepTimer_EnableInt;

   

SleepTimer_Start;

   

SleepTimer_SetTimer(bticks); 

   

   

wile(1)

   

{

   

   

M8C_Sleep;

   

}

   

}

   

Does this code do the same as you told me? What's the difference in using the ISR Sleep Timer?

   

 

   

Thanks for your help!

View solution in original post

0 Likes
10 Replies
MR_41
Employee
Employee
First like received

Unfortunately, the debugger disconnects when M8C_Sleep is executed.  This is because the IMO stops when the processor goes to sleep and the debugger needs the IMO to maintain the connection with the pod.

For debugging you can replace the M8C_Sleep instruction with the below instructions.

while(!(INT_CLR0 & INT_MSK0_SLEEP));
M8C_ClearIntFlag(INT_CLR0, INT_MSK0_SLEEP);

What this code does is it loops till a sleep interrupt is generated and clears the interrupt flag in the INT_CLR0 register.  When you are done debugging, put back the M8C_Sleep instruction.

Best Regards,
Ganesh
The PSoC Hacker

0 Likes
Anonymous
Not applicable

Hello,

   

 

   

   

 

   

So helpful has been your fast response ...

Therefore, as it is configured now, if I powered by a 5V battery the PSoC would be an interruption every 20 seconds? I am using the function: SleepTimer_SetTimer (bticks). It is not clear to me if this function produces it or is better to use 
    SleepTimer_WaitTimer (bticks). With bticks=20 and SleepTimer= 1Hz.   
Which function does what I want? I implemented the first one because I wanted the M8C sleep all the time and only every 20 seconds to wake up it to make a routine ... In addition, there is a maximum value of bticks?

Thank you very much for your feedbacks!
0 Likes
MR_41
Employee
Employee
First like received

The SleepTimer user module does not put the processor to low power mode.  It just uses the Sleep Timer interrupt to generate various timing functions.  Do not get confused with the name SleepTimer.  The sleep timer is just a clock that can be run at 1Hz, 8Hz, 16Hz or 64Hz.  The SleepTimer user module just uses this clock and implements various timing functions.

For letting the processor to sleep 20 seconds, this is one approach you could take.

1. Configure the Sleep interval in the Global Resources to 1Hz.
2. Enable the Sleep interrupt
3. Use a variable bSleepTick to count Sleep interrupts.  You would initialize this to the number of Sleep interrupts that you want the processor to be in low power
4. Inside the while loop use a code like below:

while(1)
{
   bSleepTick = 20;
   while (bSleepTick != 0)
   {
      M8C_Sleep;
      bSleepTick--;
   }
  
   // Write code here that you would like to execute once 20 seconds
}

In the above code, every 1 second, processor will wake up and decrement the bSleepTick variable.  If it is not zero, processor will go back to sleep.  When the variable becomes zero, it will execute the code that is below the while(bSleepTick !=0) loop.

Hope this helps.

Best Regards,
Ganesh
The PSoc Hacker

0 Likes
Anonymous
Not applicable

 Hi Graa,

   

Thanks for your fast response, again!

   

I did similar as you told me, but I implemented an ISR SleepTimer.

   

My code is similar as:

   

#pragma interrupt_handler SleepISR

   

void SleepISR(void)

   

{

   

//here I putted the code I would like to do the PSoC when the interrup is produced

   

M8C_ClearWDTAndSleep;

   

return;

   

}

   

void main(void)

   

{

   

int bticks=20;

   

M8C_EnableIntMask(INT_MSK0, INT_MSK0_SLEEP);

   

M8C_EnableGInt;

   

SleepTimer_EnableInt;

   

SleepTimer_Start;

   

SleepTimer_SetTimer(bticks); 

   

   

wile(1)

   

{

   

   

M8C_Sleep;

   

}

   

}

   

Does this code do the same as you told me? What's the difference in using the ISR Sleep Timer?

   

 

   

Thanks for your help!

0 Likes
MR_41
Employee
Employee
First like received

This method also will work.  However it is not adviceable to have your complete code inside the Sleep ISR.  For example, if you have other interrupts in your code, these interrupts will not work as global interrupt is disabled when the Sleep ISR is entered.  That is why it is preferable to execute all the code in the foreground.

   


   

Best Regards,

   

Ganesh

0 Likes
Anonymous
Not applicable

Hi graa,

   


   

thanks again for your help!

   

I told you that because I had only one interruption (Sleep Interruption) but, now I understan why you recommend me how to configure it, you are right! Another thing I would like to ask you if  in your code (your example of configuration) is not needed to add :

   

M8C_EnableIntMask(INT_MSK0, INT_MSK0_SLEEP);

   

M8C_EnableGInt;

   

SleepTimer_EnableInt;

   

SleepTimer_Start;

   


   

Before you initialize the value  of bSleepTick. I don't know if is neccesary or is default. This is my last doubt...

   

Thanks for your fast responses!

   

   


0 Likes
MR_41
Employee
Employee
First like received

Yes.  For the example code I posted, you need to enable sleep interrupt by using

M8C_EnableIntMask(INT_MSK0, INT_MSK0_SLEEP);
M8C_EnableGInt;

However, for the method I suggested, it is not necessary to have the SleepTimer user module.  Just set the SleepInterval to 1Hz in the Global Resources in device editor and enable the interrupt using the above code and that should be enough.

Best Regards,
Ganesh

0 Likes
Anonymous
Not applicable

 Hi Graa,

   


   

Thanks for your clarification! I will configure without using the module Sleep Timer as you told me. So,is the same using this metod (without module Sleep Timer) and implementing with it?

   

I guess that the main reason for needing the user module is for making interruptions and the other way is only as a clock, isn't it?

   


   

Thanks for your support!

0 Likes
ravo
Level 5
Level 5
10 likes received 5 comments on blog 5 solutions authored

Dear Ganesh

   

if I replace M8C_Sleep with

   

 

   

   

while(!(INT_CLR0 & INT_MSK0_SLEEP));
M8C_ClearIntFlag(INT_CLR0, INT_MSK0_SLEEP);

   

in this sample code (sleep timer configured 125 msec period - measured on scope):

   

   

while (1)
   {
   M8C_Sleep;
    LED_invert(); 
}

   

to this:

   

while (1)
{
while(!(INT_CLR0 & INT_MSK0_SLEEP));
M8C_ClearIntFlag(INT_CLR0, INT_MSK0_SLEEP);

}

   

than the code is runnig very irregularly...

   

Is it normal, or something is going wrong ?

   

Regards

   

Radim

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Since you cannot debug with an ICE-Cube during sleep-mode because the connection to the ICE is got lost you should do something instead, like using a timed loop, the sleep-timer or a wait-function.

   

When you #ifdef those parts of code to distingush between debug and production will that make your life easier.

   

The beaveour of the code snippets must be different in the second case there is no LED.

   

If you post your complete examples here as a zipped folder we all can have a look at and try to follow your problems better.

   

 

   

ICE is cool

   

Bob

0 Likes