【得捷电子Follow me第2期】自定义任务:esp32控制放大器
[复制链接]
在第二期的活动中为了凑单买了XIAO ESP32C3,支持arduino开发,十分方便,尺寸也十分的mini,板子带了锂电池充电芯片,可玩性非常高。
通过SPI接口驱动AD5270这款数字电位器,来调整仪表放大器的增益,从而实现程控增益,测试代码如下:
// 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:
}
开发板支持wifi功能,可以实现分布式的数据采集,非常强大。
1fb89d7f5efda7662016581c76fffc9c
|