![]() |
Forum Index : Microcontroller and PC projects : Settick
Author | Message | ||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
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 StatesPosts: 30 |
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 KingdomPosts: 1702 |
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: AustraliaPosts: 6283 |
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 KingdomPosts: 1702 |
You sir are a genius ![]() |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
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 KingdomPosts: 2170 |
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 KingdomPosts: 1702 |
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 StatesPosts: 3378 |
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 KingdomPosts: 1702 |
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 KingdomPosts: 10310 |
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 StatesPosts: 3378 |
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 KingdomPosts: 1702 |
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: AustraliaPosts: 6283 |
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 StatesPosts: 3378 |
[Posted by mistake] ~ Edited 2020-12-07 06:21 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |