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

Author Message
Grogster

Admin Group

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

I don't follow this at all.....

My code is:

  Quote  '=========== MAIN LOOP ==============
DO
If SM$="Y" then 'Summer mode
Text mm.hres/2,075,"SUMMER MODE.",CM,2,1,RGB(CYAN)
Text 20,130,"VALVE #4:",L,2,1,RGB(White)
DO
BUTTON=
0
If Pin(BRN)=0 then 'Brown water level sensor underwater.(#4 - bottom of tank)
Pin(VALVE_4)=1 'Open valve #4
Text 200,130," OPEN ",L,2,1,RGB(GREEN)
ELSE
Pin(VALVE_4)=0 'Close valve #4
Text 200,130,"CLOSED",L,2,1,RGB(RED)
Time$="00:00:00"
DO
Text mm.hres/2,165,Time$,CM,2,1,RGB(BROWN)
Text mm.hres/2,MM.VRES-25,"WAIT FOR TANK...",CM,2,1,RGB(White)
Pause 500
Text mm.hres/2,MM.VRES-25," ",CM,2,1,RGB(BLACK)
Pause 500
Loop until Pin(BLU)=0 or BUTTON 'Wait till the tank has refilled or button pressed
Endif
If BUTTON then Exit DO 'Hop out of here if a remote button was pressed
Loop
ELSE 'Winter mode


This DOES NOT work. The clock never moves past 00:00:00, despite the 'Wait for tank' message flashing away there happily. The background RTC - having been reset in the line before the DO/LOOP, should now count up - it does not.

If I run this test code right at the top of the program:


Time$="00:00:00"
DO
Text MM.HRES/2,165,TIME$,CM,2,1,RGB(BROWN)
Text mm.hres/2,MM.VRES-25,"WAIT FOR TANK...",CM,2,1,RGB(White)
Pause 500
Text mm.hres/2,MM.VRES-25," ",CM,2,1,RGB(BLACK)
Pause 500
Loop


It works exactly as expected, and the timer counts up on the LCD.
But the code above - which is essentially the same - does not.

If I CTRL-C break the program when it WON'T count, then quickly ask for a '? TIME$', it is only counting from the point I CTRL-C stopped the program, so it is like resetting the time$ inside a loop(but only once) is not taking effect....

Can anyone help with this, as I don't understand what I am doing wrong.
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 06:48am 18 Feb 2019
Copy link to clipboard 
Print this post

try a PRINT Time$ and also try

T$ = Time$
Text mm.hres/2,165,T$,CM,2,1,RGB(BROWN)
VK7JH
MMedit
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 06:54am 18 Feb 2019
Copy link to clipboard 
Print this post

PRINT Time$ added to DO/LOOP - never makes it past 00:00:01

CTRL-C break, then ? Time$ - 00:00:06, so the RTC is ticking again, but only AFTER you CTRL-C break the running code - inside a loop which, does not clear the RTC, so it SHOULD be ticking....

I will now try the T$ idea.

EDIT: Results from adding a 'PRINT Time$' to the loop:





Results of saving Time$ to T$ first is EXACTLY the same - the RTC never moves.

The extra code I added was: T$=Time$ which is now the first line in the DO/LOOP with the blinking tank message:





EDIT: Run the code for 7 seconds, RTC never moves past 1s. CTRL-C break, wait a little, ask for the time$:





This is really odd..... Edited by Grogster 2019-02-19
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 07:16am 18 Feb 2019
Copy link to clipboard 
Print this post

I agree that there seems to be a problem.

I would use a settick to do the timing.
That alone might solve the problem
Rather than using the clock, I prefer my own counter.
  Quote   DO
n = n +
1
PRINT TimeX$(n)
PAUSE 500

LOOP

FUNCTION TimeX$(u AS INTEGER)
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


It is counting at double speed here but with the two pauses as in your code, it should be close.
I would still use settick.

JimEdited by TassyJim 2019-02-19
VK7JH
MMedit
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 07:25am 18 Feb 2019
Copy link to clipboard 
Print this post

I....am....a....phucking.....idiot.





I added a PRINT "DEBUG" right after LOOP UNTIL PIN(BLU)=0 OR BUTTON line.
This resulted in the above readout.
If everything was working correctly, I should NOT get the debug messages, but I was.
This revealed all.

PIN(BLU) is the top-level tank sensor. It HAS to be out of water(and therefore zero), but I have a hardware short on that one for now to simulate a full tank. Naturally, you can't have the lower sensor out of water at the same time as the upper one IN water, so what was happening, was that the OR operator on the LOOP UNTIL PIN(BLU) OR BUTTON line, was seeing that the top-level sensor was now under water, so it was then looping, and it comes around the same loop again, and falls over itself.

As soon as I removed the hardware short on the BLU input, the problem went away, and the timer now works.

Sheesh.....

My brain sometimes.....
Smoke makes things work. When the smoke gets out, it stops!
 
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