I'd like to be able to break up a single gate_rising listening event into multiple events.

Currently, we have a pmt connected to a ttl channel that listens for, let's say, 300 microseconds. We count ttl pulses from the pmt using the following code
with parallel:
self.detection.sw.pulse(300 * us)
gate_end = self.ttl0.gate_rising(300 * us) # end of parallel
pmt_counts = self.ttl0.count(gate_end)
delay(long_time * ms)

However, I'd like to break up that single 300 microsecond window into three 100 microsecond windows one immediately after the other. My first thought was to do this:
self.detection.sw.on()
gate_end = self.ttl0.gate_rising(100 * us)
pmt_counts_0 = self.ttl0.count(gate_end)
gate_end = self.ttl0.gate_rising(100 * us)
pmt_counts_1 = self.ttl0.count(gate_end)
gate_end = self.ttl0.gate_rising(100 * us)
pmt_counts_2 = self.ttl0.count(gate_end)
self.decetion.sw.off()
delay(long_time * ms)

However, since count() blocks, this is likely to cause an RTIOUnderflow. Is it possible to do the counting later when I know there will be longer delays such as:
with parallel:
self.detection.pulse(300 * us)
with sequential:
gate_end_0 = self.ttl0.gate_rising(100 * us)
gate_end_1 = self.ttl0.gate_rising(100 * us)
gate_end_2 = self.ttl0.gate_rising(100 * us) # end of parallel and sequential
pmt_counts_0 = self.ttl0.count(gate_end_0)
pmt_counts_1 = self.ttl0.count(gate_end_1)
pmt_counts_2 = self.ttl0.count(gate_end_2)
delay(long_time * ms)

Thanks!!

Yes, this is one reason why the count function is separate from gate_*.

    sb10q I have a follow up question regarding timestamp_mu(). My understanding from the docs is, if I were to replace all the count(...) calls with timestamp_mu(...), it would return the time of the FIRST event within that bin or -1 if no event occurred during that bin. Does Artiq have a method to return ALL event timestamps within a bin (opposed to just the first event)? If so, I would appreciate being pointed in the right direction.

    Yes, call timestamp_mu() in a loop until it returns -1.

      sb10q Thanks for the feedback! I'm a little confused as to how the argument of timestamp_mu(...) would work out. For example, if the ttl0 channel listens for gate_rising events for 300 microseconds and we'll assume there were 5 events during that 300 microseconds:

      with parallel:
          self.detection.sw.pulse(300 * us)
          gate_end = self.ttl0.gate_rising(300 * us)

      Below is my attempt at a looping timestamp_mu(), but I'm missing something because it would return the same event timestamp each iteration, right?

      i = 0
      timestamps[i] = self.ttl0.timestamp_mu(gate_end)
      while(timestamps[i] != -1):
          i += 1
          timestamps[i] = self.ttl0.timestamp_mu(gate_end)

      No, your timestamps array should contain the timestamps of all 5 different rising edges that occurred during the 300µs.