【Follow me第二季第1期】补充:AD5270数字电位器的驱动应用
[复制链接]
AD5270是1024位、变阻器模式下的温度系数5 ppm/°C、1%电阻容差误差、SPI接口和50-TP存储器数字变阻器,性能十分优秀。
它集业界领先的可变电阻性能与非易失性存储器(NVM)于一体,并提供50次可编程(50-TP)存储器。将电阻值编程写入50-TP存储器之前,可进行无限次调整。这些器件不需要任何外部电压源来帮助熔断熔丝,并提供50次永久编程的机会。在50-TP激活期间,一个永久熔断熔丝指令会将游标位置固定。SPI接口控制时序如下:
使用开发板的SPI接口(任意IO软件模拟SPI)可以完成驱动控制,测试代码如下:
// AD5270 commands - new digital potentiometer
#define CMD_WR_RDAC 0x01
#define CMD_RD_RDAC 0x02
#define CMD_ST_RDAC 0x03
#define CMD_RST 0x04
#define CMD_RD_MEM 0x05
#define CMD_RD_ADDR 0x06
#define CMD_WR_CTRL 0x07
#define CMD_RD_CTRL 0x08
#define CMD_SHTDN 0x09
void vspi_write_word(const int chip_select, uint16_t data_to_send, const uint8_t bit_order, const uint8_t mode) {
vspi->beginTransaction(SPISettings(SPI_FREQ_FAST, bit_order, mode));
digitalWrite(chip_select, LOW); //pull SS slow to prep other end for transfer
vspi->transfer16(data_to_send);
digitalWrite(chip_select, HIGH); //pull ss high to signify end of data transfer
vspi->endTransaction();
}
/* Write a 4-bit command and a 10-bit data word */
void AD5270_Write(const int chip_select, uint8_t cmd, uint16_t data){
uint16_t data_word = ((cmd & 0x0F) << 10) | (data & 0x03FF);
vspi_write_word(chip_select, data_word, MSBFIRST, SPI_MODE1);
}
/* Enable/disable rheostat value changes */
void AD5270_LockUnlock(const int chip_select, uint8_t lock){
AD5270_Write(chip_select, CMD_WR_CTRL, lock ? 0 : 0x002);
}
/* Enable/disable hardware shutdown */
void AD5270_Shutdown(const int chip_select, uint8_t shutdown){
AD5270_Write(chip_select, CMD_SHTDN, shutdown ? 1 : 0);
}
/* Set the value of the digital rheostat - range is 0-0x3FF (0-100kOhm) */
void AD5270_Set(const int chip_select, uint16_t val)
{
AD5270_Write(chip_select, CMD_WR_RDAC, val);
}
#define CHIP_SEL_MEAS 10 // Chip select pin for measuring digital rheostat potentiometer
void setup() {
// put your setup code here, to run once:
// Set voltage measurement gain to 1 (maximum current (5V pk-pk) must be within ADC range)
AD5270_Shutdown(CHIP_SEL_MEAS, 1);
AD5270_Set(CHIP_SEL_MEAS, 100);
}
void loop() {
// put your main code here, to run repeatedly:
}
测试接线和效果:
|