Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:51 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 : Time$ curiosity...

Author Message
Malibu
Senior Member

Joined: 07/07/2018
Location: Australia
Posts: 260
Posted: 06:14am 09 Mar 2019
Copy link to clipboard 
Print this post

G'day All
I'm fiddling with a timing idea so I can keep track of the actual time spent doing machining on the CNC... basically, when the CNC starts, it will start the timer and once finished, the timer stops and I can see exactly how long the process has taken and bill out accordingly.

I've only started doing a few initial tests and I'm using the TIME$ function to get the time elapsed since startup... I'm just using the PRINT statement for now, like this:
print mid$(time$,1,2);"-";mid$(time$,4,2);"-";mid$(time$,7,2);" ";Time$

(Naturally, I reset the time to 0:0:0 at the start)

My question is - can I read the hours, minutes and seconds directly, or do I need to split the string and convert to a numeric value
For example, is it possible to do something like this...
print Minute$

... to only access the minutes portion of the time string?
John
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 06:26am 09 Mar 2019
Copy link to clipboard 
Print this post

No. Not that I am aware of, anyway. You need to use MID$ as you already are, to pull-apart TIME$ into the bits you want.

Well, that is a half-truth. There is no pre-defined MINUTE$ in MMBASIC, but you most certainly could create your own MINUTE$ and reference that.
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 07:11am 09 Mar 2019
Copy link to clipboard 
Print this post

  Quote   starttime$ = TIME$
PRINT "Starting at "+starttime$
PAUSE 10000

'do stuff

endtime$ =
TIME$
PRINT "Stopping at "+endtime$

PRINT "timetaken = "+STR$(secsX(endtime$)-secsX(starttime$))+ " sec"
PRINT " which is = "TimeX$(secsX(endtime$)-secsX(starttime$))

END

FUNCTION secsX(dt$) AS INTEGER
' given date as "hh:mm:ss"
' returns time in seconds
LOCAL INTEGER hh,mm,ss
hh=
VAL(MID$(dt$,1,2))
mm=
VAL(MID$(dt$,4,2))
ss=
VAL(MID$(dt$,7,2))
secsX=hh*
60*60+mm*60+ss
END FUNCTION

FUNCTION TimeX$(u AS INTEGER)
' given seconds returns time formatted
LOCAL hh,mm,ss
hh=
INT(u/3600)
mm=
INT((u MOD 3600)/60)
ss=(u
MOD 3600) MOD 60
TimeX$ =
STR$(hh,2,0,"0")+":"+STR$(mm,2,0,"0")+":"+STR$(ss,2,0,"0")
END FUNCTION


Jim
VK7JH
MMedit
 
Malibu
Senior Member

Joined: 07/07/2018
Location: Australia
Posts: 260
Posted: 07:15am 09 Mar 2019
Copy link to clipboard 
Print this post

Thanks Grogs, it's all good
It doesn't take a whole lot of extra code (or time) to convert the string, so I'm happy enough to do it that way... (it was just a curious question that I thought I may have missed the answer to reading the manual)
I'll need to extract each value (disregarding the seconds), convert to a value and tally-up that for total minutes elapsed.
For example - 01:30:00 on the time$ function would end up being 90 minutes - calculated to decimal works out to 1.5 Hours.
(I need to calculate by decimal time intervals)
I'll post the code once I sort it all out in case it helps someone else in the future
For now... it's dinner time!
John
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2442
Posted: 02:22pm 09 Mar 2019
Copy link to clipboard 
Print this post

you can also just use the millisecond timer:

Start = Timer

' do the stuff in here that takes time

Elapsed = (Timer-Start)/1000
Print Elapsed " seconds"


cheers,
rob :-)
 
Malibu
Senior Member

Joined: 07/07/2018
Location: Australia
Posts: 260
Posted: 10:03pm 09 Mar 2019
Copy link to clipboard 
Print this post

Thanks everyone... all good answers and suggestions
Here's this morning's effort which is good enough for what I'm trying to do

OPTION EXPLICIT
DIM True=1, False=0
DIM ShowNewTime = False
DIM ElapsedTime AS FLOAT

TIME$="1:59:30" 'Initialise the clock for testing (in use, set to 0:0:0)
SETTICK 1000, UpdateDisplay 'Interval for showing the time

DO
IF ShowNewTime = True THEN GOSUB ShowTime
LOOP

ShowTime:
ElapsedTime=VAL(STR$(((VAL(MID$(TIME$,1,2))*3600)+(VAL(MID$(TIME$,4,2))*60)+VAL(MID$(TIME$,7,2)))/3600,0,4))
PRINT ElapsedTime;" | ";Time$ 'print the decimal time and the clock for debug
ShowNewTime = False
RETURN

SUB UpdateDisplay
ShowNewTime = True
END SUB

I don't actually need to know the start time because it's always going to be reset to "00:00:00" when the spindle starts.
John
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 12:58pm 10 Mar 2019
Copy link to clipboard 
Print this post

deleted...Edited by MicroBlocks 2019-03-11
Microblocks. Build with logic.
 
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 435
Posted: 01:00pm 10 Mar 2019
Copy link to clipboard 
Print this post

Hi Jim

why in function TimeX, did you use

hh= INT(u/3600)


and not

hh= u\3600


I have tested speed dif between 2 lines.
in loop "for i=1 to 1000" I win....
1 ms, yesssss!!!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 08:22pm 10 Mar 2019
Copy link to clipboard 
Print this post

  goc30 said   Hi Jim

why in function TimeX, did you use

hh= INT(u/3600)


and not

hh= u\3600


I have tested speed dif between 2 lines.
in loop "for i=1 to 1000" I win....
1 ms, yesssss!!!


Left over from the days before we had INTEGERs
Showing my age.

Jim

VK7JH
MMedit
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025