Native Commands¶
TRGen devices can receive some commands, the full instruction set includes:
Program TrgenPort
Start TrgenPort
Set GPIO I/O Direction
Request Implementation parameters
Request TrgenPort Status
Set the TrgenPort level
Get the TrgenPort Level
Get GPIO I/O Direction
Stop the TrgenPort
Program TrgenPort¶
You can program a trigger behaviour in two ways:
Default trigger using
programDefaultTrigger()
tr = client.createTrgenPort(TrgenPin.GPIO0)
# This sends an impulse of duration (default 20µs)
client.programDefaultTrigger(tr) # impulse of default 20µs
tr = client.createTrgenPort(TrgenPin.GPIO0)
# This override the standard duration and sends an impulse.
client.programDefaultTrigger(tr, us=50) # impulse of 50µs
# In this way, all the successive triggers
# sent from GPIO0 PIN will have a duration of 50 microseconds
Advanced programming by manually setting instructions with
setInstruction()
tr = client.createTrgenPort(TrgenPin.NS1)
tr.setInstruction(0, istrActiveFor(10))
tr.setInstruction(1, istrUnactiveFor(5))
tr.setInstruction(2, istrRepeat(0, 3))
tr.setInstruction(3, istrEnd())
client.writeTrgenMemory(tr)
Start Trigger¶
After programming triggers, you can start them with:
client.start()
This command makes the Trgen execute all programmed triggers.
Remember: you must have previously written at least one TrgenPort program into its memory.
Set GPIO I/O Direction¶
You can use this helper to build the complete or partial pinout map to set.
# we choose to set just GPIO0 -> High and the GPIO1 -> Low
mask = DirectionConfig().out(TrgenPin.GPIO0).in(TrgenPin.GPIO1).build()
# once you have it, you can use it as argument in the set_level function
client.set_gpio_direction(mask)
Request Implementation¶
You can get information about the hardware configuration (number of channels, memory length, etc.) with:
impl = client.getImplementation()
print(impl.memory_length) # max number of instructions per trigger
Request TrgenPort Status¶
To check current status of triggers (active/inactive state):
status = client.get_status()
print(status)
This returns an integer bitmask where each bit represents the state of a trigger pin.
Set the Trigger level¶
It is possible to change the polarity (active-high or active-low) for any TrgenPort:
Use the helper funcion set_levellike this in order to build the complete or partial pinout map to set.
# we choose to set just GPIO0 -> High and the GPIO1 -> Low
mask = LevelConfig().high(TrgenPin.GPIO0, TrgenPin.BNCO).low(TrgenPin.GPIO1).build()
# once you have it, you can use it as argument in the set_level function
client.set_level(mask)
Get the Trigger Level¶
To check trigger polarity:
level = client.get_level()
print(bin(level))
Get the GPIO I/O Direction¶
To retrieve the current GPIO configuration:
gpio_state = client.get_gpio_direction()
print(bin(gpio_state))
Stop the TrgenPort¶
To stop the TRGen device use the stop() function
gpio_state = client.stop()