Using PPS to trigger received data storage in Python

Dear all,

I used USRP N200 with LFRX +UHD to design a receiver, which works well
to continuously receive data. I am trying to control the received data
streaming using PPS to trigger received data storing, which is storing
the received data into a data file for 1ms after receiver detecting the
edge of the PPS signal every second.

I tried the approach introduced in gnuradio apps, rx_timed_samples,
detecting the PPS signal, then setup streaming, then filled meta-data by
recv(). Eventually, I got to know stream_cmd and recv() are not swigged
in gnuradio, which means it cannot be implemented in Python.

I got to know the USRP source already tags the samples with a timestamp
and I do not need to control when streaming begins, because the
downstream block determine the time of any sample using “metadata”.

  1. I am wondering how to fill meta-data in Python if device.recv() is
    not swigged? I need to use the PPS signal to trigger the received data
    storage for 1ms every second after detecting the edge of PPS signal
    every second.
    I am using the follow setting method to detect the PPS signal:

self.clk_cfg = uhd.clock_config()
self.clk_cfg.pps_source = uhd.clock_config.PPS_SMA
self.clk_cfg.pps_polarity = uhd.clock_config.PPS_NEG
self._usrp2.set_clock_config(self.clk_cfg, uhd.ALL_MBOARDS)
self._usrp2.set_time_unknown_pps(uhd.time_spec(0.0))

  1. This PPS setting is done just after the usrp device is created. The
    PPS signal could be detected while usrp device is setup. I am also
    wondering if this approach could make usrp detect PPS signal every
    second or only once when the usrp device is setup?

Any suggestion will be really appreciated!! I am dying to know how this
scheduling issue could work in Python.

Thanks,
Yan

When you say PPS, do you mean “pulse per second” or are you trying to
use the PPS input as a generic triggering system? If the second case,
you can do this, but my advice will be different.

  1. I am wondering how to fill meta-data in Python if device.recv() is
    not swigged? I need to use the PPS signal to trigger the received
    data storage for 1ms every second after detecting the edge of PPS

It seems like you do not need the PPS to trigger anything. Your
downstream block can use the timestamp tag and sample count to determine
which samples should be stored.

signal every second. I am using the follow setting method to detect
the PPS signal:

self.clk_cfg = uhd.clock_config() self.clk_cfg.pps_source =
uhd.clock_config.PPS_SMA self.clk_cfg.pps_polarity =
uhd.clock_config.PPS_NEG self._usrp2.set_clock_config(self.clk_cfg,
uhd.ALL_MBOARDS)
self._usrp2.set_time_unknown_pps(uhd.time_spec(0.0))

That will work

  1. This PPS setting is done just after the usrp device is created.
    The PPS signal could be detected while usrp device is setup. I am
    also wondering if this approach could make usrp detect PPS signal
    every second or only once when the usrp device is setup?

You need to understand that the PPS is only used to trigger the latching
of the time registers. Once you set the time registers, thats it, your
are done. You know what time the next pps will occur because it is one
second plus the time you set.

-Josh

I really appreciate your reply, Josh.

I am using a GPS as the input for PPS of my receiver based on USRP N200
in order to synchronize with a transmitter which uses GPS pulse to
synchronize with other devices. This transmitter detects the NEG edge of
GPS pulse, then 2ms later, starts to transmit signal for 1ms,then it
suspends for the remainder of this second. When next GPS pulse coming at
the beginning of next second, this transmitter repeats the transmission
process again for every second.

Therefore, this PPS signal is used as a synchronization signal in my
receiver to synchronously receive the signal sent by this transmitter
needed to collaborate with. The PPS signal need to trigger the signal
reception every second, as the precision of the clock of USRP and GPS
cannot be exactly the same. If only use PPS to trigger the latching of
the time registers the first second of signal reception, eventually, the
receiver and transmitter cannot be precisely synchronized.

To sychronize the receiver with this transmitter, I need use the PPS
triger the signal reception every second. I am so interested in your
uhd_work branch the set_start_time feature of gr_uhd_usrp_source block
would be a good solution for triggering data reception. I have some
further questions on set_sart_time:

  1. The version of my UHD does not include this feature into
    gr_uhd_usrp_source block, how can I add it into UHD after compiling the
    modified source code?

  2. As for the PPS triggering problem,how can I implement PPS triggering
    the latching of the time registers with different timestamps?

Thank you so much for your help, Josh! Your reply did help me to find
the solution to my current problems.

Have a great weekend!

with thanks,
Yan

On 11/25/2011 05:51 PM, Yan N. wrote:

Therefore, this PPS signal is used as a synchronization signal in my
receiver to synchronously receive the signal sent by this transmitter
needed to collaborate with. The PPS signal need to trigger the signal
reception every second, as the precision of the clock of USRP and GPS
cannot be exactly the same. If only use PPS to trigger the latching
of the time registers the first second of signal reception,
eventually, the receiver and transmitter cannot be precisely
synchronized.

Ah, so you are not sharing a reference, therefore PPS is not “pulse per
second”, its “pulse per approximately a second” because of clock drift,
in other words, just a generic event trigger.

Well, there isnt a way to cause streaming to start on a pulse unless you
perform some FPGA mods, but I will tell you one creative way to solve
this:

Continually read get_time_last_pps(). Every time this function returns a
different value, you know the exact time (relative to USRP) that a pulse
event occurred.

So you know:

  1. the exact time for every sample thanks to stream tags
  2. the exact time of every pulse thanks to get_time_last_pps

Now you just have make some code that combines both pieces of
information to store the samples.

-Josh

Thank you so much for your suggestions, Josh.

Your suggestion on solving the problem I met is absolutely creative.
Thank you so much!

I have more further detailed questions related:
get_time_last_pps gives a timespec representing the last pps, while how
can I obtain the stream tags from the my down stream block? Can I get
the stream tags in Python, as from a post on my gnuradio discuss list,
stream tags functionality had not pulled into mainline gr-uhd yet until
this Sep.?

Then combine these two timespec together to control which samples would
be stored. I am using the file_sink block to create a data file and
store the data in. If using these timespec information to store the
samples, I think it needs to correspond the certain stream tags when pps
pulse occurs (timespec given by get_time_last_pps) to the exact sample
stored in the data file created by file_sink. Therefore, I am wondering
how this stream tags correspond to data samples in the data file, as the
data file only stores data samples from my understanding?