so I am trying to control a digital potentiometer to control a voltage output. What I did was look at the datasheet for the control register values and I store that as a value and then bitwise OR this with the value I want to send.
I pick the values I picked for C3-C0 respectively are 0,0,1,1 as I just want to write to the RDAC which is why C0 is a one and C1 is a 1 as this allows me to operate the digital interface (SPI). The issue is I dont get any output from the wiper when I send the values to it via SPI, so if there is anything with wrong with the code I would really appreciate the help, as if there is nothing wrong with it then I can ask somewhere else about the hardware.
Here is my test code where I just send a value of 512 bitwise OR'd with the control bit over spi to the ic.
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include "pico/stdlib.h"
#include "hardware/spi.h"
using namespace std;
//----------SPI Init----------
#define SPI_Port_Dig_Pot spi0
#define CS_HV 4
#define MOSI_HV 3
#define SCK 2
//----------------------------
void SPI_Setup(){
spi_init(SPI_Port_Dig_Pot, 5000000); //init spi port to run at 5MHz, chosen as doesnt need to run any faster
//and is 10x lower than the max the dig pot can support
//-------CS for all setup-------
gpio_init(CS_HV);
gpio_set_dir(CS_HV, GPIO_OUT);
gpio_put(CS_HV, true);
//------------------------------
gpio_set_function(SCK, GPIO_FUNC_SPI);
gpio_set_function(MOSI_HV, GPIO_FUNC_SPI);
spi_set_format(SPI_Port_Dig_Pot, 16, SPI_CPOL_0, SPI_CPHA_1, SPI_MSB_FIRST); //may need to change length
}
int main(){
stdio_init_all();
SPI_Setup();
uint16_t control_bit = 0b0000110000000000; //ctrl bit value in binary
//See ad5293 datasheet for derivation
uint16_t SPI_Code_With_CTRL_Bit = (control_bit | 512);
uint16_t spi_buffer[1];
spi_buffer[0] = SPI_Code_With_CTRL_Bit;
while(1){
gpio_put(CS_HV, true);
spi_write16_blocking(SPI_Port_Dig_Pot, spi_buffer, 1);
gpio_put(CS_HV, false);
busy_wait_us(1);
}
}
Edit: Changed SPI instance to mode 1 (CPOL = 0, CPHA = 1) as stated in datasheet. And added a small delay after toggling CS_HV line.
After doing some more testing I have these waveforms from scope, which I cant personally see anything wrong with but hopefully someone could shed some light if I am doing something wrong. Here I am sending value 6146 (five 0's and rest 1's), but have tried a wide range of different control bits according to the data sheet but still see no change in wiper position.
In image Yellow = TX Data, Purple = CS, and Blue = Clock
Thanks in advance, Dean