cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1

HuEl_264296
New Contributor II

Hi,

   

I am trying to use sleep mode, but I'm experiencing two problems:

   

1. Only the first sleep seems to work. Subsequent sleep commands seem to pass instantly.

   

2. Even that first working sleep seems to be the wrong length of time.

   

 

   

Here is my code:

   

 

   

void main()
{
    UART_Debug_Start();
   
    UART_Debug_PutString("\r\nHello\r\n");
    CyDelay(2000);

    while(1)
    {
        UART_Debug_PutString("going to sleep ...\r\n");
        while(UART_Debug_GetTxBufferSize())                  // Wait for the UART to finish
        {
        }
        CyDelay(5);                                          // Still needs more time
       
        UART_Debug_Sleep();
       
        CyPmSaveClocks();
        CyPmSleep(PM_SLEEP_TIME_CTW_4096MS, PM_SLEEP_SRC_NONE);
        CyPmReadStatus();
        CyPmRestoreClocks();

        UART_Debug_Wakeup();

        CyDelay(5);                                          // Needed otherwise UART doesn't work.
        UART_Debug_PutString("...woken up\r\n");
        CyDelay(4096);
    }
}

   

 

   

What have I forgotten?

   

Many thanks - Hugo

0 Likes
22 Replies
Anonymous
Not applicable

Is the project built for PSoC3 or PSoC5 ?

0 Likes
HuEl_264296
New Contributor II

PSoC 3. Sorry, forgot to mention that.

0 Likes
Anonymous
Not applicable

Hi Rocketmagnet,

   

 

   

I haven't tried the code which you have put up yet. But the length of the Sleep time may not be exactly 4096ms as the Internal 1kHz Oscillator has a comparitively larger tolerance than the internal IMO.

0 Likes
HuEl_264296
New Contributor II

 It's not that the sleep time isn't exactly 4096ms, it that the sleep time is closer to 50ms. I.E. it's waking up immediately from sleep.

0 Likes
Bob_Marlowe
Expert II

Hi,

   

it comes to my mind, that your questioning about a complete transfer of data my not be correct, you just ask, if the allocated buffer has been transfered to the UART-Fifo. This seemingly is the reason for some of your delays you inserted and commented them as neccessary.

   

I would (but didn't try) to use the UART_ReadTxStatus() function and mask out the values for FiFo empty and Tx complete to be sure that the UART has finished all characters.

   

I don't think that this is the source of your sleep-malfunction, but so you can get rid of all your CyDelays.

   

Happy coding

   

Bob

0 Likes
HuEl_264296
New Contributor II

Thanks Bob, I'll try that.

   

 

   

Does anyone have any thoughts on the sleep problem?

0 Likes
Bob_Marlowe
Expert II

Well, in the back of my mind I have the idea that an interrupt is disturbing the "going to sleep". What happens, when you just toggle a LED when sleeping (switch off, before and switch on when awaken) and comment-out all the UART-stuff. When that doesn't work there's something wrong with your CyPmSleep parameters. Else something is horrorbly bad with your UART.

   

Bob

0 Likes
Anonymous
Not applicable

The thing that I observe here is, the API call CyPmReadStatus()does not seem to have any parameters. Can you try this,

   

CyPmReadStatus(CY_PM_CTW_INT);

0 Likes
Bob_Marlowe
Expert II

Where is your global interrupt enable     CYGlobalIntEnable ?

   

Bob

0 Likes
HuEl_264296
New Contributor II

 > CyPmReadStatus(CY_PM_CTW_INT);

   

 

   

Thanks, I'll try this tonight.

0 Likes
Bob_Marlowe
Expert II

I built a test-project to check an UART for complete transmission, use as you like.

   

Happy coding

   

Bob

0 Likes
HuEl_264296
New Contributor II

Bob,

   

CyPmReadStatus(CY_PM_CTW_INT);

   

 

   

I added that, but it seemed to make no difference. The first sleep takes about 4s, but subsequent ones pass almost instantly.

   

 

   

Hugo

0 Likes
HuEl_264296
New Contributor II

Are there any online examples of sleep working?

0 Likes
Bob_Marlowe
Expert II

I tried a VERY simple example (Led switch, sleep ) and couldn't get it to work either.

   

Kit 001, PSoC 5 processor module.

   

Bob

0 Likes
HuEl_264296
New Contributor II

Hmm, interesting. I wonder if it works at all. I notice that Cypress has removed the application note about sleeping / wake from CTW.

0 Likes
Anonymous
Not applicable

The CTW Timer used during Sleep is a free running Timer. The first terminal count(after counting 4096) will be reached when device will be in Sleep mode. This will wake up the device. The second terminal count will be reached before device enters sleep mode, as You have specified 4096 ms delay and Sleep Timer has the same interval configured. Executing CyPmSaveClocks() will make delay interval greater than 4 s. Also take note ot the low power ILO Clock tolerance. So when u call CyPmSleep(), the device will not enter Sleep unless, CyPmReadStatus(CY_PM_CTW_INT)is called to clear the CTW interrupt. 

   

In the following piece of code, the device active only for one second. And before the CTW timer overflows, device is put back to sleep. This code is tested fine to work.

   

   

CyPmSaveClocks();        

   

CyPmSleep(PM_SLEEP_TIME_NONE, PM_SLEEP_SRC_CTW);

   

CyPmReadStatus(CY_PM_CTW_INT );

   

CyPmRestoreClocks();

   

CyDelay(1000);

   

 

   

   
    
   
0 Likes
Anonymous
Not applicable

Oops.... there is a mistake in the previous code, here is the correct code,

   

   

CyPmSaveClocks();        

   

CyPmSleep(PM_SLEEP_TIME_CTW_4096MS, PM_SLEEP_SRC_NONE);

   

CyPmReadStatus(CY_PM_CTW_INT );

   

CyPmRestoreClocks();

   

CyDelay(1000);

0 Likes
Anonymous
Not applicable

There is another way to use the CTW as the Sleep Timer. And that would be throught the Sleep Timer component in PSoC Creator. Place a Sleep Timer Component on the TopDesign, configure it tow wakeup the device aftre particular time(4096ms) . Also paste the  following piece of code,

   

        SleepTimer_1_Start();
CyPmSaveClocks(); 
CyPmSleep(PM_SLEEP_TIME_NONE, PM_SLEEP_SRC_CTW);
CyPmReadStatus(CY_PM_CTW_INT);
CyPmRestoreClocks();
SleepTimer_1_Stop();
CyDelay(4000);

0 Likes
HuEl_264296
New Contributor II

 Thanks U2,

   

That code works correctly.  Now, my last problem is that the chip is still drawing about 14mA during sleep.

   

 

   

The only thing in TopDesign.cysch is the UART which I'm putting to sleep. What else

   

could be drawing so much current?

   

 

   

UART_Debug_PutString("going to sleep ...\r\n");

   

while (UART_Busy());

   

UART_Debug_Sleep();

   

CyPmSaveClocks();

   

CyPmSleep(PM_SLEEP_TIME_CTW_4096MS, PM_SLEEP_SRC_NONE);

   

CyPmReadStatus(CY_PM_CTW_INT );

   

CyPmRestoreClocks();

   

UART_Debug_Wakeup();

   

CyDelay(5);

   

UART_Debug_PutString("...woken up\r\n");

   

CyDelay(1000);

0 Likes
Anonymous
Not applicable

Hi Rocketmagnet,

   

 

   

Can you elaborate on the setup you are using to measure the current consumed by PSoC.

   

If you are using CY8CKIT-001, are you disabling the modules on the board which you are not using in the project like LCD, Potentiometer, etc using jumpers?

   

While measuring the current consumed by the PSoC, you need to isolate the current consumed by other components. In this project you are using UART, the charge pump capacitors used with the voltage converter MAX232 might also consume high currents.

0 Likes
HuEl_264296
New Contributor II

Can you elaborate on the setup you are using to measure the current consumed by PSoC.

   

I'm using a custom made PCB. There are a couple of other components on it, though I thought they were ultra low power consumption. I might have to check those very carefully.

   

 

   

> In this project you are using UART, the charge pump capacitors used with the voltage converter MAX232 might also consume high currents.

   

I'm not using a MAX232. I'm just using a Prolific USB to serial converter. Seems to work ok.

   

 

   

Let me do some more tests and get back to you.

   

 

   

Hugo

0 Likes
Anonymous
Not applicable

Hi Hugo,

   

First you need to isolate the part which is consuming so much current. The best way to go about it is, figure out what is the current consumed by parts other than PSoC when the board is powered. There might be other components in the board that are consuming excess current. Then place PSoC, put the device to sleep and measure the current. The difference between the 2 measurements should give the PSoC Sleep current. You could also try this,

   

Use this API to disable UART interrupts before entering sleep,

   

UART_1_SetRxInterruptMode(0) ;

   

Also if you are driving any Pins high or low, make sure(by changing the drive mode) that they are not sinking additional current

0 Likes