Post Go back to editing

Problems with ad 5372 ebz evaluation board control program.

Category: Software
Product Number: AD-5372EBZ

Hey guys. I;m trying to make a python program, in order to control the aformentioned board through SPI. The problem is that the board seems to ignore some of the command that i load. What i mean is that if i load function with two commands, it might execute one of none of them.I always set LDAC low when loading a command and reset low and then high during start up.


dev=0
bus=0

LDAC_pin = 17
BUSY_pin = 22
CLR_pin = 27
RESET_pin = 4

gpio.setwarnings(False)


def setup_gpio():

gpio.setmode(gpio.BCM)
gpio.setup(LDAC_pin, gpio.OUT)
gpio.setup(RESET_pin, gpio.OUT)
gpio.setup(CLR_pin, gpio.OUT)
gpio.setup(BUSY_pin, gpio.IN)

reset()
clear()


def reset():
gpio.output(RESET_pin, 0)
time.sleep(0.001)
gpio.output(RESET_pin, 1)


def clear(enable=None):

if enable is None:
if clear_state is True:
enable = False
else:
enable = True
if enable is True:
gpio.output(CLR_pin, 0)
clear_state = True
else:
gpio.output(CLR_pin, 1)
clear_state = False


def loadDAC(keep=False):

gpio.output(LDAC_pin, 0)
if keep is False:
time.sleep(0.001)
gpio.output(LDAC_pin, 1)


def cleanUp():

spi.close()
gpio.cleanup()



def dacCommandTest(bus,dev,command,dacGroup,dacChannel):

Vref = 3
offsetCode = 0
M = 65535
C= 32768
Vout= 6

Vmax=4*Vref*(65535-4*offsetCode)/(2^16) # Vout should be in this range, given Vref
Vmin=4*Vref*(-4*offsetCode)/(2^16) # Vout should be in this range, given Vref


byte1=command|dacGroup|dacChannel
dacCode=math.ceil(Vout*(2**16)/(4*Vref)+4*offsetCode)
inputCode=math.floor((dacCode-C+(2**15))*(2**16)/(M+1))

d = struct.pack('<H', inputCode)
data= [0, 0, 0 ]
data = [byte1, d[1], d[0]]

if connected ==1 :
spi.open(bus,dev)
spi.mode = 0b01

spi.xfer3(data)
loadDAC()
spi.close()

print('>> CHANNEL '+str(dacChannel)+' in group '+str(int(dacGroup)/8-1)+', is set to : '+ str(Vout)+' Volts ')


def setupOffset(bus,dev,offsetRegister):
byte1=offsetRegister
offsetCode=0
dataZero=0
d = struct.pack('<H', offsetCode)
data = [byte1, d[1], d[0]]
if connected ==1 :
spi.open(bus,dev)
spi.mode = 0b01

spi.xfer3(data)
loadDAC()
spi.close()

def offsetConfigure():

setupOffset(bus, dev, reg_Offset0)
time.sleep(0.001)
setupOffset(bus, dev, reg_Offset1)
time.sleep(0.001)


if __name__ == '__main__':


spi=spidev.SpiDev()

setup_gpio()
time.sleep(0.001)

offsetConfigure()
time.sleep(0.001)

dacCommandTest(bus,dev,reg_X,all_group,all_ch)
time.sleep(0.001)
dacCommandTest(bus,dev,reg_X,group_0,ch_0)

cleanUp()