Timers are used independently of states to control program flow or stimulus presentation.
The period and number of repeats can be modified at runtime within the Python code.
There are two Control types, Trigger and Enable.
In Trigger mode, you initiate the timer with the
start method and it runs until it
has reached the set number of Repeats (or indefinitely if Repeats is set to -1).
See Synchronizing Events for information on the Sync to State Change option.
The Timer can operate in two modes,
Early Pulse, depending on the state of the
Early Pulse checkbox.
|Standard Flow Diagram|
In Early Pulse mode, the tick event and the timer
output fires immediately after you call the
turnOn method (or
when the next state change happens if Sync to State Change is enabled). Use this to start
timed stimulus presentations immediately.
|Early Pulse Flow Diagram|
In Trigger mode,
Repeats must have a value greater than 1 to enable the
Early Pulse checkbox.
Slot Methods for Responding to Timer Ticks
These slot methods capture status information about the timers. They are available as method definitions inside Pynapse states for each timer. Write a method with this name to react to the corresponding event.
The timer slot method has the form
def s_ in the
Pynapse Code Editor and let the code completion do the work for you.
Set a timer that fires once per second for 10 seconds, and print the current timer count when it fires
class Always: # StateID = 0 def s_Mode_standby(): p_Timer.MyTimer.setPeriod(1) p_Timer.MyTimer.setRepeats(10) def s_Mode_recprev(): p_Timer.MyTimer.turnOn() def s_Timer1_tick(count): print(count)
In this example, Synapse stops the recording after 10 seconds and switches to Idle.
class Always: # StateID = 0 def s_Mode_standby(): p_Timer.MyTimer.setPeriod(10) p_Timer.MyTimer.setRepeats(1) def s_Mode_recprev(): p_Timer.MyTimer.turnOn() def s_Timer1_tick(count): print('done') syn.setModeStr('Idle')
All control methods have the form
p_ in the Pynapse Code Editor
and let the code completion do the work for you.
Set the period between timer ticks.
Set the number of ticks before the timer finishes, when timer is in Trigger mode. Can be -1 to run indefinitely.
Start a timer that has Control mode set to Enable. This call is required to start any timer in Enable mode.
Stop a timer prematurely. This only works with timers that have Control mode set to Enable.
Start a timer that has Control mode set to Trigger. This call is required to start any timer in Trigger mode.
Get information on the current state of the timer.
n_ticks = p_Timer.MyTimer.getCount()
Returns the number of times the timer has fired. See Pulse Control for a flow chart example.