Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:53 11 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 : Question about settick

Author Message
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 600
Posted: 02:55pm 14 Apr 2018
Copy link to clipboard 
Print this post


settick never fires while waiting for console input.

Is that how it should be working?


Option EXPLICIT
SetTick 1000,tock,4
Dim k, count=0

Do
Input "Waiting for tick to fire ";k
Print "main loop "; count
Loop

Sub tock
count=count+1
Print "Ding Dong ";count
End Sub
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 04:46pm 14 Apr 2018
Copy link to clipboard 
Print this post

Yes.
Use inkey$ instead.

Microblocks. Build with logic.
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1671
Posted: 07:43pm 14 Apr 2018
Copy link to clipboard 
Print this post

MB is correct.

From the MMbasic manual for Maximites (v4.5)
  Quote  Up to four periodic interrupts (or regular “ticks”) with periods specified in milliseconds can be setup using the SETTICK statement. This interrupt has the lowest priority. Using the ON KEY command an interrupt can be generated whenever a key is pressed.
Interrupts can occur at any time but they are disabled during INPUT statements. If you need to get input from the keyboard while still accepting interrupts you should use the INKEY$ function or the ON KEY command.
When using interrupts the main program is completely unaffected by the interrupt activity unless a variable used by the main program is changed during the interrupt


EDIT:
I did not find the text above (about interrupts) in the manual for the Micromites (v5.4). Geoff should maybe complete that.

I think this could be a replacement for Input (and LINE INPUT) that works with SETTICK (not tested).

MichaelEdited by twofingers 2018-04-16
causality ≠ correlation ≠ coincidence
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2171
Posted: 09:47pm 14 Apr 2018
Copy link to clipboard 
Print this post

  Quazee137 said  
settick never fires while waiting for console input.

Is that how it should be working?



yes.

Input is a very blunt instrument and as you have discovered, once you disappear inside it your own program loses control of things until INPUT returns.

There was a thread a little while back where a number of options were posted that give you much better functions that play nice with your code and still give you the input you require as shown in rave's link in the previous post and Peter63 function here Edited by CaptainBoing 2018-04-16
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 600
Posted: 04:55am 15 Apr 2018
Copy link to clipboard 
Print this post


Thanks everyone for the replies.

I looked in the 5.4 manual for the Micromites and did not see any thing
showing it would not work.

This will also apply to LINE INPUT ?

So inkey$ will do.

Quazee
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 06:03am 15 Apr 2018
Copy link to clipboard 
Print this post

  twofingers said  I did not find the text above (about interrupts) in the manual for the Micromites (v5.4). Geoff should maybe complete that.

Page 40.
Geoff Graham - http://geoffg.net
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 600
Posted: 06:32am 15 Apr 2018
Copy link to clipboard 
Print this post

Geoffg is there an updated version of the 5.4 MicroMite user manual?

Page 40 shows information on the Timing related to

PAUSE, PULSE, TIMER and SETTICK.


Quazee


Thanks. Found it on 38 and 39 under Interrupts
Edited by Quazee137 2018-04-16
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2171
Posted: 01:21pm 15 Apr 2018
Copy link to clipboard 
Print this post

  Quazee137 said  
So inkey$ will do.


Not on its own. INKEY$ grabs any *single* character waiting in the buffer, if there's nothing waiting you get the empty string ""

So what you'll have to do is grab characters in a loop and build up your input data in a string variable, generally until INKEY$ returns character (13) - this is the enter key on most keyboards. Then will you have your "INPUT" string in your variable.

it isn't hard to do but if you want something canned, use one of the functions mentioned earlir.

I rarely use INPUT at all, only when I can afford to wait indefinitely in a program of for debugging etc. At any time in main threads where other things are happening in the background I always build up a string using the method above.Edited by CaptainBoing 2018-04-16
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1671
Posted: 01:40pm 15 Apr 2018
Copy link to clipboard 
Print this post

  Geoffg said  
  twofingers said  I did not find the text above (about interrupts) in the manual for the Micromites (v5.4). Geoff should maybe complete that.

Page 40.

Thanks Geoff. All good!
I found this
  Quote  Interrupts can occur at any time but they are disabled during INPUT statements.
on page 39 in the manual for Micromites (MM V5.04.08).
(I scanned the manual only for the occurence of SETTICK)

Michael



causality ≠ correlation ≠ coincidence
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9750
Posted: 12:21am 16 Apr 2018
Copy link to clipboard 
Print this post

  CaptainBoing said  
  Quazee137 said  
So inkey$ will do.


Not on its own. INKEY$ grabs any *single* character waiting in the buffer, if there's nothing waiting you get the empty string ""


Yes indeed. I made that mistake a few times, when I thought that the keyboard input was buffered - it isn't. (well, not past one byte it isn't)
Smoke makes things work. When the smoke gets out, it stops!
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2171
Posted: 07:33am 16 Apr 2018
Copy link to clipboard 
Print this post

  Grogster said   ... the keyboard input was buffered - it isn't. (well, not past one byte it isn't)


good point. You have to scan the keys (I always do it in in the main loop) fairly frequently and build up a global variable, I then set a flag when char(13) received so anything that needs to know about input gets signaled there is a complete line waiting.
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 08:35am 16 Apr 2018
Copy link to clipboard 
Print this post

?? Keyboard input is buffered otherwise you would miss keystrokes.
INKEY$ does not wait when there is nothing in the buffer.

I always make sure i use INKEY$ about every 200ms or faster. This will keep the user happy as longer times will be felt as being non responsive.


Microblocks. Build with logic.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 08:45am 16 Apr 2018
Copy link to clipboard 
Print this post

Yes, the console input is buffered (128 characters). So, for example, the user could type in 20 characters and the next 20 calls to INKEY$ will return all 20 one by one.

Interrupts should be allowable during INPUT and LINE INPUT but it is amazingly difficult to implement so it has remained on my ToDo list for the time being.
Geoff Graham - http://geoffg.net
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9750
Posted: 09:29am 16 Apr 2018
Copy link to clipboard 
Print this post

Really? That's never worked for me. If I check INKEY$ at the time I am expecting a keystroke, I get it. If I check it any other time - even if keys have been pressed, I always get back an empty string, so the code never does what it should.

IE: If I check INKEY$ inside a loop, and grab characters as they arrive, no problem.
If I don't check INKEY$ inside a loop, and just request a key from INKEY$, it is always "". I assumed this was cos at the time of the request, no key was being pressed, so you get back an empty string.

I will have a play with this command now - perhaps I was doing something else wrong at the same time.

EDIT: I am wrong. Totally wrong.





This test code does exactly what Geoff says it does. At the time I was trying to get INKEY$ to work for me, I must have been doing something wrong.

I stand corrected. Edited by Grogster 2018-04-17
Smoke makes things work. When the smoke gets out, it stops!
 
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