主题中讨论的其他器件: MSP430G2553
工具与软件:
您好、 我最终尝试以低频、7.8或14Hz 的频率驱动 PZT 芯片、但我无法让它播放任何频率的波形。 您能否检查我的代码以验证我是否正确地对标头和数据进行了编程? 此外、如果我希望待机位在发出"GO"位后始终变为1、
下面是我的代码和响应。
import smbus import time drv2667_adrrs = [0x59] # I2C write def i2c_write(slave_adress :int, reg_adress :int, data :int): i2c.write_byte_data(slave_adress, reg_adress, data) time.sleep(.01) check = i2c.read_byte_data(slave_adress, reg_adress) print("written to "+ str(slave_adress) +", register"+str(reg_adress)+ "=" + hex(check)) return # I2C read def i2c_read(slave_adress :int, reg_adress): data = i2c.read_byte_data(slave_adress, reg_adress) print("Device: "+ str(slave_adress) +", register"+str(reg_adress)+ "=" + str(data)) return def drv2667_setup(slave_adress): # Control i2c_write(slave_adress, 0x02, 0x00) # Exit STNBY mode #i2c_write(slave_adress, 0x01, 0x3D) # DRV2667, Analog Mode, Gain: Vpp=100V i2c_write(slave_adress, 0x01, 0x3B) # DRV2667, Digital Mode, Gain: Vpp=100V #i2c_write(slave_adress, 0x02, 0x02) # EN_OVERRIDE=1 i2c_write(slave_adress, 0x03, 0x01) # Waveform ID# 0x01 to start waveform i2c_write(slave_adress, 0x04, 0x00) # Terminate Waveform by clearing this register 0x03 print("DRV2667 @" + str(slave_adress) + "is ready on Digital Amplifier Mode, Vout=50V when Vdd=3.6V") return def drv2667_waveform(slave_adress): #Following the Example in 8.3.2.1 Single Click Alert Example (Modified) #Set to memory page 1 i2c_write(slave_adress, 0xFF, 0x01) #Header i2c_write(slave_adress, 0x00, 0x05) #Header Size i2c_write(slave_adress, 0x01, 0x80) #Start address upper Byte, Mode 3 i2c_write(slave_adress, 0x02, 0x06) #Start address lower byte i2c_write(slave_adress, 0x03, 0x00) #Stop address Upper Byte i2c_write(slave_adress, 0x04, 0x09) #Stop address lower byte i2c_write(slave_adress, 0x05, 0x01) #Repeat waveform count, once #Data i2c_write(slave_adress, 0x06, 0xFF) #Amplitude, Full scale i2c_write(slave_adress, 0x07, 0xFF) # Frequency i2c_write(slave_adress, 0x08, 0xFF) #Cycles i2c_write(slave_adress, 0x09, 0x00) # Envelope, no envelope #Set Page Register back to Control Space i2c_write(slave_adress, 0xFF, 0x00) print("DRV2667 @" + str(slave_adress) + "is ready to Trigger GO for waveform play") return if __name__ == "__main__": # I2C Setting i2c = smbus.SMBus(1) # DRV2667のAnalog Mode Setup for addr in drv2667_adrrs: drv2667_setup(addr) drv2667_waveform(addr) time.sleep(1) # Check STANDBY bit print("DRV2667 STATUS STANDBY") i2c_read(addr, 0x02) i2c_write(addr, 0x02, 0x01) # GO data2 = i2c.read_i2c_block_data(addr, 0x02, 1) print ("GO:" ,hex(data2[0]))
这是我从上述代码返回的响应。
written to 89, register2=0x0 written to 89, register1=0x3b written to 89, register3=0x1 written to 89, register4=0x0 DRV2667 @89is ready on Digital Amplifier Mode, Vout=50V when Vdd=3.6V written to 89, register255=0x1 written to 89, register0=0x5 written to 89, register1=0x80 written to 89, register2=0x6 written to 89, register3=0x0 written to 89, register4=0x9 written to 89, register5=0x1 written to 89, register6=0xff written to 89, register7=0xff written to 89, register8=0xff written to 89, register9=0x0 written to 89, register255=0x0 DRV2667 @89is ready to Trigger GO for waveform play DRV2667 STATUS STANDBY Device: 89, register2=0 written to 89, register2=0x40 GO: 0x40
在任何频率、振幅或周期下、DRV2667的输出端都没有响应。 我不确定我是否正确构建了波形接头和数据。
如有任何帮助、将不胜感激。
谢谢!
David