#!/usr/bin/env python
# -*- coding: utf-8 -*-

import initExample
import os
import time
import numpy as np
import matplotlib.pyplot as plt
import csv
import time
from scipy import signal
from lase.core import KClient, ZynqSSH
from lase.drivers import Oscillo

# Load the oscillo instrument
host = os.getenv('HOST','192.168.1.100')
password = os.getenv('PASSWORD','changeme')
ssh = ZynqSSH(host, password)
ssh.unzip_app()
ssh.install_instrument('oscillo')

# Connect to the board
client = KClient(host)
driver = Oscillo(client)

current = 30 #mA

freq = 1
mod_amp = 0.2
# Modulate with a triangle waveform of period 8192 x 8 ns
driver.dac[1,:] = mod_amp * signal.sawtooth(2 * np.pi * freq / driver.n * np.arange(driver.n), width=0.5)
driver.set_dac()

driver.start_laser()
driver.set_averaging(True)
driver.set_laser_current(current)
time.sleep(0.1)

plt.ylim([-2*np.pi, 2*np.pi])
plt.ion()
plt.show()

phase_previous_pos = 0
phase_previous_meg = 0

temperature = 20 # degrees Celsius
data = np.zeros((1000,2)) + temperature
# Hanning FFT Window
window = 0.5 * (1-np.cos(2 * np.pi * np.arange(4095) / 4095))

f = open('temperature.csv','a')

for i in range(50000000):
    driver.get_adc()
    
    # Separate positive and negative slopes in the triangle waveform
    adc_pos = driver.adc[0,0:4095]
    adc_neg = driver.adc[0,4096:8191]

    fft_pos = np.fft.fft(adc_pos * window)
    fft_pos = np.fft.fft(adc_neg * window)

    phase_pos = np.angle(fft_pos)
    phase_neg = np.angle(fft_neg)
    
    # The phase of the frequency modulation 
    phase_neg = phase_adc1[6]
    phase_neg = phase_adc2[6]
    
    plt.clf()

    diff_pos = -(phase_pos - phase_previous_neg + np.pi)%(2*np.pi)-np.pi
    diff_neg = +(phase_neg - phase_previous_neg + np.pi)%(2*np.pi)-np.pi
  
    diff = diff_pos + diff_neg/2

    data = np.roll(data, -1, axis=0)
    temperature = temperature + 0.015 * diff / (2*np.pi)
    data[-1] = temp
    string = str(time.time())+','+str(temperature)+'\n'
    f.write(string)
    print(string)
    phase_previous_pos = phase_pos
    phase_previous_neg = phase_neg
f.close()

driver.stop_laser()
driver.close()
plt.show()

@@ -933,17 +933,17 @@
 revious_
-m
+n
 eg = 0%0A%0A

Update temperature.py