I have run into a scenario where I am managing an external chip that requires me to send a control sequence, wait over a minute, then input the next part of the control sequence. Since busy waiting on the PSOC side would be super wastefull in this scenario.
I have decided it would be far better to place the PSOC into sleep mode instead. However, the maximum sleep time that can be set the CTW is just over 4 seconds. I was wondering in this case, what is normally the best solution? I am thinking about entering sleep mode repeaditly unitl the complete duration has elasped, for example, if I need to sleep for 60 seconds, I would enter and exit sleep mode using the CTW to wake me up (60/4) times.
Would me entering and exiting sleep mode this often cause problems or waste more energy than it's worth? What other strategies exists for trying to sleep longer than what the CTW can allow?
This is a quite usual way, since there is not much to do, just awake from sleep, increment and test the counter and go back to sleep again. Just a matter of some µs.
I appreciate it, and I think I will take you up on your offer than 🙂
Reading the data sheet about setting the sleep timer interval, I read the following
"Sets the CTW interval period. The first interval can range from 1 to (period + 1) milliseconds.
Additional intervals occur at the nominal period. You can only change the interval value
when CTW is disabled, which you can do by stopping the component"
So this means that each time you change the timer interval, its possible that you could receive your interupt from the sleep timer at 1ms into the sleep instead of the nominal value. So if I set the interval to 4096ms and subtracted that from the amount of time I wanted to sleep its possible that I could only sleep for 56 seconds instead of the 60 seconds I was suposed to sleep for.
Would it be possible for me to clear some kind of register to make sure that i sleep closer to the nominal amount of time each time I set the sleep timer interval? I am concerned about sleeping for only 1 ms or on average (sleep interva /2) ms each time I try and set the interval timer.
I am trying to write some code that allows the user to sleep for a specified number of ms. My function essentailly goes into a loop, checks to see if it can sleep for 4096ms, performs the sleep, subtracts that from a counter, then checks again to see if it can sleep for 4096, if it can't it checks to see if it can sleep for 2048, and so on and so forwarth until the correct number of ms has been slept away.
There is no editing feature in this forum software.
And there are no registers afaik to increase the precision of the first interrupt.
A better approach would be to use a much higher interrupt rate (64) and so only the first count of your minute will be a bit off.