Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 06:46 09 May 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 : Quick PULSE and PWM question...

Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9070
Posted: 02:17pm 06 Jun 2013
Copy link to clipboard 
Print this post

Hi all.


Manual for v4.3, page 29, states that with the PULSE command, any pulse greater then 3ms will run in the background. But I am correct that this is still a single pulse, correct?

In other words: Pulses greater then 3ms are processed while the main program code continues to run. The code does not stop for the pulse time, if it is greater then 3ms, correct?

I think I understand that right, but I just want to clear that up in my head.

Can I make the assumption that both the background PULSE command and the PWM command will fail if the core crashes, or are these being dealt with more at a hardware level then a MMBASIC level?

With respect to PWM mainly, if I set it going, but then the MMBASIC crashes, does the PWM stop, or is that set running by MMBASIC, and even if MMBASIC crashes, so long as there is still power on the circuit, the PWM will keep going?

MMBASIC has not crashed on me yet for something that was not my fault, but I am curious about this aspect, as I want to setup an external watchdog reset for the MM, but if the PWM especially, keeps going at hardware level even if MMBASIC has crashed, then it won't really work as a watchdog trigger!

Hope you all can see what I am getting at....
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 07:33pm 06 Jun 2013
Copy link to clipboard 
Print this post

The PULSE is produced by software (both less than 3mS or over) and the PWM is produced by the PIC32 hardware. But both will stop if MMBasic crashes.

The more detailed explanation is that while the PIC32 is running MMBasic it can be presented with an impossible situation. For example, a request to access memory that does not exist, or divide by zero, etc. When this happens the CPU is forced into a reset and you get the message "An internal error was trapped...". This is probably what you meant when you said "if MMBasic crashes".

Mostly this is caused by a bug within MMBasic and over the last couple of years I believe that I have weeded out almost all all of them. However, in something as complex as a BASIC interpreter you can never offer a guarantee. Some things in your BASIC program can also cause this situation. For example: POKE 1,1,1

But to get back to the original question, if MMBasic crashes it will force a reset and any PULSE and PWM will be stopped. If you want to implement a watchdog facility I believe that the best way would be to use occasional PULSE commands to reset an external timer as that would also catch a problem in your BASIC code (such as an infinite loop).

Geoff
Geoff Graham - http://geoffg.net
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9070
Posted: 10:00pm 06 Jun 2013
Copy link to clipboard 
Print this post

Excellent - thanks Geoff.


I was thinking along the lines of the PULSE over PWM command, as you mentioned, and as my program is menu based, with a main menu screen, I can have the pulse command as part of the main menu screen - if the program takes too long to get back to the main menu, then it resets kind of thing.

HOWEVER - if MMBASIC self-resets in the way you mention, perhaps an external watchdog is not really of any use?

I mean, if MMBASIC resets the PIC32 if it gets in major trouble, that would achieve the same result as an external watchdog would it not?

Thanks for taking the time to post.

Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 05:22am 07 Jun 2013
Copy link to clipboard 
Print this post

Yes, a reset would be the same. Just one point, when recovering from a crash MMBasic does NOT run the autorun.bas. This is because the autorun might have contained the thing that caused the crash.


MMBasic is different from Windows (which crashes all the time). MMBasic is much simpler, it does not have dogy device drivers and it cannot have memory leaks. If MMBasic runs your program once without a problem, then it will run it for a million years without a problem.

Your problems are more likely to come from power glitches and issues in your BASIC program. I would still have a watchdog for them. It would also do a full reset so that autorun will run.

Geoff

BTW It is the PIC32 that detects the impossible situation and forces the reset without consulting MMBasic. MMBasic only regains control after the reset and posts a suitably apologetic message.
Edited by Geoffg 2013-06-08
Geoff Graham - http://geoffg.net
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9070
Posted: 12:47pm 07 Jun 2013
Copy link to clipboard 
Print this post

  Quote  MMBasic only regains control after the reset and posts a suitably apologetic message.


Ha ha!

Thanks for the extra info.
I will incorporate an external watchdog using the PULSE command at menu level, I think.
Probably still a good idea to have one, for the few extra cents it costs...
Smoke makes things work. When the smoke gets out, it stops!
 
Print this page


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

© JAQ Software 2024