Beispiel #1
0
"""
test.py - Simple demonstration of sampling rate using the PRU library for the ADC

Takes 10k samples at 10kHz, returned in a numpy array, and displays the time taken. Repeats 10 times
"""

import time as time
import numpy as np
import ADC_PRU as ADC

N = 10
num_vals = 10000

ADC.set_clk(160)  # Optional, 160 is default (10kHz), 16=100 kHz

np_vals = np.empty(num_vals, dtype=np.intc)
for i in range(0, N):
    t1 = time.time()
    ADC.read(np_vals)
    t2 = time.time()
    print(t2 - t1)
Beispiel #2
0
import ADC_PRU as ADC
import numpy as np
import matplotlib.pyplot as plt

clk='10k'

#Set clock properly and set up array for 1s of data
nsamples=0
if clk=='10k':
    ADC.set_clk(160) #Optional, default
    nsamples=10000
elif clk=='100k':
    ADC.set_clk(16)
    nsamples=100000
else:
    print 'Unknown frequency'
    exit()
vals = np.empty(nsamples,np.intc)

raw_input("Press Enter:")
ADC.read(vals)

#Plot and save
fig=plt.figure()
t=np.arange(0,1,1.0/nsamples)
plt.plot(t,vals*1.8/4095)
plt.ylabel('Voltage (V)')
plt.xlabel('Time (s)')
plt.title(clk)
fig.savefig("out.png")