-
Notifications
You must be signed in to change notification settings - Fork 1
/
accu_2.py
59 lines (42 loc) · 1.27 KB
/
accu_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from Adafruit_BBIO.SPI import SPI
import struct
import time
spi = SPI(0,0)
spi.mode = 1
spi.msh = 300000
spi.xfer([0b00011000, 0x02])
def decode_sent_command(ser_cmd):
cmd_bits = (ser_cmd & (((1<<6) - 1)<<10))>>10
data_bits = ser_cmd & ((1<<10)-1)
return bin(cmd_bits)[2:], data_bits
def send_cmd(cmd,data):
ser_cmd = (cmd << 10) | (data & ((1<<10)-1))
w0 = ser_cmd >> 8
w1 = ser_cmd & ((1<<8)-1)
return [w0, w1]
# write to RDAC
spi.xfer(list(struct.unpack('BB', struct.pack('>H', 1 << 10 | 0))))
# read RDAC
spi.xfer(list(struct.unpack('BB', struct.pack('>H', 0b10 << 10 | 0))))
# read Control register
spi.xfer(list(struct.unpack('BB', struct.pack('>H', 0b111 << 10 | 0))))
spi.readbytes(2)
for i in range(1024):
spi.xfer(list(struct.unpack('BB', struct.pack('>H', 1 << 10 | i))))
time.sleep(.2)
spi.writebytes([0x0,0x0])
spi.writebytes([0x18,0x02])
spi.writebytes([0x05,0x00])
spi.writebytes([0x08,0x0])
spi.writebytes([0x0,0x0])
spi.writebytes([0x0,0x0])
spi.writebytes([0x0,0x0])
spi.xfer([0x0,0x0])
spi.xfer([0x18,0x02])
spi.xfer([0x05,0x00])
spi.xfer([0x08,0x0])
spi.xfer([0x0,0x0])
class voltage_divider:
def __init__(self):
self.R1 = 1e20
self.R2 = 1e20