Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 01:12 02 Sep 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 : Playing around with SETTICK.

Author Message
pwillard
Guru

Joined: 07/06/2022
Location: United States
Posts: 313
Posted: 11:16am 08 Aug 2022
Copy link to clipboard 
Print this post

Maybe its me...

I've been playing around with using SETTICK to create essentially variable rate blinking by issuing successive SETTICK commands to change the "period" on-demand.

Now I believe that SETTICK PAUSE <target> ,1 and SETTICK RESUME <target>,1 are what I really want if I wish to HALT the blinking on an output pin.  

But reading the manual, I saw that SETTICK 0,0,1 would disable the timer.  My observation, so far, shows me that *if* I issue that command "SETTICK 0,0,1", I actually don't seem to be able to re-enable it with a follow-up "SETTICK 1000,<target>,1  (where <target> is my interrupt subroutine, of course).

Am I doing it wrong if I thought "disabling" the tick timer means I can also "re-enable it later" by issuing a standard SETTICK command?  (Because in my test code... I could not re-enable it and I had to reboot to make it work again)
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10379
Posted: 11:39am 08 Aug 2022
Copy link to clipboard 
Print this post

Works fine for me. Not sure why you think you need to use PAUSE and RESUME. They were for a very specific reason. Were you pausing and then issuing the SETTICK 0,0,1? If so you may need to resume after the new settick

SetTick 1000,myint,1
Timer =0
Do
 If Timer>10000 Then
   If T Then
     SetTick 0,0,1
     SetTick 1000,MYINT,1
   Else
     SetTick 0,0,1
     SetTick 2000,MYINT,1
   EndIf
   T= Not T
   Timer =0
 EndIf
Loop
'
Sub myint
 If i Then
   CLS RGB(red)
 Else
   CLS RGB(green)
 EndIf
 Text 0,0,Str$(Timer)
 i=Not i
End Sub
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3399
Posted: 11:55am 08 Aug 2022
Copy link to clipboard 
Print this post

Thanks for this question and this example. I ran it in MMBasic for Windows. It leads me to a question which may be somewhat of a hijacking: Is there a reason why F10 (AUTOSAVE) cannot be made to work in MMBasic for Windows?
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
pwillard
Guru

Joined: 07/06/2022
Location: United States
Posts: 313
Posted: 12:08pm 08 Aug 2022
Copy link to clipboard 
Print this post

  Quote  
SetTick 0,0,1
SetTick 2000,MYINT,1


That example is exactly what I was doing with Picomite... but my experience was that it would not restart.

Hmmm... I'll keep experimenting, I guess.


Follow-up

Confirmed to working now... I'm not sure why I was having a problem with it.
Edited 2022-08-08 22:31 by pwillard
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10379
Posted: 12:19pm 08 Aug 2022
Copy link to clipboard 
Print this post

  Quote  That example is exactly what I was doing with Picomite

I developed/tested the example on the PicoMite V5.07.05b15
Edited 2022-08-08 22:20 by matherp
 
pwillard
Guru

Joined: 07/06/2022
Location: United States
Posts: 313
Posted: 12:39pm 08 Aug 2022
Copy link to clipboard 
Print this post

At this point,  I'm going to blame the pico hardware acting up as my code matched your example.  I'm running the same version of firmware  ;-P



Edited 2022-08-08 22:40 by pwillard
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1270
Posted: 01:32pm 08 Aug 2022
Copy link to clipboard 
Print this post

Playing around with SETTICK


V%=25
start:
Do While Inkey$="":Loop
SetTick 20,bing,1
Do While Inkey$<>"":Loop
GoTo start

Sub bing
 Play sound 4,"B","S",2700,V%
 Inc v%,-1
 If v%<=0 Then
   SetTick 0,0,1:V%=25
   Play stop
 EndIf
End Sub


'no comment
 
pwillard
Guru

Joined: 07/06/2022
Location: United States
Posts: 313
Posted: 02:26pm 08 Aug 2022
Copy link to clipboard 
Print this post

Well, if you are curious... here is my code, as-is. (I managed to break My VT100  stuff by lowercase-ing my codes, no big deal)


' Program:      pulser.bas
' Author:       Pete WIllard
' Version:      0.1
' Target:       picomite
' Date:         2022/08/08
' Time:         09:26:41
' Notes:
' Reference:  Borrowed VT100 Sequences from M. Herhaus code for SOKOBAN
' microprocessor development clock
' 1)  free running fast clock
' 2)  free running slow clock
' 3)  single step
' 4) Exit
'=================================
'
'  Goal - using a VT100 Menu
'         -- Allow selection of clock rates for the Ben Eater 6502 project
'         -- Using a Chainsaw to cut butter, but it's cheaper to implement.
'         -- Quick and dirty test... so lazy coding techniques used
 OPTION EXPLICIT
'=====[ CONST ]==================================================================
 CONST el$=CHR$(27)+"["
 CONST slow = 1000 ' 1000 ms trigger
 CONST fast = 10   ' 10 ms trigger
'=====[ VARIABLES ]==============================================================
 DIM STRING lastmode$ = "slow"  ' Not really using this yet...
 DIM STRING USER$, SW$
'=====[ PINS ]===================================================================
 SETPIN GP2,DOUT
 
'=====[ SETUP ]==================================================================
 PIN(GP2) = 1
 SETTICK slow,clktoggle,1
 
startup:
'=====[ MAIN CODE ]==============================================================
 tcls
 at 2,30
 PRINT "Clock Test"
 at 3,30
 PRINT "=========="
 at 5,30: PRINT "1. Astable fast clock"
 at 6,30: PRINT "2. Astable slow clock"
 at 7,30: PRINT "3. Single step clock"
 at 8,30: PRINT "4. Exit"
 
 at 10,30
 
 user$ = ""
 DO WHILE user$ = ""
   user$ = INKEY$
 LOOP
 at 11,30
 
 SELECT CASE user$
   CASE "1"
     'SETTICK 0,0,1    ' Didn't seem to let the next line work
     SETTICK fast,clktoggle,1
   CASE "2"
     ' SETTICK 0,0,1   ' Didn't seem to let the next line work
     SETTICK slow,clktoggle,1
   CASE "3"
     PRINT " "
     SETTICK 0,0,1  '  But workes here... \_('')_/
     PIN(GP2) = 0
     PRINT "Single Step Mode - Press `s` to Toggle, `q` to Cancel"
           DO
             sw$ = ""
             DO WHILE sw$ = ""
               sw$ = INKEY$
             LOOP
             sw$ = LCASE$(sw$)
             IF sw$ = "s" THEN
                 clktoggle
                 PAUSE (250)
                 clktoggle
             ENDIF
           LOOP UNTIL sw$ = "q"
           lastmode$="Single"
   CASE "4"
     GOTO theend
   CASE ELSE
         lastmode$ = ""
 END SELECT
 
 GOTO startup
 
'================================================================================
theend:
' Bye
 
'=====[ SUBROUTINES ]============================================================
 
SUB clktoggle
 LOCAL status
 status = NOT PIN(gp2)
 PIN(gp2) = status
END SUB
 
 
SUB tcls
' clear terminal screen
 PRINT el$;"2j";
 home
END SUB
 
SUB home
' cursor top left
 PRINT el$;"h";
END SUB
 
SUB at row,col
 PRINT el$;;STR$(row);"h";el$;STR$(col);"g";
END SUB
 



Edited 2022-08-09 00:55 by pwillard
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1270
Posted: 02:59pm 08 Aug 2022
Copy link to clipboard 
Print this post


' Reference:  Borrowed VT100 Sequences from M. Herhaus code for SOKOBAN

youre welcome
Edited 2022-08-09 01:04 by Martin H.
'no comment
 
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