Skip to content

Timers

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.

Control Modes

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).

In Enable mode, you turn the timer on and off with the turnOn/turnOff method pairs.

Timers Tab
Timers Tab

See Synchronizing Events for information on the Sync to State Change option.

Pulse Control

The Timer can operate in two modes, Standard and Early Pulse, depending on the state of the Early Pulse checkbox.

Standard

In standard mode, the tick event and the timer output fires after one timer period has passed. Use this to time events starting from when you first turn the timer on with the start or turnOn method.

Standard Flow Diagram

Early Pulse

In Early Pulse mode, the tick event and the timer output fires immediately after you call the start or 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

Note

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.

Slot name Event
s_MyTimer1_tick Fires on each tick of MyTimer1. See Pulse Control for the flow diagram

The timer slot method has the form s_{TIMER_NAME}_tick. Type def s_ in the Pynapse Code Editor and let the code completion do the work for you.

Example

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')

Methods

All control methods have the form p_Timer.{TIMER_NAME}.{METHOD}. Type p_ in the Pynapse Code Editor and let the code completion do the work for you.

Setup

setPeriod

p_Timer.MyTimer.setPeriod(period_sec)

Set the period between timer ticks.

Inputs Type Description
period_sec number New period, in seconds

setRepeats

p_Timer.MyTimer.setRepeats(reps)

Set the number of ticks before the timer finishes, when timer is in Trigger mode. Can be -1 to run indefinitely.

Inputs Type Description
reps number Number of times to repeat the timer tick

Control

turnOn

p_Timer.MyTimer.turnOn()

Start a timer that has Control mode set to Enable. This call is required to start any timer in Enable mode.

turnOff

p_Timer.MyTimer.turnOff()

Stop a timer prematurely. This only works with timers that have Control mode set to Enable.

start

p_Timer.MyTimer.start()

Start a timer that has Control mode set to Trigger. This call is required to start any timer in Trigger mode.

Status

Get information on the current state of the timer.

getCount

n_ticks = p_Timer.MyTimer.getCount()

Returns the number of times the timer has fired. See Pulse Control for a flow chart example.