Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 00:37 14 Nov 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 : MMBasic v4.5 - how to pause/restart tick and share main/isr variables

     Page 2 of 2    
Author Message
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4139
Posted: 02:03pm 09 Jun 2020
Copy link to clipboard 
Print this post

Why not use Rob's ring buffer?

The test for head<>tail looks central.

If you use something like that you won't be trying to get a change to MMBasic so you won't have to persuade anyone to change the multiple versions and also won't have to wait.

Do you have a use case that can't be made to work without needing a change to MMBasic?

John
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1955
Posted: 09:57pm 09 Jun 2020
Copy link to clipboard 
Print this post

You won't get a change to MM Basic for this. As JohnS allured to, don't really have a case where there is not a simple workaround.

Just on the subject of an ISR, the other alternative that I and others often use is to have a faster ISR handling a number of time sliced tasks / flags with individual task counters. Something like 1ms to 20ms with a call counter to handle the code at the 100ms count, that way the main code knowns where the 100ms trigger is at, and can decide when it's safe to update the shared variables in main without any unwanted ISR timing clash.

Mike.

EDIT: To make it clear for those new to MM Basic, this simple piece of code demonstrates. NOTE: Code is for the CMM2 as that's what I'm playing with at the moment but will run with on ARMH7, MM100 etc with "mode 1" removed.

Pressing s will flag a DoChange in the main loop. The 100ms Counter value at time of save is displayed in RED, the running ISR trip count display for the 100ms timer is white.

Setting a SetTick timer to 100ms produces the same timer values as a 1ms timer with a counter for a 100ms event.

The Main loop and the T1_INT interrupt procedure both share PrintLine(). Therefore if DoChange in the Main loop is ever interrupted by T1_INT, then the displayed 100ms T1_INT interrupt time will also be highlighted in RED instead of white.  


 option explicit
 option default none
 
 const Tperiod=1   ' timer period in ms 1 to 20
 const MaxCutoff=99-(Tperiod+1) ' increase for slow dev/code in DoChange section.

 dim float Tval
 dim integer x,y,linesp,colsp,DoChange,T100,Sval
 
 mode 1 : font 1 : colsp=60 : linesp=16 : x=10 : y=10
 Const VertLimit=MM.VRES-Linesp  
 Const HorzLimit=MM.HRES-colsp  

 SetTick Tperiod,T1_INT(),1 : timer=0 : cls
 
Sub T1_INT()
 T100=T100+Tperiod
 if T100>=100 then
   Tval=timer : T100=0
   Printline(str$(Tval,2))
   timer=0
 endif
End Sub
 
 Do
   if DoChange and T100 =< MaxCutoff then
     Sval=T100
     colour RGB(red),RGB(black)
     DoChange=0 : PrintLine("S "+str$(Sval,2))
     colour RGB(white),RGB(black)
   endif

   Select case ucase$(INKEY$)
     Case "S"
       DoChange=1
     Case "Q"
       end
     Case "C"
       cls : end
   End Select
 Loop
 
Sub PrintLine(ThisLine as string)
 y=y+linesp
 if y > VertLimit then
   y=10 : x=x+colsp
   if x > HorzLimit then
     x=10 : y=10 : cls
   endif
 endif
 Text x,y,ThisLine
End sub
end

Edited 2020-06-11 18:14 by KeepIS
NANO Inverter: Full download - Only Hex Ver 8.1Ks
 
     Page 2 of 2    
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