Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:05 01 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 : Settick start timing

Author Message
expo
Newbie

Joined: 10/01/2016
Location: Australia
Posts: 25
Posted: 04:01am 21 May 2018
Copy link to clipboard 
Print this post

Can someone tell me when "Settick" starts? Is it at the start of the programme, the line position in the programme or, in the case of a subroutine, when the line in the subroutine starts?
Thanks,
expo
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 04:53am 21 May 2018
Copy link to clipboard 
Print this post

  expo said   Can someone tell me when "Settick" starts? Is it at the start of the programme, the line position in the programme or, in the case of a subroutine, when the line in the subroutine starts?
Thanks,
expo


It's at the point in your program where you set it.

You could test this to satisfy your curiosity, by printing out the TIMER, using SETTICK and then in your sub, have it print out the TIMER again. Put a tight DO:LOOP after the settick line so your cpu is just spinning doing nothing.

Subtract one number from the other and you should get the time in your SETTICK + a few for the processing and serial comms.
 
expo
Newbie

Joined: 10/01/2016
Location: Australia
Posts: 25
Posted: 05:09am 21 May 2018
Copy link to clipboard 
Print this post

thanks capt for your early morning reply.....

expo
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 05:35am 21 May 2018
Copy link to clipboard 
Print this post

Often I want the first tick subroutine to occur immediately, rather than wait for a long time for the first timed event.
In those cases, I set the timer then immediately call the SUB

SETTICK 10000, doread "do a reading every 10 seconds
doread ' do the first read 'NOW'


Jim
VK7JH
MMedit
 
expo
Newbie

Joined: 10/01/2016
Location: Australia
Posts: 25
Posted: 05:48am 21 May 2018
Copy link to clipboard 
Print this post

Thanks Jim, good suggestion.

expo
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 02:41pm 21 May 2018
Copy link to clipboard 
Print this post

In JavaScript there is something called SETTIMEOUT.

It works the same as a SETTICK but it will only execute the routine one time.
Currently i simulate it like this:
[code]

SUB DoRead
SETTICK 0, 0, 1

'Do the stuff you need to do

SETTICK 10000, DoRead, 1
END SUB
[/code]

The subroutine is then more self contained as it takes care of its own invocation.
You can even in certain circumstances manipulate how long the interval is.

[code]
SUB DoRead
STATIC INTEGER Interval
SETTICK 0, 0, 1

'Do the stuff you need to do

if Condition1 = true then Interval = 5000 else Interval = 10000

SETTICK Interval, DoRead, 1
END SUB
[/code]

You start the whole thing by just calling it one time. You could add a parameter to control the stop and start of it

[code]
SUB DoRead(Action)
STATIC INTEGER Interval
SETTICK 0, 0, 1
IF Action = "STOP" THEN
EXIT SUB
ENDIF
'Do the stuff you need to do

if Condition1 = true then Interval = 5000 else Interval = 10000

SETTICK Interval, DoRead, 1
END SUB
[/code]

You can add more 'Actions' if needed. Maybe a 'Speed' setting that sets the interval to a certain value.



Microblocks. Build with logic.
 
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