![]() |
Forum Index : Microcontroller and PC projects : Time$ curiosity...
Author | Message | ||||
Malibu Senior Member ![]() Joined: 07/07/2018 Location: AustraliaPosts: 260 |
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 ZealandPosts: 9610 |
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: AustraliaPosts: 6283 |
Jim VK7JH MMedit |
||||
Malibu Senior Member ![]() Joined: 07/07/2018 Location: AustraliaPosts: 260 |
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 ZealandPosts: 2442 |
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: AustraliaPosts: 260 |
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: ThailandPosts: 2209 |
deleted... Microblocks. Build with logic. |
||||
goc30![]() Guru ![]() Joined: 12/04/2017 Location: FrancePosts: 435 |
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: AustraliaPosts: 6283 |
Left over from the days before we had INTEGERs Showing my age. Jim VK7JH MMedit |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |