Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 19:08 29 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CPU SLEEP question

     Page 1 of 2    
Author Message
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 02:48am 08 May 2015
Copy link to clipboard 
Print this post

I am not currently in front of any MicroMite to try the following so I am therefore hoping that someone out there is with one so that they may answer a query I have that is 'bugging' me.

The CPU SLEEP command has two different usage 'scenarios'. When used by itself, the MM will go to sleep and only wake up on a change on the 'WAKE' pin.

If it is used in the form CPU SLEEP xx then the MM will sleep for xx seconds and then wake up.

My question is this: If I put the CPU to sleep for xx seconds, then can it also be woken by a change on the WAKE pin OR will it only wake after xx seconds??

Many thanks from anyone that can provide any confirmation regarding this query . . . .

WW
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 02:59am 08 May 2015
Copy link to clipboard 
Print this post

I use the WAKE pin, and the original method was that you could wake it up by a change in state on the WAKE pin.

In the latest firmware, you can still do that, but, as you already know, you can also set it to go to sleep for X number of seconds.

To the best of my knowledge, if you sleep the MM for, say, five seconds, you cannot wake it up before that five second period - it is more of a coma then a sleep, if you get the time wrong!

I have elected to use the old method, and external caps as discussed in a previous thread, as accuracy was not an issue for me - close enough was near enough. Naturally, that will not suit some other members...
Smoke makes things work. When the smoke gets out, it stops!
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2870
Posted: 05:13am 08 May 2015
Copy link to clipboard 
Print this post

Hi Phil,

The easy way was to try it..

I did that and found that if you set a sleep TIME you cannot wake by use of the wake pin

Regards,

Mick


Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 05:52am 08 May 2015
Copy link to clipboard 
Print this post

Thanks guys - not the answer I wanted to hear though

WW
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 02:15pm 08 May 2015
Copy link to clipboard 
Print this post

The reason why the wake pin does not wake the MM when in timeout mode (and this is silly) is that I could not think of a good syntax for specifying BOTH the timeout AND the wake pin together

Does anyone have a good idea?
Geoff Graham - http://geoffg.net
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2289
Posted: 02:18pm 08 May 2015
Copy link to clipboard 
Print this post

one method: use a negative time value to indicate that the wakeup pin should also be active during the sleep period.

ie:
CPU SLEEP -1000
to sleep for 1000mS with wakeup pin also monitored

cheers,
rob :-)Edited by robert.rozee 2015-05-10
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 02:34pm 08 May 2015
Copy link to clipboard 
Print this post

Rob comes up with the logic once again.

That seems like a really nice way to do it.
Simple and elegant.
You could then use CPU SLEEP 1 for a normal un-interruptible sleep, and CPU SLEEP -1 for an interruptible sleep of the same period.

Gets my vote.
Smoke makes things work. When the smoke gets out, it stops!
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2870
Posted: 02:50pm 08 May 2015
Copy link to clipboard 
Print this post

Hi Geoff, All,

or simply,

CPU SLEEP, 1000, WAKE

or

CPU SLEEP, 1000, W

with ,W (inferring Wake Pin) optional


Regards,

Mick




Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 03:39pm 08 May 2015
Copy link to clipboard 
Print this post

I like Mick's syntax with a mod. A zero timeout defines no timeout.

wake pin only
CPU SLEEP,0,W
or timeout only
CPU SLEEP,1000
or combination
CPU SLEEP,1000,W
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 03:46pm 08 May 2015
Copy link to clipboard 
Print this post

Thanks for the responses.

I tend to favour Rob's suggestion. Therefore quoting BobD's examples:

wake pin only
CPU SLEEP,0,W would simply be: CPU SLEEP (i.e. as it currently is)
or timeout only
CPU SLEEP,1000 would simply be: CPU SLEEP 1000 (i.e. as it currently is)
or combination
CPU SLEEP,1000,W would simply be: CPU SLEEP -1000 (as Robs suggestion)

I prefer to minimise lots of commas when they are not needed. I think it may also make Geoff's task easier (remembering a similar topic before where a command became 'messy' with lots of unnecessary commas)

Guess there is plenty for Geoff to consider and hence decide the most appropriate way forward.

Thanks again . . .
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2870
Posted: 01:47pm 09 May 2015
Copy link to clipboard 
Print this post

Gday WW, All,

  WhiteWizzard said  
I prefer to minimise lots of commas when they are not needed.


Firstly commas are used in many MMBasic commands and to move away from using commas is changing `tack' so to speak.

I do not think adding a ,W makes it messy looking in any way.

and

Secondly, I dont see -1000 as really telling the story of what it does like ,W does..

Also if you are using a variable say Sleep_Time you then have to manipulate the variable to include the minus where-as ,W doesnt need Sleep_Time to be changed.

In either case just having the command in whatever form Geoff decides to use would make it a step better than it is already.

Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 03:43pm 09 May 2015
Copy link to clipboard 
Print this post

  bigmik said  Secondly, I dont see -1000 as really telling the story of what it does like ,W does..

Also if you are using a variable say Sleep_Time you then have to manipulate the variable to include the minus where-as ,W doesnt need Sleep_Time to be changed.


Excellent point. I withdraw my vote for Rob's idea(with no disrespect to Rob, naturally) and put it with Mick's.
Smoke makes things work. When the smoke gets out, it stops!
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2289
Posted: 04:14pm 09 May 2015
Copy link to clipboard 
Print this post

i'm not quite sure how CPU SLEEP -T is too difficult to do. there is a long history of using 'invalid' numbers as a flag, in particular where a negative return value from a function indicates an error. but the nicest thing about using a negative parameter is that it requires minimal (if any) changes to the instruction parser within MMbasic. the sleep function, internally, just needs to act upon the negative input.

speaking of negative numbers... might i take the opportunity to push for the inclusion of MM.INTPIN in the next release of micromite basic? where the value returned is the number of the pin that generated an interrupt, and the sign is the polarity of the pin (a positive going or a negative going transition).


cheers,
rob :-)
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 09:03pm 09 May 2015
Copy link to clipboard 
Print this post

  robert.rozee said  ... might i take the opportunity to push for the inclusion of MM.INTPIN in the next release of micromite basic? where the value returned is the number of the pin that generated an interrupt, and the sign is the polarity of the pin (a positive going or a negative going transition).


YES PLEASE
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 03:54am 10 May 2015
Copy link to clipboard 
Print this post

I like the ,W[AKE] idea. It is simple and will not break existing code.

But, why would we need MM.INTPIN? You can specify an interrupt specific to the pin, so you know what the pin is and by using the function PIN() you can find out if it was hi to lo or vice versa. Why clutter the language with something that is not needed?

Geoff (who is always trying to keep the language simple).
Geoff Graham - http://geoffg.net
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 04:08am 10 May 2015
Copy link to clipboard 
Print this post

I think it is so you can find out which pin caused an interrupt if you don't know which one it was - if you have several interrupted pins, for example, it would probably be handy to know which one was the LAST one to cause an interrupt.

I might not be understanding things right - it is 2AM.
Smoke makes things work. When the smoke gets out, it stops!
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2289
Posted: 04:08am 10 May 2015
Copy link to clipboard 
Print this post

it enables a single interrupt handler to service a number of pins that may be used for similar functions (for instance, sensing switch inputs) leading to much more compact and clear code. also, reading the pin directly within the handler - i surmise - is not totally reliable, as a short pulse on a pin could be gone by the time control has been transferred to the handler. the value of MM.INTPIN would be latched prior to the handler being called, and only cleared when the handler exits.


cheers,
rob :-)
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 06:49am 10 May 2015
Copy link to clipboard 
Print this post

@Geoff,

I would use a MM.INTPIN value to determine which actual pin caused an interrupt when using very short 'pulse' interrupts. As Rob highlights, if the interrupt pin has already changed state before the Int Service Routine processes things then it is impossible to find out which pin actually caused the interrupt.

If there is another way to do this then there is no need for a MM>INTPIN but I don't think there is.

WW



For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 08:03am 10 May 2015
Copy link to clipboard 
Print this post

@ Geoff,

I now see why you said your reason originally for not waking after an elapsed time OR the wake pin when the CPU SLEEP command was issued.

So if you want to wake the MM on the Wake Pin only; do you use:
1> CPU SLEEP (as it currently is)
2> CPU SLEEP,W (to include the 'W' as you say you like)
3> CPU SLEEP,0,W (as suggested by BobD)
4> CPU SLEEP,,W (no timeout required so leave parameter out - but still need the double comma)
5> anything else?

And if you want to wake the MM after a pre-determined time only; do you use:
6> CPU SLEEP 1000 (as it currently is)
7> CPU SLEEP,,1000 (logical if going with option 2 above - need the double comma if the W is the first parameter))
8> CPU SLEEP,1000 (logical if going with option 3 or 4 above)
9> anything else?

Finally, if you want to do timed Wake AND monitor the Wake Pin (as I ideally require); do you use:
10> CPU SLEEP,1000,W (logical if going with option 3, 4, or 8 above)
11> CPU SLEEP,W,1000 (logical if going with option 2 or 7 above)

Is a comma needed? What about brackets to 'contain' the parameters?
Can I propose:
1> Wake pin only: CPU SLEEP
2> Timed only: CPU SLEEP(1000)
3> Both: CPU SLEEP(1000,W)

I know this may spark a debate (hopefully!!) but open to 'comments'. Please note I don't know the level of 'impact' on the firmwares code so will need Geoff's response to say which is easy and/or least impact.
Personally I still think CPU SLEEP -1000 is the easiest and most logical - no commas or brackets but understand the usefulness of a 'W' in the command somewhere.
CPU SNOOZE . . . . .


For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 01:17pm 10 May 2015
Copy link to clipboard 
Print this post

MMBasic treats CPU SLEEP as a single command, so a comma is not needed after the SLEEP keyword.

I think that the cleanest syntax is:
CPU SLEEP
CPU SLEEP 1000
CPU SLEEP 1000, WAKE
The latter would wake up after 1000mS or on a change on the WAKE pin (whichever occurred first).

Geoff
Geoff Graham - http://geoffg.net
 
     Page 1 of 2    
Print this page
© JAQ Software 2024