Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 05:49 12 Nov 2025 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 : MM.RESTART like MM.WATCHDOG?

Author Message
sagt3k

Guru

Joined: 01/02/2015
Location: Italy
Posts: 313
Posted: 06:51am 29 Nov 2018
Copy link to clipboard 
Print this post

Hi Geoff

Is it possible to have a variable like MM.WATCHDOG but increased +1 after the instruction CPU RESTART?

Thanks
Antonio
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1646
Posted: 07:27am 29 Nov 2018
Copy link to clipboard 
Print this post

Antonio,

Would something like this suit your purpose?

'
DIM CPU_Starts% = 0
VAR RESTORE
CPU_Starts% = CPU_Starts + 1
IF CPU_Starts% <= 10 THEN
VAR SAVE
END IF
'


If this is put near the start of your program CPU_Starts% will record the number of times the program has restarted. I've chosen a limit of 10 to save the flash from over-use.

It might be a problem if you are using VAR SAVE and VAR RESTORE elsewhere in your program.

Bill
Keep safe. Live long and prosper.
 
sagt3k

Guru

Joined: 01/02/2015
Location: Italy
Posts: 313
Posted: 08:07am 29 Nov 2018
Copy link to clipboard 
Print this post

Hi Bill
Thanks, I already use this method, I just wanted to know if it was useful and implementable MM.RESTART in RAM. Is CPU RESTART a HW reset or SW reset?

AntonioEdited by sagt3k 2018-11-30
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1646
Posted: 09:01am 29 Nov 2018
Copy link to clipboard 
Print this post

OK Antonio,

But your query did make me realise that it would be good to have a way of knowing if a watchdog (internal or external) was operated and how many times it has. In a slave device, this could be reported to the master.

Bill
Keep safe. Live long and prosper.
 
sagt3k

Guru

Joined: 01/02/2015
Location: Italy
Posts: 313
Posted: 09:23am 29 Nov 2018
Copy link to clipboard 
Print this post

Hi Bill

Exact , it would be convenient to have a variable RAM (integer) that is not affected by a sw reset.

Take for example simple IOT remote device. You put it in inaccessible places, maybe you've never had power problems, but for reasons of logic code you had watchdog and cpu restart, then after you connect a uart and you would like to know how many times the micro has restarted.

Ok, you could use the RAM/EPROM of other devices/i2c, but it would increase the costs and complexity of the circuit.

AntonioEdited by sagt3k 2018-11-30
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10572
Posted: 09:36am 29 Nov 2018
Copy link to clipboard 
Print this post

  Quote  Exact , it would be convenient to have a variable RAM (integer) that is not affected by a sw reset.


This should certainly be possible and sounds like a useful idea. I'll have a play on the MMX as part of the 5.05.01 update and report back.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 11:06am 29 Nov 2018
Copy link to clipboard 
Print this post

It is possible (and easy to do). The syntax would be challenging.

Perhaps something like:
MM.KEEPVALUE = nn
CPU RESET
...
PRINT MM.KEEPVALUE

Geoff
Geoff Graham - http://geoffg.net
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10572
Posted: 11:15am 29 Nov 2018
Copy link to clipboard 
Print this post

Just implemented in the latest MMX firmware

  Quote  It includes a new function and command MM.PERSIST. MM.PERSIST is an integer variable that is not affected by CPU RESTART or a watchdog restart. So you can assign a value to it.

MM.PERSIST=123

then restart

CPU RESTART

then use the variable

? MM.PERSIST


long long int saved_variable __attribute__ ((persistent));
void fun_persist(void){
iret = saved_variable;
targ = T_INT;
}
void cmd_persist(void) {
while(*cmdline && tokenfunction(*cmdline) != op_equal) cmdline++;
if(!*cmdline) error("Syntax");
saved_variable = getinteger(++cmdline);
}
Edited by matherp 2018-11-30
 
sagt3k

Guru

Joined: 01/02/2015
Location: Italy
Posts: 313
Posted: 11:56am 29 Nov 2018
Copy link to clipboard 
Print this post

Hi Geoff & matherph

Thanks , but will it be available on all MMbasic family PIC32,MMX,STM32 ?

Thanks
Antonio

 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025