In [1]:
from pynq.overlays.base import BaseOverlay
overlay = BaseOverlay('base.bit')
trace_analyzer = overlay.trace_pmoda
The I2C controller on PMODA interface runs at 100KHz, it is recommended to oversample the transactions (capturing more than 2 samples per logic level). Hence here we set the sampling frequency to 400KHz.
It takes little time to capture the samples, therefore we set the number of analyzer samples to the maximum (64K samples).
In [2]:
trace_analyzer.setup(frequency_mhz=0.4, num_analyzer_samples=65535)
In [3]:
from pynq.lib.pmod import Pmod_TMP2
sensor = Pmod_TMP2(overlay.PMODA)
In [4]:
trace_analyzer.run()
reading = sensor.read()
trace_analyzer.stop()
print('Temperature is {} degree C.'.format(reading))
After the trace analyzer has been stopped, we can call analyze()
method to prepare all the captured samples into lanes of data. We can ignore the returned values for now because we want to see the sigrok decoded transactions as well.
In [5]:
_ = trace_analyzer.analyze()
The next following cells utilize the sigrok decoders. The decoders are slightly modified, so decoded transactions can be aligned with the captured samples.
The next cell set protocol and the signal probes.
Fore more information, please read https://sigrok.org/wiki/Sigrok-cli
In [6]:
trace_analyzer.set_protocol(protocol='i2c',
probes={'SCL': 'D2', 'SDA': 'D3'})
Sigrok can also show the information about a specified protocol.
In [7]:
trace_analyzer.show_protocol()
After protocol and probes have been set, we can call the decode()
method. The path to the saved samples, the starting and ending sample numbers, and the path to the decoded file have to be specified.
Note: It is recommended not to set too large number for samples to decode. A very large number of decoded samples may lead to very slow rendering of the waveform display, possibly hanging the system.
In this example, we only decode 1000 samples. In general, it is okay to decode less than 4000 samples at a time. Users can decode more than 4000 samples, but displaying the waveforms will become very slow.
If users want to check various parts of the entire trace of samples, users can set the starting and ending positions repeatedly and rerun this cell.
In [8]:
start_position, stop_position = 1, 1000
waveform_lanes = trace_analyzer.decode('pmod_i2c_trace.csv',
start_position, stop_position,
'pmod_i2c_trace.pd')
Let's polish the waveform for better display. We will add footer and header to the waveform dictionary.
For more information: http://wavedrom.com/tutorial.html
In [9]:
waveform_dict = {'signal': waveform_lanes,
'foot': {'tock': start_position},
'head': {'text': ['tspan', {'class': 'info h3'},
'Pmod I2C Transactions']}}
The next cell will display the waveform. Users can use scrollbar to check the I2C transactions. The Pmod TMP2 sensor has the I2C base address 0x4B.
The next cell will take a few seconds to render the waveform.
In [10]:
from pynq.lib.logictools.waveform import draw_wavedrom
draw_wavedrom(waveform_dict)
In [11]:
from pprint import pprint
pprint(trace_analyzer.get_transactions())
In [12]:
trace_analyzer.reset()