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:
UART_Debug_PutString("going to sleep ...\r\n");
while(UART_Debug_GetTxBufferSize()) // Wait for the UART to finish
CyDelay(5); // Still needs more time
CyDelay(5); // Needed otherwise UART doesn't work.
What have I forgotten?
Many thanks - Hugo
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.
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.
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.
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.
I added that, but it seemed to make no difference. The first sleep takes about 4s, but subsequent ones pass almost instantly.
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.
Oops.... there is a mistake in the previous code, here is the correct code,
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,
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");
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.
> 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.
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,
Also if you are driving any Pins high or low, make sure(by changing the drive mode) that they are not sinking additional current