This demonstration shows how to use the PmodTC1. You will also see how to plot a graph using matplotlib.
The PmodTC1 is required.
The thermocouple sensor is initialized and set to log a reading every 1 second. The temperature of the sensor can be changed by touching it with warm fingers or by blowing on it.
In [1]:
from pynq.overlays.base import BaseOverlay
base = BaseOverlay("base.bit")
In [2]:
from pynq.lib import Pmod_TC1
# TC1 sensor is on PMODB
my_tc1 = Pmod_TC1(base.PMODB)
print('Raw Register Value: %08x hex' % my_tc1.read_raw())
print('Ref Junction Temp: %.4f' % my_tc1.read_junction_temperature())
print('Thermocouple Temp: %.2f' % my_tc1.read_thermocouple_temperature())
print('Alarm flags: %08x hex' % my_tc1.read_alarm_flags())
In [3]:
my_tc1.start_log()
In [4]:
my_tc1.stop_log()
log = my_tc1.get_log()
In [23]:
%matplotlib inline
import matplotlib.pyplot as plt
from pynq.lib.pmod.pmod_tc1 import reg_to_tc
from pynq.lib.pmod.pmod_tc1 import reg_to_ref
tc = [reg_to_tc(v) for v in log]
ref = [reg_to_ref(v) for v in log]
plt.plot(range(len(tc)), tc, 'ro', label='Thermocouple')
plt.plot(range(len(ref)), ref, 'bo', label='Ref Junction')
plt.title('TC1 Sensor log')
plt.axis([0, len(log), min(tc+ref)*0.9, max(tc+ref)*1.1])
plt.legend()
plt.xlabel('Sample Number')
plt.ylabel('Temperature (C)')
plt.grid()
plt.show()
In [ ]: