0

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.

AD5293 truth table

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

enter image description here

Thanks in advance, Dean

Dean
  • 63
  • 5
  • BTW, don't write [`using namespace std;`](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice). You don't even need to. Even though you include iostream and cmath, you're not using anything from them. – Friedrich Jun 21 '23 at 14:46
  • 1
    yes fair comment, its just cause this was cut from a larger program and trimmed to just have the spi just forgot to remove it. Thanks – Dean Jun 21 '23 at 14:52
  • The `SYNC` signal on the AD5293 is active low. If this is controlled by the `CS_HV` pin then you are driving it high when you should be driving it low (and vice-versa). – pmacfarlane Jun 21 '23 at 16:19
  • "C3-C0 respectively are 0,0,1,1" DISCLAIMER: I haven't touched that device before. From the manual I would assume that the C1/C2 in Table 13 are not the same as in Table 11 but they refer to Table 12. That means you nead C3-C0 hold 0,1,1,0 and these C2,C1 values in the Control register go into D2,D1 to write "allows update of wiper position through digital interface" into control register. Then you need C3-C0 to hold 0,0,0,1 to write into RDAC. – Gerhardh Jun 21 '23 at 16:25
  • @pmacfarlane but isnt SPI suppose to be nominally high and then brought low to send the tx data and then you bring it back high to be in the nominal state. – Dean Jun 21 '23 at 19:50
  • @Dean If you're talking about the "chip select" signal, then yes. What does this line of code do? `gpio_put(CS_HV, true);` I'm assuming it drives the signal high, but maybe I'm wrong? (Never used the Pi-Pico before.) – pmacfarlane Jun 21 '23 at 19:58
  • Not related to the problem, how did you connect the AD chip to the Pico? Did you get a ready-made board with headers to connect or did you wire a plain chip to the pins of the Pico? I didn't find a board with that chip. – Gerhardh Jun 22 '23 at 06:39
  • @Gerhardh Hi it is soldered onto a custom PCB that I designed with KiCAD – Dean Jun 22 '23 at 10:04
  • @pmacfarlane yes your correct that line just sets the pin to high, I did realise after looking at the scope that the CS line wasnt low for full duration of the transfer, so I added a small delay after gpio_put(CS_HV, false) to fix that – Dean Jun 22 '23 at 10:06
  • Did you consider my comment that you might send wrong data? – Gerhardh Jun 23 '23 at 06:21
  • @Gerhardh yes I did but I dont think your assumption is correct as this digital potentiometer has a 1024 steps and thus the 10 bits to program the wiper position is 1024. otherwise you would have 8 bits of data you send to program 1024 different positions – Dean Jun 23 '23 at 06:58
  • That is what D9-D0 are for. Not C3-C0. You only send 1 command. I think you need to write to control register first and then set the requested value. – Gerhardh Jun 23 '23 at 07:06
  • BTW: Where in my comments did you find anything about using only 8 bits for the value? – Gerhardh Jun 23 '23 at 07:12
  • I interpreted what you said as when you say these C2, C1 Values in the control register go to D2 and D1, made me think think that those control bits are then taking up data bit positions, and thus reducing the number of usable data bits from 10 to 8. But it seems I haven't understood what you meant – Dean Jun 23 '23 at 08:51
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/254216/discussion-between-gerhardh-and-dean). – Gerhardh Jun 23 '23 at 12:41

1 Answers1

0

so I figured this out, in the end there was two things, I had 15V on one side of the EXT_CAP pin capacitor, which killed the chip after changing this so EXT_CAP goes to ground and a new chip it was fine.

Also you have to send the hex value 0x1802 to enable the digital interface and then send your data with the control bits for C3-C0 as 0,0,0,1 respectively

Hope this helps someone in future.

Dean
  • 63
  • 5