Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:05 09 May 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 : 'flags' in interrupt routine

     Page 2 of 2    
Author Message
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1139
Posted: 07:57am 06 Mar 2025
Copy link to clipboard 
Print this post

  Volhout said  
a%=pin(gp0)
if a% then


if pin(gp0) then



 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4854
Posted: 08:50am 06 Mar 2025
Copy link to clipboard 
Print this post

Even better...
.
PicomiteVGA PETSCII ROBOTS
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2139
Posted: 10:51am 06 Mar 2025
Copy link to clipboard 
Print this post

  JohnS said  Unless you're desperate for every byte of memory just (KISS) use one variable per flag. Easy to read, easy to write, easy to maintain, easy to reuse.

It'll be much faster than some of the stuff just posted, too, especially in the interrupt routine.


arghh!!! it burns! IT BURNS!!!  

Quite right, single variables will be faster, but the SET/RESET subs only take around 300uS on a 48MHz Micromite (further optimisations are available at the expense of legibility) and I really hate wasting 8 bytes to represent a bit and all the extra variables... if MMBasic had a Bit (or even Byte) datatype these routines would likely not exist. my firmly entrenched miserness (years of assembler). It's also nice to be able to see the all the flags using BIN$(flags,64). I guess personal preferences are playing here - I like to see stuff like

Every 47,DuskDawnTimer
FlagSet DuskDawnTimer
Every 60,PipeTempTimer
...
If FlagTest(PipeTempTimer) Then
 FlagRes PipeTempTimer
 PipeTemp=Fix(Tempr(TempSense))
 If FlagTest(HeaterForce) ...

in my progs... which are derivations of the Z80 BIT,SET & RES mnemonics... but I felt going full 8-bit on them is a step too-far - maybe a questionable decision

  ville56 said  use INV instead of NOT.

e.g. Flag=Flag and inv (1<<b)

should work this way ....


the version of MMBasic I use (MicroMites) doesn't have INV(), the FotS article does show a version at the bottom that uses INV.
Edited 2025-03-06 21:03 by CaptainBoing
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3309
Posted: 05:28pm 06 Mar 2025
Copy link to clipboard 
Print this post

  PhenixRising said  
  Volhout said  
a%=pin(gp0)
if a% then


if pin(gp0) then


Unless you're going to be doing something else with pin(gp0) inside the IF statement--like save the state value of the pin. It may have changed by the time you say "pin0State%=pin(pgo)"; better to be able to say "pin0State%=a%" and then deal with any new change the next time you check pin(gp0).

This probably implies that your IF statement is going to be "if pin0State%<>a%".

~
Edited 2025-03-07 03:31 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
58kk90
Regular Member

Joined: 14/06/2023
Location: United Kingdom
Posts: 59
Posted: 06:38am 08 Mar 2025
Copy link to clipboard 
Print this post

I am really grateful for the guidance given, and thought I had decided on using one integer per flag, but I do like the @CaptainBoing idea as it is similar to what I have always done in the 8048 / 8051 / arduino / Pic days where a single bit of a byte represented a particular flag so I decided to give that a try.

Seting and clearing the bit work fine, but I cannot get the 'Test a flag' function to work.

Most likely it's due to my limited knowledge, but I cannot see what the issue is

Dim Flags as integer

Flags = 1                       ' set a bit for testing


do

  if FlagTest(0) = 0 then print "bit is 0"

loop
End



Function FlagTest(b As Integer)
    FlagTest=Abs(Sgn(Flags And (&o1<<b)))
End Function

When I try and run this I get

[12] If FlagTest(0) = 0 Then Print "bit is 0"

"Error  : Variable type not specified"

I am using PicoMite MMBasic Version 6.00.00b4

Any suggestions please.

Tony
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6219
Posted: 07:20am 08 Mar 2025
Copy link to clipboard 
Print this post

My guess is that you have
option default none

set

If so, you have to give the function a type.

Jim
VK7JH
MMedit
 
58kk90
Regular Member

Joined: 14/06/2023
Location: United Kingdom
Posts: 59
Posted: 08:08am 08 Mar 2025
Copy link to clipboard 
Print this post

Jim, you are correct I do have Option default none set.

How do I give the function a type? I have defined b as integer

Tony
 
58kk90
Regular Member

Joined: 14/06/2023
Location: United Kingdom
Posts: 59
Posted: 08:11am 08 Mar 2025
Copy link to clipboard 
Print this post

Cancel the last, I have figured that i've done :-

Function FlagTest(b As Integer) as integer


Now it works :-)

Tony
Edited 2025-03-08 18:12 by 58kk90
 
     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