Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 22:56 01 May 2024 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 : MMbasic "time"

Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 04:40am 25 Jan 2016
Copy link to clipboard 
Print this post

Is there an easy way to get a 1 second pulse output at the start of every second after setting the internal clock?

I've been reading the manual and found
TIME$ = "HH:MM:SS"
or
TIME$ = "HH:MM"
or
TIME$ = "HH"
Sets the time of the internal clock. MM and SS are optional and will default
to zero if not specified. For example TIME$ = "14:30" will set the clock to
14:30 with zero seconds.
The time is set to "00:00:00" on power up.

but it doesn't say what you can do with the time once its set?

I'm still trying to get my head round basic, I learnt it first when I was 16 in 1977 on a computer at college which had 4k ram, basic was programmed into it by punchcard and we typed the programs in manually, and there was only a printer output with no monitor back then.

Its hard remembering some of the commands, and there are a good few new ones to learn
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8591
Posted: 04:55am 25 Jan 2016
Copy link to clipboard 
Print this post

here is how I would do it

Const pulsepin=21 'assign the pin you want the pulse on
Const width=50 'set the pulse time in msec
SetPin pulsepin,dout 'set the chosen pin as an output
pin(pulsepin)=0 'set whether the pin should rest low or high
SetTick 1000,pulseout 'setup a 1 second interrupt
Do 'wait forever, the pulses will happen in the background
Loop
'
Sub pulseout 'called every second
Pulse pulsepin,width 'fire off a pulse for "width" msec
End Sub
Edited by matherp 2016-01-26
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 712
Posted: 05:33am 25 Jan 2016
Copy link to clipboard 
Print this post

Wow, what a service.
A complete "Program" from Peter

The thing that makes it is the Timer "SetTick 1000,pulseout".

Have a look at the manual, it is easy to understand:

************************************************************************************
A timing function is also provided by the SETTICK command. This command will generate an interrupt at
regular intervals (specified in milliseconds). Think of it as the regular "tick" of a watch. For example, the
following code fragment will print the current time and the voltage on pin 2 every second. This process will
run independently of the main program which could be doing something completely unrelated.
SETPIN 2, AIN
SETTICK 1000, DOINT
DO
‘ main processing loop
LOOP
SUB DOINT ‘ tick interrupt
PRINT TIME$, PIN(2)
END SUB
The second line sets up the "tick" interrupt, the first parameter of SETTICK is the period of the interrupt (1000
mS) and the second is the starting label of the interrupt code. Every second (ie, 1000 mS) the main processing
loop will be interrupted and the program starting at the label DOINT will be executed.
************************************************************************************
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 08:55am 25 Jan 2016
Copy link to clipboard 
Print this post

Thank you so much
 
Bizzie
Senior Member

Joined: 06/07/2014
Location: Australia
Posts: 185
Posted: 01:53pm 25 Jan 2016
Copy link to clipboard 
Print this post

Further to the excellent explanations above.

Is there any way to synchronize the SETTICK to the start of the minute or hour?
Rob White
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 903
Posted: 02:34pm 25 Jan 2016
Copy link to clipboard 
Print this post

  Quote  Is there any way to synchronize the SETTICK to the start of the minute or hour?


I would suppose that the clock and settick are derived from the same signal so if for example your settick arrived 23 seconds behind the start of the hour you could add that difference in your code?
GM
 
mindrobots
Newbie

Joined: 21/05/2014
Location: United States
Posts: 32
Posted: 03:03pm 25 Jan 2016
Copy link to clipboard 
Print this post

What if you set the time to something ending in :00 and the immediately after that do the SETTICK with the interval you want?

By setting the time at :00 you've established the "zero seconds" point and synched the internal RTC. Every tick interval after that should be pretty accurate for the interval you set. I would think this would be accurate enough for most events. You could tune it a bit for drift if needed.

Or like said above, if it is 10:51:00 when you initially set the time then just set the initial SETTICK interval for 9 minutes. The interrupt routine would then always set the interval for 60 minutes (less however long it runs) to have another pulse at the top of the next hour.Edited by mindrobots 2016-01-27
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5907
Posted: 06:29pm 25 Jan 2016
Copy link to clipboard 
Print this post

You can keep testing the time until the seconds (or minutes and seconds) are zero.
You may need to put a flag in to stop the code running more than once.
You set the flag once triggered and then later in your code when the trigger value is past, reset the flag ready for next time.

triggered = 0 ' we only want to run the code once
main:
DO
test$ = TIME$
LOOP UNTIL MID$(test$,7,2)="00" AND triggered = 0
triggered = 1

PRINT test$
GOTO main


The micromites that don't use a crystal and don't have very good timekeeping without fine tuning.

Jim
VK7JH
MMedit   MMBasic Help
 
ajkw
Senior Member

Joined: 29/06/2011
Location: Australia
Posts: 290
Posted: 07:32pm 25 Jan 2016
Copy link to clipboard 
Print this post

In response to Bizzie, perhaps this would do


Dim ss$ As string
SetTick 1000,sync,1
Print Time$

Do

Loop

Sub sync
ss$ = Mid$(Time$,7,2)
Print ".";
If ss$ = "00" Then
SetTick 10000,pulsemin,2 '10000 for 10sec, 60000 for 1 minute
SetTick 0,sync,1 'turn of sync
Print "sync@";Time$
EndIf
End Sub

Sub pulsemin
Print Time$
End Sub


Anthony.


Use code as your own risk & always test for your own suitability.
Edited by ajkw 2016-01-27
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 712
Posted: 08:14pm 25 Jan 2016
Copy link to clipboard 
Print this post

.....and sometimes comes the time, where you reach the point, to use one of the cheap, precise and fully
Micromite supported RTC's......

 
Print this page


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

© JAQ Software 2024