Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 08:56 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

Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 06:59pm 05 Dec 2020
Copy link to clipboard 
Print this post

I've read through all the posts about Settick

This does not work
Anyone know why?
SetTick 1000,UpDateTime,1   'Call every second, print date/time
 Do
   Print "hello"
   Pause 10000 'run every 10 seconds
 loop
End
Sub UpDateTime ' called by 1 second interrupt from SetTick
 print time$
End Sub

It prints the time every second but not the text I ask it to every 10 seconds
Edited 2020-12-06 04:59 by lew247
 
qwerty823
Newbie

Joined: 30/07/2020
Location: United States
Posts: 30
Posted: 07:16pm 05 Dec 2020
Copy link to clipboard 
Print this post

It works for me. Try adding a "trace on" at the top and see what line numbers get executed.

SetTick 1000, UpDateTime, 1

Do
 Print "hello"
 Pause 10000
Loop
End

Sub UpDateTime
 Print time$
End Sub


> run
hello
14:17:39
14:17:40
14:17:41
14:17:42
14:17:43
14:17:44
14:17:45
14:17:46
14:17:47
14:17:48
hello
14:17:49
14:17:50
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 08:00pm 05 Dec 2020
Copy link to clipboard 
Print this post

It could be one of the bugs in Pi-Cromite
I changed the time to 5 seconds
it just loops between lines 11 and 12


TRACE ON
SetTick 1000, UpDateTime, 1

Do
Print "hello"
Pause 5000 ' 5 seconds
Loop
End

Sub UpDateTime
Print time$
End Sub


If I don't use SETTICK then it works perfectly

I kinda need settick to keep a clock running

EDIT is there a way to keep the program running but only doing what it says in the settick? as in using 2 setticks?
Edited 2020-12-06 06:02 by lew247
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 08:05pm 05 Dec 2020
Copy link to clipboard 
Print this post

OK
It looks like the Pi PAUSE hides the interrupts.

Instead of PAUSE 10000

try
for n = 1 to 100
PAUSE 100
next n

That will allow the one second ticks to fire.

Jim
VK7JH
MMedit
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 08:12pm 05 Dec 2020
Copy link to clipboard 
Print this post

You sir are a genius  
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 08:15pm 05 Dec 2020
Copy link to clipboard 
Print this post

Use the interrupt to count the ten seconds, and set a flag for the main routine.

For example (untested)
countdown = 10
SetTick 1000,UpDateTime,1   'Call every second, print date/time
Do
  if countdown = 0 then
    Print "hello"
    countdown = 10
  endif
  < do other amazing stuff here >
loop
End

Sub UpDateTime ' called by 1 second interrupt from SetTick
countdown = countdown - (countdown > 0)  ' only decrement if not zero
print time$
End Sub

Visit Vegipete's *Mite Library for cool programs.
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 09:26pm 05 Dec 2020
Copy link to clipboard 
Print this post

Jim has highlighted a serious step to fluid flow of a program, never pause for long periods, always pause for lots of small ones  

it might add to the complexity in a small way to have to count more steps but it allows your code to do stuff and greatly helps in the asynchronous nature of your code, just as vegipete illustrates.
Edited 2020-12-06 07:26 by CaptainBoing
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 02:21pm 06 Dec 2020
Copy link to clipboard 
Print this post

NO matter what I try I can't get it perfect
I can run the program without setticks and a timer to call the weather update and it works fine but I've no way to update the time on the display every second

If I use 2 setticks one for updating the time and one for updating the weather call it crashes

It crashed using both for next loop and countdown timer

I can get it working using one settick and using the for next timer to update the weather  
Also the time doesn't update when it's calling the weather sub so it skips 2-3 seconds

I've been experimenting all day and last night trying to find a way to do it
This is with trace on start time and crash time
15:35:31
15:29:31 crashed on line 18 PAUSE 10
15:47:26
15:51:16 crashed on line 18 PAUSE 10
15:56:45
14:00:35 crashed line 18  PAUSE 10
14:03:11  removed the sub that parses the 15000 character weather call
and it's still running now almost 20 minutes later
but
The time on the display still skips when updating the weather

I guess it's time to either learn Python to talk to the Pi direct, or find another micromite with HDMI and WiFi or use a 2nd MM with maybe an Esp8266 to parse the weather and use the Pi to send it to the HDMI
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 03:05pm 06 Dec 2020
Copy link to clipboard 
Print this post

If you can assure that no pauses or delays in your main loop cause the loop to take more than a second, this can work:

do     ' main loop
 ss$=mid$(time$,7,2): if ss$ <> sec$ then: sec$=ss$: print time$: endif
 ' the rest of your program
loop

> do: ss$=mid$(time$,7,2): if ss$ <> sec$ then: sec$=ss$: print time$: endif: loop
11:01:36
11:01:37
11:01:38
11:01:39
11:01:40
11:01:41
11:01:42
11:01:43
11:01:44
11:01:45
11:01:46
11:01:47
11:01:48
11:01:49
11:01:50
11:01:51
11:01:52
11:01:53
11:01:54
11:01:55
11:01:56
11:01:57
11:01:58
11:01:59
>

~
Edited 2020-12-07 01:09 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 04:54pm 06 Dec 2020
Copy link to clipboard 
Print this post

Thanks
Unfortunately I have 3 sets of data I need collecting and parsing
They take a total of 3 seconds to do
and even using what you suggested with settick set to 10 seconds so it collects the data every 10 seconds the clock still stops while it's doing it

I have the following
Settick
Do
update time as per your suggestion
loop

sub collect data
collect data1
parse data1
collect data2
parse data2
collect data3
parse data3
update display
END SUB

SUB display
displays information from parsed data
END SUB
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 05:00pm 06 Dec 2020
Copy link to clipboard 
Print this post

Are you using settick to collect and/or parse data?

If you are then that is breaking the golden rule - Processing in interrupts must be as short as possible

Interrupts can't interrupt other interrupts

Anything that take more than a millisecond to process should be in the main program - never, ever in an interrupt

By all means use the interrupt to set the timing but just set a flag in the interrupt routine for the main program to know it is time to do something
Edited 2020-12-07 03:02 by matherp
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 05:42pm 06 Dec 2020
Copy link to clipboard 
Print this post

  lew247 said  Unfortunately I have 3 sets of data I need collecting and parsing

There is no settick in code sample I provided. It relies on a change in the seconds string in time$.

The question I would have, is whether your subroutines really need 3 seconds. For instance, if you are reading a string of DS18B20s, your code can be rewritten to use the TEMPR START command. Depending on what else your routines do, they may possibly also be rewritten.

Another possibility is if the subroutines each take less than a second (but cumulatively more), you could put the code I provided after each one.

MMBasic on the pi is quick--I would wonder what code prevents a main loop from completing more than once a second. I had a 2300+ line program with a dozen ds18b20s which looped many times a second on a pi.
Edited 2020-12-07 03:47 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 07:10pm 06 Dec 2020
Copy link to clipboard 
Print this post

it's collecting weather data from an online server which takes a while to process, download and then parse
There are 3 of them and one is 15000 characters long
Matherp: I was originally only using the interupt to set the time to display every second and using a pause to collect and parse the data but it kept crashing and as Pi-Crommite isn't being updated anymore I was trying to find another way of doing it.

The collecting and parsing takes a minimum of 3 seconds
I think the only real option is to do the collecting and parsing on another micro and use the pi-cromite for the main program, unless there is another mmbasic device that has internet access
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 08:06pm 06 Dec 2020
Copy link to clipboard 
Print this post

Break you collect data sub up into smaller chunks.
In the main loop , do each small chunk in turn and then the one second clock ticks can happen in their own time without stopping the main work.
The only time that the main data collection is critical is when you actually fetch the data. TCPIP can be slow.
The rest of the time, things can wait.

Much as I like putting everything into a sub, sometimes a big main loop is better.

Jim
VK7JH
MMedit
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 08:19pm 06 Dec 2020
Copy link to clipboard 
Print this post

[Posted by mistake]

~
Edited 2020-12-07 06:21 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
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