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.
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1667
Posted: 11:58am 03 Sep 2016
Copy link to clipboard
Print this post
Hi all,
I've just finished getting some logging up & running & was looking for a few answers & don't find a lot.
Firstly:-
Insertion & Removal.
Powered up Vs Down; Code Running or not running.
Notice occasionally, insertion or removal; code NOT running, leaves the MM unresponsive at the console.
Secondly:-
Card Detect, Not a lot of mention of this is the manual.
Is it possible to read CD without inducing an error first?
IE MM.ERRNO<>0
I presume I could use something like,
not considering all the options for now,
[Code]OPTION ERROR CONTINUE
FILES
IF MM.ERRNO<>0 THEN
Skip writing stuff to the card
ELSE IF MM.ERRNO=0
Go and right stuff to the card
END IF
[/code]
Using FILES as above seems a big waste of CPU time.
Phil.
mikeb Senior Member Joined: 10/04/2016 Location: AustraliaPosts: 174
Posted: 10:37am 04 Sep 2016
Copy link to clipboard
Print this post
Hi Phil,
I guess you could just check to see if the 'CD' input is low (0), just like you would with any other digital input, before you execute anything in the SD card routine.There are 10 kinds of people in the world. Those that understand binary and those that don't.
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1667
Posted: 11:42am 04 Sep 2016
Copy link to clipboard
Print this post
Hi Mike,
That thought did cross my mind but assumed it wouldn't work.
You've prompted me to give it a go.
[Code]
> print Pin(30)
Error: Pin 30 is reserved on startup
>
[/code]
Phil.
mikeb Senior Member Joined: 10/04/2016 Location: AustraliaPosts: 174
Posted: 11:00am 05 Sep 2016
Copy link to clipboard
Print this post
Hi Phil,
Have been really slack and have not used anything to do with the SD card yet.
Can you NOT declare the 'CD' and 'WP' pins to the SD Card OPTION settings and do a check of them, in your program, prior to entering any code which accesses the SD card ? As they are optional, not declaring should leave them available to your program.
The OPTION ERROR CONTINUE looks right. MM.ERRNO looks like it should return the error message as plain text, which you could print out, at the appropriate moment.
Not trying to tell you how to 'suck eggs'. As I said, haven't used it. Just looking at the manual. There are 10 kinds of people in the world. Those that understand binary and those that don't.
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1667
Posted: 12:57pm 05 Sep 2016
Copy link to clipboard
Print this post
Thanks Mike,
I'd totally overlooked the fact that assigning them to the card is optional.
Wonder what the Pro's & Con's of not assigning them are.
They would certainly be readable if not assigned.
Phil.
mikeb Senior Member Joined: 10/04/2016 Location: AustraliaPosts: 174
Posted: 05:35pm 05 Sep 2016
Copy link to clipboard
Print this post
@Phil,
The Pro might be that you don't get the error and are free to branch to where ever you like. Try it out. I'll follow your lead. I get lots of tips off your threads. There are 10 kinds of people in the world. Those that understand binary and those that don't.
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10214
Posted: 06:57pm 05 Sep 2016
Copy link to clipboard
Print this post
It is trivial to read any pin in a Cfunction. Will post something later today when in front of a computer.
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209
Posted: 07:49pm 05 Sep 2016
Copy link to clipboard
Print this post
It might be a good addition to the 5.3 wish list.
Reading a pin while it is reserved for something is not going to change its function.
The ability to monitor a pin and use in software as shown above can be valuable.
Microblocks. Build with logic.
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10214
Posted: 02:12am 06 Sep 2016
Copy link to clipboard
Print this post
This CFunction will return a 1 or a 0 for any pin irrespective of whether it is defined in an OPTION command
usage:
[code]
integer a,pinno=3
a=readpin(pinno) 'pinno should be a literal or an integer variable
WhiteWizzard Guru Joined: 05/04/2013 Location: United KingdomPosts: 2932
Posted: 02:41am 06 Sep 2016
Copy link to clipboard
Print this post
Very useful Peter - Thanks (although untested here as of yet. . . )
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1667
Posted: 11:07am 07 Sep 2016
Copy link to clipboard
Print this post
Thanks Peter. That completely addresses the issue.
Is the Internal Time & Date something equally simple to retrieve?
I made mention of it in the 5.3 thread I created, but think it is probably not the best use of Geoff's resources to add it as a Native Basic command.
The time portion of it may be especially useful for people developing clocks & timing related things.
Would remove the need to convert the string values to integer before proceeding with the task at hand.
Phil.
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10214
Posted: 11:40am 07 Sep 2016
Copy link to clipboard
Print this post
There is no internal time and date. The firmware maintains 6 variables
second, minute, hour, day, month,year based on a millisecond timer interrupt.
Time$ and date$ are just these converted to strings which are easily interrogated using VAL, LEFT$, MID$ and RIGHT$ Edited by matherp 2016-09-08
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1667
Posted: 12:35pm 07 Sep 2016
Copy link to clipboard
Print this post
Thanks Peter,
I was aware of that and it's how I deal with it at present.
My thinking was it would be more efficient to just deal with numeric values until there was requirement to display it as a string.
Curruntly using these:-
[Code]
'----------------------------------------------------------------------
'Functions to turn Time String to Seconds & Seconds back into a String
'----------------------------------------------------------------------
Function TimeSecs(TimeStr as String) As integer 'Converts Time$ to an Integer Value, Seconds since midnight.
Function SecsTime(TimeInt as Integer) as String 'Converts Seconds from Midnight back to a Time String.
Local Integer HH,MM,SS
HH=TimeInt\3600
MM=(TimeInt-HH*3600)\60
SS=TimeInt-HH*3600-MM*60
SecsTime=Str$(HH,2,0,"0")+":"+Str$(MM,2,0,"0")+":"+Str$(SS,2,0,"0")
[/code]
Cheers.
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1667
Posted: 12:33am 08 Sep 2016
Copy link to clipboard
Print this post
Hi Again Peter,
Further to the above, can I add another question?
To the human mind, those two functions I listed seem like long winded processes;
Converting Strings to numbers & back again.
This undoubtedly is our lack of understanding of the PIC processor's power with the interpreter, and it makes us question is there a better or faster alternative.
We immediately think of a new inbuilt feature or custom cFunctions as a magic alternative; better, faster etc. Yet in reality a similar thing is done.
Can you give a rough estimation of the time the interpreter would take to processing the likes of the above?
That would help make it seem more trivial to users when they think there might be a better way.
I probably wouldn't be surprised if the cSub Vs Basic Code execution time for something like above is minimal, but it would be interesting to know a loose ball park figure.
Thanks
Phil.
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1667
Posted: 10:21pm 14 Sep 2016
Copy link to clipboard
Print this post
Is the Internal Time & Date something equally simple to retrieve?
There is no internal time and date. The firmware maintains 6 variables
second, minute, hour, day, month,year based on a millisecond timer interrupt.
Time$ and date$ are just these converted to strings which are easily interrogated using VAL, LEFT$, MID$ and RIGHT$
Hi @matherp or @geoffg, anyone else who might know.
Just wondering if it's possible to access this & return a value with something like:-
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10214
Posted: 10:31pm 14 Sep 2016
Copy link to clipboard
Print this post
Phil
Probably >90% of the CPU time in MMBasic is taken in the interpreter, i.e. parsing the command line. There will be little difference between your "PEEK" version and your version above. The MM runs at c30,000 lines of Basic per second so the overhead for all normal use is irrelevant. The only time it would be worth using the internal variables direct would be in a CFunction where the C code also used the result without returning to Basic.
Your working code may feel clunky but don't worry it is not creating significant overhead.
As an example, when we were playing with the STM32 which has a floating point processor built in, there was almost no speed difference between using it and using the software floating point routines, all the time was taken by MMBasic "interpreting" the Basic commands.Edited by matherp 2016-09-16
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1667
Posted: 11:35pm 14 Sep 2016
Copy link to clipboard
Print this post
Thanks Peter,
It's always good to hear that there's nothing to gain in trying to build a better mouse trap.
Sometimes it's hard not to look upon some bits of code as clunky, particularly when you have a mathematical mind; it's simply what we think time is; numeric.
Mid-day & a quarter to six, never enter the mind as a clunky conversion.
Knowing the power of the interpreter & the irrelevance of the difference helps.