Hi,
Im trying to make a program that does someting similar as my code below (but this will not compile).
I have a main scan of 10 min, every two minutes before a full hour, I would like to start two burst samplings with a scan of 10 sec and 100 msec.
I would prefere to avoid fast scans between :00 - :58 to save on battery.
I need the two Burst modes to be in seperate SlowSequences to avoid missing samples (my real program will not run in pipeline mode).
Any idea how I can get this to work, and made the code pretty?
Thanks,
John
Public PTemp, Batt_volt
Sub Burst1
SlowSequence
Scan (10,Sec,0,0)
PanelTemp (PTemp,15000)
If TimeIntoInterval (0,60,Min)
Exit Sub
EndIf
NextScan
EndSub
Sub Burst2
SlowSequence
Scan (100,mSec,0,0)
Battery (Batt_volt)
If TimeIntoInterval (0,60,Min)
Exit Sub
EndIf
NextScan
EndSub
'Main Program
BeginProg
Scan (10,Min,0,0)
PanelTemp (PTemp,15000)
Battery (Batt_volt)
' Do meassuremnts here...
NextScan
SlowSequence
Scan (2,Min,0,0)
If TimeIntoInterval (58,60,Min)
Call Burst1
Call Burst2
EndIf
NextScan
EndProg
I think I found a general solution to my problem. Instead of using 'Sub', I use 'Do...Loop' with the 'TriggerSequence' command. That does what I want.
SequentialMode
Const Burst_Period = 5
Const Burst_Intervall = 30
Const Burst_Intervall_unit = sec
Const Burst_ScanIntervall_1 = 1
Const Burst_ScanIntervall_unit_1 = sec
Const Burst_ScanIntervall_2 = 100
Const Burst_ScanIntervall_unit_2 = msec
Public Wild1, Wild2, Wild3 As Long
'Main Program
BeginProg
Scan (10,Sec,0,0) 'main scan can be any interval
Wild1 = RND*100
'Do main meassuremnts here...
NextScan
SlowSequence '(1) Controls the burst interval
Scan (Burst_Period,Burst_Intervall_unit,0,0)
If TimeIntoInterval (Burst_Intervall-Burst_Period,Burst_Intervall,Sec)
TriggerSequence (2,0) 'Trigger first burst sampling (SlowSequence 2)
TriggerSequence (3,0) 'Trigger second burst sampling (SlowSequence 3)
EndIf
NextScan
SlowSequence '(2)
Do
WaitTriggerSequence
Scan (Burst_ScanIntervall_1,Burst_ScanIntervall_unit_1,0,0)
Wild2 = RND*100
'Do burst meassuremnts 1 here...
If TimeIntoInterval (0,Burst_Intervall,Burst_Intervall_unit)
ExitScan
EndIf
NextScan
Loop
SlowSequence '(3)
Do
WaitTriggerSequence
Scan (Burst_ScanIntervall_2,Burst_ScanIntervall_unit_2,0,0)
Wild3 = RND*100
'Do burst meassuremnts 2 here...
If TimeIntoInterval (0,Burst_Intervall,Burst_Intervall_unit)
ExitScan
EndIf
NextScan
Loop
EndProg
It looks like the main issue is that the burst sequences sit inside a slow-sequence block that already controls the timing. Because of that, the calls won’t run the way you expect, and the compiler rejects the structure.
A common solution is to move the timing logic outside the burst sequences and trigger each burst with its own flag. Then each burst runs in its own SlowSequence, independent of the main scan. That way you avoid timing conflicts and still keep the fast scans from running outside the :58–:00 window.
You’re on the right track, you just need cleaner separation between the trigger and the burst routines so each sequence can run safely on its own.
Hi John, you might try using two separate SlowSequences triggered by If TimeIntoInterval(58,60,Min) inside your 2-min scan, but instead of nesting the bursts inside the main scan, schedule them as independent sequences. That way, each Burst runs without interfering with the other, avoiding missed samples. Also, ensure the Scan intervals in the bursts are short enough for your 10 sec and 100 ms needs, and use ExitSub to prevent overshoot.
Understanding the Problem
You want to:
Run a main scan every 10 minutes.
At 2 minutes before the hour (:58), start two burst scans:
One of 10 seconds
One of 100 milliseconds
Constraints:
Avoid continuous fast scanning outside the bursts to save battery.
The two bursts should run in separate SlowSequences, so they don’t interfere.
You don’t want to run in pipeline mode.
Approach
Use a main SlowSequence for your 10-minute scans.
Create two separate SlowSequences for the bursts:
Each sequence triggered by a time condition (:58).
Each sequence handles its own sampling interval independently.
Avoid fast scans between :00–:58 by only activating the sequences conditionally.
Pseudo-Code Example
def main_scan():
while True:
perform_main_scan() # your 10-min scan
wait_until_next_10min()
def burst_scan_10sec():
while True:
if time_is_near_58min():
start_burst_scan(duration=10, interval=0.1) # 10 sec, 100ms intervals
sleep_short() # check periodically
def burst_scan_100ms():
while True:
if time_is_near_58min():
start_burst_scan(duration=10, interval=0.001) # 10 sec, 1ms intervals
sleep_short()
# Run main scan and bursts as independent sequences
run_in_slow_sequence(main_scan)
run_in_slow_sequence(burst_scan_10sec)
run_in_slow_sequence(burst_scan_100ms)
Notes:
time_is_near_58min() checks if the current minute is around :58.
start_burst_scan() handles the sampling loop with specified duration and interval.
Each SlowSequence runs independently, so bursts won’t interfere with each other.
sleep_short() ensures the loop doesn’t consume unnecessary CPU while waiting.
Tips for “Pretty” Code
Encapsulate burst logic in a reusable function to avoid duplicating code.
Use constants for durations and intervals.
Document your sequences clearly so anyone reading knows which SlowSequence does what.
Consider using events or triggers if your framework supports them, rather than constant polling.
If you want, I can rewrite this in a fully compilable code example in your target language, using proper SlowSequence/Sub syntax, so it can run directly without errors.
Do you want me to do that?