![]() |
Forum Index : Microcontroller and PC projects : Settick start timing
Author | Message | ||||
expo Newbie ![]() Joined: 10/01/2016 Location: AustraliaPosts: 25 |
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 KingdomPosts: 2170 |
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: AustraliaPosts: 25 |
thanks capt for your early morning reply..... expo |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
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: AustraliaPosts: 25 |
Thanks Jim, good suggestion. expo |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
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. |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |