I am trying to model the complex action potential for calibrating research tools. The goal is to provide a signal with a frequency of 10 μV at 250 Hz. Low voltage will be considered later, the main problem for me is the frequency. The figure below shows an overview of the system I'm trying to make.

By collecting data from a live animal and processing the data in MATLAB, I made a low-noise signal with 789 values in 12-bit format. Then I cloned the repository where I saved this in csv format for Raspberry Pi using Git. Below is the Python script I wrote in RPi. You can skip the main section in the script to see the functionality.
import spidev
from time import sleep
import RPi.GPIO as GPIO
import csv
import sys
import math
DEBUG = False
spi_max_speed = 20 * 1000000
V_Ref = 5000
Resolution = 2**12
CE = 0
spi = spidev.SpiDev()
spi.open(0,CE)
spi.max_speed_hz = spi_max_speed
LDAQ = 22
GPIO.setmode(GPIO.BOARD)
GPIO.setup(LDAQ, GPIO.OUT)
GPIO.output(LDAQ,GPIO.LOW)
def setOutput(val):
lowByte = val & 0b11111111
highByte = ((val >> 8) & 0xff) | 0b0 << 7 | 0b0 << 6 | 0b1 << 5 | 0b1 << 4
if DEBUG :
print("Highbyte = {0:8b}".format(highByte))
print("Lowbyte = {0:8b}".format(lowByte))
spi.xfer2([highByte, lowByte])
def main():
with open('signal12bit.csv') as signal:
signal_length = float(raw_input("Please input signal length in ms: "))
delay = float(raw_input("Please input delay after signal in ms: "))
amplitude = float(raw_input("Please input signal amplitude in mV: "))
print "Starting Simulant with signal length %.1f ms, delay %.1f ms and amplitude %.1f mV." % (signal_length, delay, amplitude)
if not DEBUG : print "Press ctrl+c to close."
sleep (1)
read = csv.reader(signal, delimiter=' ', quotechar='|')
try:
while(True):
signal.seek(0)
for row in read:
if DEBUG : print ', '.join(row)
setOutput(int(row)/int((V_Ref/amplitude)))
sleep (signal_length/(data_points*1000)
sleep (delay/1000)
except (KeyboardInterrupt, Exception) as e:
print(e)
print "Closing SPI channel"
setOutput(0)
GPIO.cleanup()
spi.close()
if __name__ == '__main__':
main()
script . MCP4921 , , .
, , . , , 79 . 789000 , , , , Python Pi, csv . , csv, 6 .
:
250 ? , 789 script, SPI , 250 . csv, . csv.read . !