Skip to content
Snippets Groups Projects
Commit 83783953 authored by Mr. SQUID's avatar Mr. SQUID
Browse files

added some exception testing to catch errors with the arduino and fail a bit...

added some exception testing to catch errors with the arduino and fail a bit more gracefully, and same for get_IV
parent 88b655e1
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
......@@ -17,6 +17,8 @@ jupyter:
# Load libraries + setup functions
<!-- #endregion -->
Run the following hidden cell at the start of each session to make sure you have a connection to the Red Pitaya:
```python hide_input=true
import warnings
warnings.filterwarnings('ignore')
......@@ -79,7 +81,10 @@ def auto_scale(r, d):
r.end = d_max + d_range*0.1
def get_IV_t(decimation = 1024):
s.decimation = decimation
try:
s.decimation = decimation
except:
print("Error connecting to red pitaya, please rerun hidden cell at top of the notebook.")
s._start_acquisition()
time.sleep(s.duration)
I,V = s._get_curve()
......@@ -101,7 +106,7 @@ Please update the practicum round
```python hide_input=false
academic_year = "2020_2021"
practicum_round = 0
practicum_round = 6
```
Run this code to create the folder where your data will be saved and make a subfolder with a copy of the latest analysis scripts.
......@@ -128,7 +133,7 @@ for file in "autoplot.py", "Plot all my data.ipynb":
# IV vs Time Live Display
<!-- #endregion -->
```python hide_input=false
```python hide_input=true
I = []
V = []
t = []
......@@ -219,7 +224,7 @@ print("Live view done")
# IV Live Display
```python hide_input=false
```python hide_input=true
I = []
V = []
t = []
......@@ -245,7 +250,7 @@ def update_display():
if scale_mode.value == "Autoscale":
if plot_ref_button.value:
auto_scale(p1.x_range,np.concatenate(I,np.array(source3.data['x'])))
auto_scale(p1.y_range,np.concatenate(V,np.array(source3.data['y']))
auto_scale(p1.y_range,np.concatenate(V,np.array(source3.data['y'])))
else:
auto_scale(p1.x_range,I)
auto_scale(p1.y_range,V)
......@@ -400,17 +405,24 @@ def get_temperature(serial_port, baudrate, timeout):
ser.write(b'g')
#Serial read + Temperature calculations:
Vout = float(str(ser.readline().decode("utf-8")))*(Vin/1023.0) #calculates the voltage from the voltage divider (over the PT1000)
serial_reply = ser.readline()
try:
Vout = float(str(serial_reply.decode("utf-8")))*(Vin/1023.0) #calculates the voltage from the voltage divider (over the PT1000)
except:
return serial_reply
Rpt = (Vout*R1)/(Vin-Vout) #calculates the resistance of the PT1000
Temp_C = ((Rpt/R0)-1)/alpha #with the above calculated resistance and 'known' variable we calculate the temperature in Celsius
Temp_K = Temp_C + 273.15 #Temperature in Kelvin
return Temp_K
def take_measurement():
global timer_t0
timer_t0 = time.time()
T_meas = get_temperature('COM7',9600,1)
if not isinstance(T_meas,float):
print("Error reading temperature, serial reply: ", T_meas)
return
T.append(get_temperature('COM7',9600,1))
I,V,_ = get_IV_t()
R.append(np.polyfit(I,V,1)[0])
......@@ -527,7 +539,7 @@ print("Live view stopped")
# Power Spectral Density Live Display
<!-- #endregion -->
```python hide_input=false
```python hide_input=true
# The traces we download
I = []
V = []
......@@ -578,7 +590,7 @@ def update_display():
V_psd = V_psd_trace
elif n_filled < nmax:
I_psd = (I_psd * n_filled + I_psd_trace) / (n_filled+1)
V_psd = V_psd * n_filled + V_psd_trace) / (n_filled+1)
V_psd = (V_psd * n_filled + V_psd_trace) / (n_filled+1)
else:
# this should work because of numpy array index wrapping
I_psd += I_psd_trace / nmax - I_psd_array[ind_next-nmax]/nmax
......
This diff is collapsed.
---
jupyter:
jupytext:
formats: ipynb,md
text_representation:
extension: .md
format_name: markdown
format_version: '1.2'
jupytext_version: 1.6.0
kernelspec:
display_name: Python 3
language: python
name: python3
---
Following:
https://github.com/gsteele13/gary-misc-notebooks/blob/master/Test%20ADALM1000.ipynb
```python
import pysmu
import numpy as np
import matplotlib.pyplot as plt
from time import time
import time
```
```python
session = pysmu.Session()
```
```python
dev = session.devices[0]
chA = dev.channels["A"]
```
```python
print(session.devices)
print(len(session.devices))
print(session.devices[0])
```
```python
# Put channel in "source current, measure voltage"
chA.mode = pysmu.Mode.SIMV
```
```python
# Set the current to 4 mA?
chA.constant(2e-3)
```
```python
# Get 10 samples
chA.get_samples(10)
```
```python
N = 1e4
t0 = time()
voltage = np.array(chA.get_samples(N))[:,0]
t1 = time()
print("%.1f seconds" % (t1-t0))
print("%e sec per point" % ((t1-t0)/N))
plt.plot(voltage)
plt.show()
```
Measured voltage for a 4 mA current is about 4.235 V for the PT1000 sensor in the room right now.
The resistance I measure with the DMM is 1078.
Does that make sense?
```python
print(4e-3*1078)
```
OK, a bit stranget it is a bit off. Which do I trust?
The PT1000 has a resistance of 1000 ohms at 0 degrees C, and a first order calibration extrapolates to zero resistance at zero temperature.
```python
T_in_K = 273/1000*1078
T_in_C = T_in_K - 273
print(T_in_K)
print(T_in_C)
```
That seems about right.
Let's check the ALM assuming 4 mA:
```python
print(4.24/4e-3*273/1000)
print(4.24/4e-3*273/1000-273)
```
Seems a bit cold? I wonder what the DAC steps are in the sourcing mode of the ALM1000?
Maybe we need to calibrate some offsets and gains.
Let's try an IV:
```python
I = np.linspace(0,4e-3,100)
V = []
N = 10
for i in I:
chA.constant(i)
#time.sleep(0.1)
print(".",end="")
chA.get_samples(20) # need to clear the buffer?
v = np.array(chA.get_samples(N))[:,0]
V.append(v)
```
```python
plt.plot(I,V)
```
Looks pretty linear. Maybe it's a gain calibration problem?
**In the meantime, had another dead kernel!!! This is going to be a problem...probably should go back to the arduino...**
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
......@@ -19,7 +19,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"metadata": {},
"outputs": [
{
......@@ -28,7 +28,7 @@
"'.\\\\SQUID measurement software.ipynb'"
]
},
"execution_count": 2,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment