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.
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1533
Posted: 07:41am 17 Sep 2014
Copy link to clipboard
Print this post
Hi all!
For my new MAXIMITE project (Quad NIMH Discharger, already working) I want to know if there is a way to reset the PIN and SETPIN status after (or precautions before, respectively) the Ctrl-BREAK automatically. I use "DOUT" to control four MOSFETs. But after a Ctrl-BREAK the DOUT pin is still high and this is not very desirable (Something will be/could be destroyed!) If I call "EDIT" after the Ctrl-BREAK all pins are reseted.
Any ideas to reset the PINs automatically? (Sure, I can disable Ctrl-BREAK)
Bug or feature? I expected Ctrl-BREAK will reset all PINs and close all open files.
I can't see any reason in not resetting all PINs.
Regards and thanks in advance
Michael
causality ≠correlation ≠coincidence
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209
Posted: 08:03am 17 Sep 2014
Copy link to clipboard
Print this post
Normally you can resume running the program after a Ctrl-Break, this would require keeping everything in the state it is at the moment of the Ctrl-Break.
Disabling the Ctrl-Break and ending the program gracefully is i think the only safe option.
Also using a watchdog to make sure your program does not do something unexpected can return the program in a controlled state.
Microblocks. Build with logic.
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1533
Posted: 09:25am 17 Sep 2014
Copy link to clipboard
Print this post
Thanks a lot @TZAdvantage for your very quick and competent answer.
Your answer makes things more clear.
I didn't try yet, but I guess the best way must be:
1. Disable CTRL-C (OPTION BREAK 255)
2. Set CTRL-C to a new routine Crtl-C handler (ON KEY New_CrtlC)
3. Each CTRL-C will then reset the PINs, then eventually close open files and exit the program
Unfortunly a watchdog will not work.
MMBasic Language Manual Page 45:
Best regards
Michaelcausality ≠correlation ≠coincidence
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209
Posted: 09:32am 17 Sep 2014
Copy link to clipboard
Print this post
I would think the watchdog would work in combination with disabling the CTRL-C.
Not tested it but i think the watchdog timer is only turned off when a CTRL-C is detected AND the program returns to its prompt, allowing the user/programmer to inspect variables and such.
Let me know if it works like that. It is good to know for sure.
Microblocks. Build with logic.
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9502
Posted: 12:13pm 17 Sep 2014
Copy link to clipboard
Print this post
I can confirm that the WATCHDOG timer keeps running after a CTRL-C break.
I have often forgot to manually stop it, and wonder why the MM seemed to spontaneously restart in front of me!
My guess is that MMBASIC issues the watchdog commands to the PIC32's internal watchdog timer, so CTRL-C breaking into the program, stops the program, but the internal watchdog timer is still running unless you manually stop it or reset it.
At first glance, this looks like an inconvenience, but it is actually a very good thing, because if MMBASIC falls over to the command-prompt with an error of some kind, now that the program is no longer running, the watchdog timer will reach zero, and reboot the system without user intervention, which allows for a clean restart.Edited by Grogster 2014-09-18Smoke makes things work. When the smoke gets out, it stops!
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1533
Posted: 12:30pm 17 Sep 2014
Copy link to clipboard
Print this post
@TZA
Solution, works as expected:
'******************************************
'************** code snippet **************
'************** useless code **************
' Provided AS IS without any warranty.
' Use it at your own risk.
'******************************************
On key new_ctrlC '** set key interupt to my own key handler
Option break 255 '** disable CTRL-C, you can't use CRTL-C
'** anymore!
Do '** endless loop - just waiting for CRTL-C
Loop
'******************************************
END
'******************************************
Sub new_ctrlC ' my new CTRL-C handler
Local key_value, i
key_value=KeyDown
If key_value=3 Then ' 3= keycode for CTRL-C
Print "Resetting used PINs ..."
For i = 1 To 4
Pin(i+10)=LOW
SetPin i,OFF
SetPin i+10,OFF
EndIf
Next i
End '* all PINs are OFF now we can leave
EndIf
End Sub
You've broken the plank in front of my head (as germans saying). Thanks again!
Best regards
MichaelEdited by twofingers 2014-09-18causality ≠correlation ≠coincidence
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1533
Posted: 12:42pm 17 Sep 2014
Copy link to clipboard
Print this post
@Grogs,
thanks for your answer. Sometime I will test out the strange watchdog behavior. For now all things are fine!
Regards
Michael
Correction:
Sub new_ctrlC ' my new CTRL-C handler
Local key_value, i
key_value=KeyDown
If key_value=3 Then ' 3= keycode for CTRL-C
Print "Resetting used PINs ..."
For i = 1 To 4
Pin(i+10)=LOW
SetPin i,OFF
SetPin i+10,OFF
Next i
End '* all PINs are OFF now we can leave
EndIf
'* ...
'* ... any other tasks as you like
'* ...
End Sub
Edited by twofingers 2014-09-18causality ≠correlation ≠coincidence
Frank N. Furter Guru Joined: 28/05/2012 Location: GermanyPosts: 939
Posted: 07:49pm 17 Sep 2014
Copy link to clipboard
Print this post
Hi Michael,
thanks for your code snippet - it looks very useful!!!
Frank
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1533
Posted: 02:02am 18 Sep 2014
Copy link to clipboard
Print this post
@Frank
it will for sure help to make the Time Warp again ... on the back of your TFT-Maximite!?
Greetings to the galaxy of Transylvania from the little blue planet Earth.
MichaelEdited by twofingers 2014-09-19causality ≠correlation ≠coincidence
Frank N. Furter Guru Joined: 28/05/2012 Location: GermanyPosts: 939
Posted: 07:34pm 18 Sep 2014
Copy link to clipboard
Print this post
@Michael:
“live long and prosper” ... oh no, that's the wrong universe! (rosa Wattebäuschchen werf')
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1533
Posted: 11:59pm 19 Sep 2014
Copy link to clipboard
Print this post
@Frank
A Jedi uses the Force for knowledge and defense, never for attack!
To be serious again. This is a improved version of the code above:
(restore of regular Ctrl-C is very important!)
'******************************************
'************** code snippet **************
'************** useless code **************
' Provided AS IS without any warranty.
' Use it at your own risk.
'******************************************
On key new_ctrlC '** set key interupt to my own key handler
Option break 255 '** disable CTRL-C, you can't use
'** regular CRTL-C anymore!
'** Don't forget to restore
'** before you leave this program!
Do '** endless loop - just waiting for CRTL-C
Loop `** your while condition
'******************************************
' do some housekeeping
Option break 3 '** re-enable regular CTRL-C
On key 0 '** we use regular key handler
END
'******************************************
Sub new_ctrlC ' my new CTRL-C handler
Local key_value, i
key_value=KeyDown
If key_value=3 Then ' 3= keycode for CTRL-C
' do some housekeeping
Print "Resetting used PINs ..."
For i = 1 To 4
Pin(i+10)=LOW
SetPin i,OFF
SetPin i+10,OFF
Next i
Option break 3 '** re-enable regular CTRL-C
On key 0 '** we use regular key handler
End '* all PINs are OFF now we can leave
EndIf