Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 22:36 27 Nov 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 : MMBasic 4.4 Beta 4

     Page 1 of 3    
Author Message
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 08:47pm 10 Jun 2013
Copy link to clipboard 
Print this post

Another beta test version of MMBasic 4.4.

This includes three new features:

The WATCHDOG command to automatically reset the Maximite if something goes wrong. WATCHDOG ENABLE will start the timer counting down from four seconds. WATCHDOG RESET will reset the counter back to four seconds and should be strategically placed in code to prevent the timer from timing out and rebooting the Maximite. When the Maximite reboots following a watchdog timeout it will attempt to run RESTART.BAS instead of AUTORUN.BAS.

You can test this function by typing WATCHDOG ENABLE at the command prompt and waiting for four seconds.

Another new feature is being able to specify the amount of memory to reserve for each element in a string array using the LENGTH qualifier. For example:
DIM str$(10,10) LENGTH 24
will dimension a string array but only reserve 24 bytes for each element of the array. In the above example MMBasic would allocate just 3KB of RAM for the array whereas the default (without the LENGTH qualifier) would require 30KB RAM.

Other than using the LENGTH keyword in the DIM command these arrays work just like any other array. Also MMBasic will correctly flag an error if a string is too long to fit into one of these elements.

This method of specifying the element size is easier for the interpreter to parse than the other suggestion of square brackets. But I am not sure about using the keyword LENGTH, other possibilities include SIZE or LEN. If anyone can think of a better word please let me know.

You can now specify 2 stop pits for serial transmitted data by adding ",S2" at the end of a COM string. For example, OPEN "COM1:2400,S2" as #1

You can download the test version from: http://geoffg.net/Downloads/Maximite/MMBasic_4.4_Beta_4.zip

There are a few other fixes/changes in this version:
- The SEEK command from beta 1
- The MODULE command from beta 2
- FILES on drive A: includes the size of the file.
- CHAIN command now resets the DATA pointer and will not throw an error indicating too many GOSUBS, FOR LOOPS, DO LOOPS or similar.
- Fixed a bug in the CLR$() function which produced random characters.

This is the end of my todo list for V4.4. I would like to make V4.4 the final release for some time (other than critical bug fixes) so, if you have an important feature that you think should be in MMBasic, now is the time to speak up. Remember that any potential addition must be useful to a lot of people, fit within the language and not doable in BASIC. Also I cannot guarantee that all (or any) suggestions will make it in.

Thanks
Geoff

Geoff Graham - http://geoffg.net
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6100
Posted: 09:11pm 10 Jun 2013
Copy link to clipboard 
Print this post

Geoff,
With the maximite powered by the USB and using TeraTerm (or MMedit), as soon as I enter "watchdog enable", the serial port disappears briefly and the only way to communicate is to unplug and reinsert.

I don't have any other hardware to try with untill I get back home in a month or so.


Mono Maximite and Windows7

Jim
VK7JH
MMedit   MMBasic Help
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 09:41pm 10 Jun 2013
Copy link to clipboard 
Print this post

Amazing speed bringing out added features!
MMBasic is getting better all the time.

In the external watchdog thread it was mentioned a few times that a slow watchdog timer would be preferable for some situations.
Would specifying a postscaler or time be difficult to do?
Something like:
[code]
WATCHDOG ENABLE value
[/code]
I think the WDTPS column of this table could be used:
[code]
WDTPS<4:0> | Postscaler Ratio | Time-out Period | Time-out Period
0 00000 1:1 1 ms 0.75 ms
1 00001 1:2 2 ms 1.5 ms
2 00010 1:4 4 ms 3 ms
3 00011 1:8 8 ms 6 ms
4 00100 1:16 16 ms 12 ms
5 00101 1:32 32 ms 24 ms
6 00110 1:64 64 ms 48 ms
7 00111 1:128 128 ms 96 ms
8 01000 1:256 256 ms 192 ms
9 01001 1:512 512 ms 384 ms
10 01010 1:1024 1.024s 0.768s
11 01011 1:2048 2.048s 1.536s
12 01100 1:4096 4.096s 3.072s
13 01101 1:8192 8.192s 6.144s
14 01110 1:16384 16.384s 12.228s
15 01111 1:32768 32.768s 24.576s
16 10000 1:65536 65.536s 49.152s
17 10001 1:131072 131.072s 98.304s
18 10010 1:262144 262.144s 196.608s
19 10011 1:524288 524.288s 393.216s
20 10100 1:1045876 1048.576s 786.432s
[/code]

Personally i would use the value that has to be set in the register. The table will make clear which time period will then be active.
Specifying the time would need much more check for valid entries and a translation table.


About specifying the length of strings in an array:
The LENGTH keyword looks fine to me. It is not how other basic do it but that is in this case a good thing.
Dim a$ as string * 24 is ugly. :)

I have noticed in a few cases connecting a serial port to a picaxe or other hardware that i had to add a delay between characters. Maybe the stopbits will help. I had to use a 50ms delay to get it to work perfectly. It was not the baudrate as the problem also occured when using low speeds. It was only the delay between characters that was the culprit.
I needed to make a extra function that sends a string one character at a time. Not too difficult, but it would be a nice feature if the OPEN "COM:x" command would have a delay parameter where you can provide the delay in milliseconds.

I would love an optional parameter with the HEX$ command to provide leading zeros.
HEX$(1,2) would then give "01".



Microblocks. Build with logic.
 
BobDevries

Senior Member

Joined: 08/06/2011
Location: Australia
Posts: 266
Posted: 09:53pm 10 Jun 2013
Copy link to clipboard 
Print this post

Hey, TZAdvantage,

your suggestion about HEX$ is fine, but it is so easy to do in just a few instructions:


print right$("00"+HEX$(val),2)


Regards,
Bob Devries
Dalby, QLD, Australia
 
BobDevries

Senior Member

Joined: 08/06/2011
Location: Australia
Posts: 266
Posted: 10:02pm 10 Jun 2013
Copy link to clipboard 
Print this post

In fact, you can easily set up a function to do this:


val=20
Print hexnum$(5,val)
End

Function hexnum$(numchrs, val)
zero$=String$(numchrs,"0")
hexnum$ = Right$(zero$+Hex$(val),numchrs)
End Function


Regards,
Bob Devries
Dalby, QLD, Australia
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 10:10pm 10 Jun 2013
Copy link to clipboard 
Print this post

  TassyJim said  With the maximite powered by the USB and using TeraTerm (or MMedit), as soon as I enter "watchdog enable", the serial port disappears briefly and the only way to communicate is to unplug and reinsert.

It does not happen "as soon as" but four seconds later. The watchdog timer is doing exactly what it is supposed to be doing... resetting the pPIC32 (which also drops the USB comms) because there has not been a WATCHDOG RESET within the past four seconds.

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

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 10:14pm 10 Jun 2013
Copy link to clipboard 
Print this post

Yes that is what i do now.
It is more a convenience and it cleans up the code.
I think that when user defined functions are used almost every time, it justifies it to promote that functionality to the language. But maybe i am the only one who uses that a lot.

It is a bit the same with BCD numbers, use it all the time.
But i don't want to bother Geoff too much :) , and many times when a feature is not in the language and you have to implement it yourself it is also part of learning.
Something not to be under estimated.

Difficult to find a good balance.


Microblocks. Build with logic.
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 10:16pm 10 Jun 2013
Copy link to clipboard 
Print this post

Previous post was a response to Bob.


Just one more remark about the way it starts after a watchdog timeout.

I personally would prefer that AUTORUN.BAS is executed all the time.
This would prevent me from having two files to maintain.
A system variable with the startup condition would be enough, so that i can add specific code to the autorun.bas file.

Choices, choices.:)
Edited by TZAdvantage 2013-06-12
Microblocks. Build with logic.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 10:34pm 10 Jun 2013
Copy link to clipboard 
Print this post

You can easily put the following into RESTART.BAS
RUN "AUTORUN.BAS"

In fact, you could put the following into RESTART.BAS to get exactly what you want:
MM.WATCHDOG = 1
CHAIN "AUTORUN.BAS"

RESTART.BAS is "more flexible" and I thought that that was more valuable than "more convenient".

GeoffEdited by Geoffg 2013-06-12
Geoff Graham - http://geoffg.net
 
ajkw
Senior Member

Joined: 29/06/2011
Location: Australia
Posts: 290
Posted: 10:54pm 10 Jun 2013
Copy link to clipboard 
Print this post

RESTART.BAS is a great idea, not too hard to maintain 1-2 lines of code and chain to AUTORUN.

Geoff,

My MM is not counting down, it immediately restarts after WATCHDOG ENABLE

The MM restarts with "The WATCHDOG command timed out..." and correctly runs RESTART.BAS

[12V PS, Keyboard and VGA.]

Anthony.
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 11:01pm 10 Jun 2013
Copy link to clipboard 
Print this post

:) The question then is why have only 1 line of code (MM.Watchdog=1) that is important and then chain to autorun.bas. The intention is to do some other work in the RESTART.BAS and that means two files (three files when you count your own program) to maintain.
But from another viewpoint i can see its uses. It would separate the code that will run. Personal preferences, and not so important as it will work either way.

My CMM clone around a UWB32 is responding good to a WATCHDOG ENABLE.
It resets after 4 seconds.


Microblocks. Build with logic.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 04:52am 11 Jun 2013
Copy link to clipboard 
Print this post

  ajkw said  My MM is not counting down, it immediately restarts after WATCHDOG ENABLE


Sorry Anthony, you are quite correct.

I have updated the download with the fixed version. Could you please re download the zip. You might need to clear your cache, the new hex files have a time of about 10:22PM.

Now for a complicated explanation...

When I first implemented the WATCHDOG command I used the hardware watchdog timer built into the PIC32 but when Anthony found that it was not working he uncovered a subtle issue with this.

The timeout of the hardware watchdog is controlled by a set of configuration bits and these are set in the bootloader (unless you use a PIC32 programmer like me). The problem is that the bootloader has the timeout fixed to 1mS, which is far too fast. Even worse, I cannot change the bootloader as there are many thousands of Maximites out there with the bootloader programmed by the original manufacturer (Altronics, Olimex, etc).

So, in the current download I changed it to a software watchdog timer using a PIC32 timer. Now, the purists will say that this is not as foolproof as a hardware timer and they are right (to a degree). However the chances of a failure which also disables the timer is very slight and, in most cases, that would cause a PIC32 exception which will restart the processor anyway (and run RESTART.BAS).

I still believe that an external (to the PIC32) watchdog timer is the only foolproof watchdog system but this software implementation comes close - and it is easy and cheap.

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

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 05:13am 11 Jun 2013
Copy link to clipboard 
Print this post

Would you not be able to change that postscalar register when MMBasic starts?
like this:
[code]
DEVCFG1bits.WDTPS = 0b01100; //4.096 sec timeout
DEVCFG1bits.FWDTEN = 0; //WDT software control enabled

and when the watchdog is needed:

WDTCONbits.ON = 1;
[/code]

The WDTPS has more bits so it should be ORed with its current value.

I use a UBW32 and i have a pickit3 to program it. My default value without doing anything is 4 seconds? Coincidence?
I am going to look in my bootloader what i have.
And i go do some more reading in the datasheet. :)
Edited by TZAdvantage 2013-06-12
Microblocks. Build with logic.
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 07:40am 11 Jun 2013
Copy link to clipboard 
Print this post

http://www.microchip.com.tw/Data_CD/Reference%20Manuals/PIC3 2MX%20Family%20Reference%20Manual/PIC32%20Family%20Reference %20Manual,%20Sect.%2032%20Configuration.pdf
I have read part 32.3 more then ten times.... boy they don't make it easy.

At the end it says it is programmable by a running program. So there is a small chance it can be done. Unfortunately i have no time to test this out.

Too many different bootloaders out there on so many variations to make a generic bootloader.
Maybe it is time to choose a specific watchdog chip and support it with some functions written in basic.





Edited by TZAdvantage 2013-06-12
Microblocks. Build with logic.
 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 01:30pm 11 Jun 2013
Copy link to clipboard 
Print this post

I am getting a color shift when loading this beta version. Anyone else? I rolled back to 4.4 beta 2 and it is not there.
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1425
Posted: 01:36pm 11 Jun 2013
Copy link to clipboard 
Print this post

  TZAdvantage said  
Maybe it is time to choose a specific watchdog chip and support it with some functions written in basic.



If there were an I2C dog chip it could be hung on the same I2C lines as the RTC. That I2C bus is kind of a system bus. No BASIC access to screw things up.
Micromites and Maximites! - Beginning Maximite
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6100
Posted: 02:35pm 11 Jun 2013
Copy link to clipboard 
Print this post

The updated Beta watchdog works correctly after 4 seconds. Thanks Geoff.

Something to be aware of if you are using USB comms.
Resetting the Maximite resets the USB and this can have strange consequences.

In my situation (and I cannot check any other PC's at the moment):
If you have the serial port open when a reset occurs, Windows seems to re-initialize the port but it is unresponsive.
This happens with MM EDit and TeraTerm.
The sequence required to get thing working again is:
Shut down the Windows application.
powerdown or unplug the Maximite.
wait for the bleep indicating it has been unplugged.
reinsert or power up the Maximite.
re start the windows application.

A solution if you require the watchdog is to use comm1 or comm2 on the Maximite and a standard serial port or usb serial port on the PC.
This way Windows will not get confused when the Maximite reboots.


To test, try this:
Start TeraTerm
Send the command WATCHDOG ENABLE
before the 4 seconds, shut down TeraTerm
Wait for the Bleeps for remove and insert USB device.
Restart TeraTerm

The maximite is back.

Now do it again without shutting down TeraTerm

This is a Windows problem and occurs if an application has the serial port open when a reset occurs.

Jim

VK7JH
MMedit   MMBasic Help
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 03:31pm 11 Jun 2013
Copy link to clipboard 
Print this post

Yes, the reset causes the USB interface on the PC to hang, it is a PC/Windows thing. However the watchdog timer is intended for unattended operation (for example Gizmo's post here).

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

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 04:00pm 11 Jun 2013
Copy link to clipboard 
Print this post

  TZAdvantage said   Would you not be able to change that postscalar register when MMBasic starts?
like this:
[code]
DEVCFG1bits.WDTPS = 0b01100; //4.096 sec timeout
DEVCFG1bits.FWDTEN = 0; //WDT software control enabled

and when the watchdog is needed:

WDTCONbits.ON = 1;
[/code]

The WDTPS has more bits so it should be ORed with its current value.

I use a UBW32 and i have a pickit3 to program it. My default value without doing anything is 4 seconds? Coincidence?
I am going to look in my bootloader what i have.
And i go do some more reading in the datasheet. :)


Good idea but it will not work. To quote from the manual:
  Quote  To ensure the 128-bit data integrity of each Configuration Word, a comparison is continuously made between each Configuration bit and its stored complement. If a mismatch is detected, a Configuration Mismatch Reset is generated causing a device Reset.


Do you know how to turn off the Configuration Mismatch Reset?

I also tried writing to WDTCONbits.SWDTPS but that is ignored.

Geoff
Geoff Graham - http://geoffg.net
 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 04:00pm 11 Jun 2013
Copy link to clipboard 
Print this post

Its just me then?
 
     Page 1 of 3    
Print this page
© JAQ Software 2024