Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:10 02 Aug 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 : Micromite MMBasic V5.3 Beta 3

     Page 2 of 3    
Author Message
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2944
Posted: 05:51am 09 Dec 2016
Copy link to clipboard 
Print this post

Geoff,

Suggestion for MM+.

IF you don't set OPTION SDCARD, but type FILES, then you get the message:

'Error: Cannot access the SD card'


Can this please be changed to something like:

'Error: SD card not configured'

This will massively help when configuring E100s, and also bring it in line with the other Error messages such as LCDPANEL and TOUCH.

WW
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 10:55pm 09 Dec 2016
Copy link to clipboard 
Print this post

Good point. OK, will do.
Geoff Graham - http://geoffg.net
 
ajkw
Senior Member

Joined: 29/06/2011
Location: Australia
Posts: 290
Posted: 12:24am 14 Dec 2016
Copy link to clipboard 
Print this post

In regards Clocktrim.

Perhaps show the Clocktrim value in Option List

Might be useful when trying to trim over a long period and remembering the value previously set.

I am about to test but does anyone know a value to correct for a gain of a minute per day?

Anthony.


Edit, I presumed this was a Console Option, it seems it needs to be set in a program.

Question stands, does anyone know a value to correct for a gain of a minute per day?

Edited by ajkw 2016-12-15
 
redrok

Senior Member

Joined: 15/09/2014
Location: United States
Posts: 209
Posted: 09:51am 14 Dec 2016
Copy link to clipboard 
Print this post

Hi ajkw;
  Quote  Page 64:
'n' is the trim value which can range from -31 to +31 (this equates to an
adjustment range of about -12.5% to +12.5%). On power up the trim value
is zero.
I don't think you will get that amount of precision.

Since there are 1440 minutes / day.
+-12.5% is about +- 180 minutes.
With a resolution of +- 31 steps this would be about +- 6 minutes per step.
This is clearly good enough for normal functions including baudrate.
Just not so good for precision time clocks.

If you need a good time clock add one of the i2c clock chips.
I use the 8563 with 32k crystal and 20pF variable cap.
I can trim it to about 1 second per day.
BTW, this trimming is not easily done without a good frequency counter.
I calibrate my counter watching the 1 pulse per second on a GPS receiver.

redrok
 
ajkw
Senior Member

Joined: 29/06/2011
Location: Australia
Posts: 290
Posted: 03:40pm 14 Dec 2016
Copy link to clipboard 
Print this post

Thanks redrok,

I was mulling over the numbers whilst getting on with other things last night and they were going the way you outlined.

Am familiar with RTC's. I was one of the first to put a DS1302 in a Maximite back in 2011. Details are in these forums.

anyway getting off topic now..


Cheers,
Anthony.
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2442
Posted: 02:00am 15 Dec 2016
Copy link to clipboard 
Print this post

found an interesting 'bug' in integer support this afternoon, that was messing up some GPS result by just a fraction (about 20 metres). try out the following code:


a$ = "4342.4026,etc" ' the original sentence
b$ = "4342" ' integer part
c$ = "4026,junk" ' fractional part + rest of sentence
d$ = "4026,S,17239.0" ' fractional part + rest including a "."

Print (Val(b$)*10000)+Val(c$),(Val(b$)*10000)+Val(d$)

i%=(Val(b$)*10000)+Val(c$)
j%=(Val(b$)*10000)+Val(d$)

Print i%, j%

> run
43424026 4.34240e+07
43424026 43424024
>


notice the small difference (2) between the values on the 2nd line of output?

the intention of the code was to use a 64-bit integer to store latitude/longitude in units of 1/10000th of a degree.

the problem is that while VAL() evaluates up to the first non-numeral character, it bases the type returned upon the presence of a decimal point, even if this decimal point is outside of the numeric characters being converted. i believe this is an error, as non-evaluated characters are having an effect on the type of result returned (but not upon the value.

note that i am very happy that VAL() does evaluate up to non-numeral without error - this is extremely useful behaviour, particularly in splitting up comma delimited NMEA sentences coming from a GPS receiver.


cheers,
rob :-)Edited by robert.rozee 2016-12-16
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 03:23am 15 Dec 2016
Copy link to clipboard 
Print this post

rob,

Does
Print val(d$)

show 4024?

It looks like a bug (either way) and I expect Geoff will fix it if he knows about it.

JohnEdited by JohnS 2016-12-16
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2442
Posted: 03:34am 15 Dec 2016
Copy link to clipboard 
Print this post

no, it prints "4026". the numeric results for each individual part are correct, the error is in they type of the result - something like "4026,." returns a result of type float, whereas it should (i believe) return a result of type int64 as evaluation never proceeds past the comma.

the problem can be resolved by using INT(VAL("4026,.")), which appears to force the type to int64.


cheers,
rob :-)Edited by robert.rozee 2016-12-16
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 07:17am 15 Dec 2016
Copy link to clipboard 
Print this post

hmm....

Traditionally the type of VAL is floating point (of whatever kind).

Might need a VAL% function...

(Otherwise the person using MMBasic may need to go back to thinking about the way fl pt behaves!)

JohnEdited by JohnS 2016-12-16
 
redrok

Senior Member

Joined: 15/09/2014
Location: United States
Posts: 209
Posted: 08:25am 15 Dec 2016
Copy link to clipboard 
Print this post

Hi robert & John;

I agree with John that traditionally VAL evaluates to a float.
Even when forced to be an integer it still retains the 24bit fractional
resolution, albeit with extra junk characters beyond the 24bits.

Part of the problem robert is having is due to the Multiply in the math.
The multiply forces the answer to be related to a float.

I have been working on some high precision fixed point math routines all
done using only hexadecimal add, subtract, and shifts. I am implementing
both multiply and divide but there are no multiply nor divides being done.
Anytime a float type math operation is done you can't expect there to be
64bit answers, only 24bit type answers.

I would like to see johns VAL%() function as this would be quite useful
for 64bit integer calculations.

Since I have been working with fixed point there is a need to have a second
VAL function that works with the fractional part.
Possibly:
VALFRAC%()
I have no idea if this is generally useful though.
BTW, one of the best calculators on the net I have found is:
Big Number Calculator.
This works much better than the Microsoft calculator as it uses and
displays HEX bignums including the fractional part.

redrok
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2944
Posted: 08:45am 15 Dec 2016
Copy link to clipboard 
Print this post

Rob,

From your code above that produces the four numbers, are you saying that the bottom right number should be 43424026, and not 43424024; and hence the 20metres inaccuracy?

I have just run the code on a MicroMite Extreme and the bottom right number is indeed 43424026

I know Peter has been working on increasing accuracy, and hence my question above!

WW

 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 12:01pm 15 Dec 2016
Copy link to clipboard 
Print this post

I think it is all to do with VAL() being floating point and not the stray decimals in the string.
  Quote   a$ = "4342.4026,etc" ' the original sentence
b$ = "4342" ' integer part
c$ = "4026,junk" ' fractional part + rest of sentence
d$ = "4026,S,17239.0" ' fractional part + rest including a "."

PRINT (VAL(b$)*10000)+VAL(c$),(VAL(b$)*10000)+VAL(d$)


i%=(
VAL(b$)*10000)+VAL(c$)
j%=(
VAL(b$)*10000)+VAL(d$)
PRINT i%, j%
PRINT
m% =
VAL(b$)
n% =
VAL(c$)
p% =
VAL(d$)
PRINT m%,n%,p%
PRINT m%*1000 + n%,m%*1000 + p%


  Quote  > RUN
43424026 4.34240e+07
43424026 43424024

4342 4026 4026
4346026 4346026
>

VAL(c$) and VAL(d$) are equal.

Jim

VK7JH
MMedit
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 12:19pm 15 Dec 2016
Copy link to clipboard 
Print this post

Jim,

I think that's right and it's not a bug but rather a behaviour that happens to be revealed by the code fragments.

I suppose it can be avoided by using integer variables and doing the addition with two of them, along the lines of:
i%=VAL(b$)*10000
i2%=VAL(c$)
i%=i%+i2%

j%=VAL(b$)*10000
j2%=VAL(d$)
j%=j%+j2%

(i.e. as you also said)

It's not very intuitive, though.

JohnEdited by JohnS 2016-12-16
 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 767
Posted: 12:31pm 15 Dec 2016
Copy link to clipboard 
Print this post

Micromite User Manual Ver 5.3 beta 3 (Page 5)...

  Quote  44-pin Chips
The best chip to use is the PIC32MX170F256D-50I/PT which is guaranteed to run up to 48MHz and costs a
little over $4 when purchased from Microchip. Similar to the 28-pin package there are versions rated at 40MHz and versions that support USB - with the latter you lose access to two I/O pins which are reserved for USB functions (pins 10 and 42).
The following is a summary of the recommended chips for the Micromite in a 44-pin package:
PIC32MX170F256D-50I/PT Guaranteed to run at 48MHz.
PIC32MX170F256DI/PT Should run at 48MHz despite its 40MHz spec.


I was reading this summery and got the impression that you could use a 44 pin part with the USB option and use it as a console port... Isn't USB only supported on the 470 class MM's..? If so, then, maybe take this out, as it could give newbie's the wrong idea when ordering parts...

Of course, I could be totally wrong also..!!
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2944
Posted: 12:59pm 15 Dec 2016
Copy link to clipboard 
Print this post

Hi Zonker

Something like this may be better :

  Quote  
Similar to the 28-pin package, there are versions rated at 40MHz, as well as versions that have USB functionality. However, on the 28pin and 44pin PICs the USB functionality is unsupported in MMBASIC. Therefor if you're using a USB version of the 44pin PIC, you will lose access to the usual two I/Os associated to pins 10 and 42.
Edited by WhiteWizzard 2016-12-16
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 01:01am 16 Dec 2016
Copy link to clipboard 
Print this post

OK, I will update the wording.
Geoff Graham - http://geoffg.net
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2442
Posted: 02:24am 16 Dec 2016
Copy link to clipboard 
Print this post

  JohnS said   Jim,
I think that's right and it's not a bug but rather a behaviour that happens to be revealed by the code fragments.
John


would have to disagree. here is a simpler example:

c$ = "4026,junk"
d$ = "4026,more.junk"

Print Val(c$)*10000, Val(d$)*10000

> run
40260000 4.02600e+07
>


the two results should be of identical format. one may argue as to weather both should be int64 (left) or scientific/float (right), but it still remains that the output sent to the console should be the same.

various other punctuation characters beyong the comma seem to also affect the result type of VAL().

if the result type of VAL() is fixed as always being float, then an argument could be made for adding a new function VAL%() that always produces int64 results.

cheers,
rob :-)Edited by robert.rozee 2016-12-17
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 02:36am 16 Dec 2016
Copy link to clipboard 
Print this post

If its type varies then that's not good and the VAL% I suggested looks to be needed - with VAL to be changed so as NOT to vary in return type.

Yeah... I reckon it's in effect a bug.

This sort of problem would not normally affect any BASIC as they don't have an integer type that can represent more integers than the floating point (aka real/double) type. (Usually the floating point type can represent - exactly - more integers than the integer type, where the BASIC has an integer type. I know, a bit odd.)

JohnEdited by JohnS 2016-12-17
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 10:20am 16 Dec 2016
Copy link to clipboard 
Print this post

Further investigation does show the problem.

If there is a decimal anywhere in the string, the number is treated as a float.
It is seen better with numbers with a lot of digits:

  Quote   c$ = "4026782977,junk"
d$ =
"4026782977,more.junk"

PRINT VAL(c$), VAL(d$)

a% =
VAL(c$)
b% =
VAL(d$)
PRINT a%,b%
PRINT a%-b%




  Quote  > RUN
4026782977 4.02678e+09
4026782977 4026782720
257
>


The solution is to trim the string before evaluating.

Jim

edit: MMBasic looks for a decimal or an 'E' to determine if the number is a float so the above example doesn't need the decimal. the 'e' in 'more' is enough to result in a float.
Edited by TassyJim 2016-12-17
VK7JH
MMedit
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 11:26am 16 Dec 2016
Copy link to clipboard 
Print this post

I will have to think about this one. VAL() does search for a '.' or 'E' and uses that to tell if it needs to convert the number as a float. The solution will be to first determine the end of the number before doing the search. This adds some complexity but might be simpler than creating a new function such as VAL%().

Geoff
Geoff Graham - http://geoffg.net
 
     Page 2 of 3    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025