2

I'm hoping to construct a feedback loop for a laser using an Chipkit UC32 and an analog-digitial converter ( the one of I have is an AD5780 evaluation board). I've been reading through Digilint's SPI library but I admit I am pretty lost.

( I believe this is on topic to Arduino because I am using an Arduino API. The micro-controller I use is basically an Arduino so I see no difference. )

I'd like to output something simple like a digital AC voltage to the DAC and have it convert it, but as I understand it from here, I am just using the digitalWritecommand which is basically binary. How do transfer something more complicated to have the DAC convert it?

Likewise, how do I get the DAC to do the reverse, ADC, where it reads in a voltage and sends the Arduino a digital signal through SPI pins?

Andrew Hardy
  • 131
  • 6
  • 1
    What does this have to do with Arduino? It seems to me that you have this UC32 which has a PIC32 microcontroller on it and you need to write a library for the AD5780 using the chip's SPI peripheral. – Maximilian Gerhardt Feb 13 '19 at 21:12
  • Also why would you write your own driver if Analog Devices has a reference driver at https://wiki.analog.com/resources/tools-software/uc-drivers/renesas/ad5780#driver_description where you only have to implement `SPI_Init`, `SPI_Write` and `SPI_Read` yourself using your board / platform's SPI lib? :) – Maximilian Gerhardt Feb 13 '19 at 21:20
  • 1
    @MaximilianGerhardt chipKIT uses the Arduino API. It's as Arduino as the esp8266 or teensy. – Majenko Feb 13 '19 at 22:15
  • @MaximilianGerhardt Have you tried to use the AD Driver before? I'm here becauseI tried that and it seems broken. It requests files that aren't included. They don't seem to be useful but even if you remove those #include commands, it references a lot of undefined functions. Perhaps its just the missing file but seems unusable. If you have any experience with this, I could open another thread and try to fix it. – Andrew Hardy Feb 21 '19 at 15:25
  • @AndrewHardy Sure, I'll download the lib and interface with the Arduino SPI class so that in theory you can drop-in the result straight away. I'll let you know if I encounter a problem. If the lib requires functions beyond that what they say, it's kind of a bad lib.. – Maximilian Gerhardt Feb 21 '19 at 18:36
  • @AndrewHardy Done. https://github.com/maxgerhardt/arduino-ad57xx-driver – Maximilian Gerhardt Feb 22 '19 at 23:11
  • So there's something you're compiling or doing differently that I don't understand. When I hit Verify for your code, I get errors https://imgur.com/BKsIk2K of undefined references to commands in the Drivers. This is different than errors if I just don't have the file, so I don't know what they mean. – Andrew Hardy Feb 24 '19 at 00:43
  • You must put the `ad57xx_generic_driver` folder https://github.com/maxgerhardt/arduino-ad57xx-driver/tree/master/lib folder in your Arduino's library folder for this to work. (This is originally a PlatformIO project btw) @AndrewHardy – Maximilian Gerhardt Feb 24 '19 at 10:26
  • No, that's not the problem. If it wasn't in the libraries folder, I would get an error at the #include line. I have had to remove those files from the "include" directory to have Arduino recognize it. https://imgur.com/a/QVxW0hi This is my file structure currently – Andrew Hardy Feb 28 '19 at 03:46
  • @AndrewHardy Then for some reason it's not compiling the cpp files. It finds the headers but doesn't compile in the implementation of it. Something is still wrong with the folder structure. Try to put all the sources and headers directly into one filder like shown in https://www.arduino.cc/en/hacking/libraries – Maximilian Gerhardt Feb 28 '19 at 20:12
  • @MaximilianGerhardt, https://imgur.com/a/WPskxYP I went away from this to work on some other things, but I'm back now. Hooking up the DAC, I get a sin function. It doesn't seem to be responsive to the numbers I change in the example code you gave. How would I go about debugging these sorts of things? I take this image is not what I am supposed to see. – Andrew Hardy Mar 22 '19 at 14:19

1 Answers1

3

I'd like to output something simple like a digital AC voltage to the DAC and have it convert it, but as I understand it from here, I am just using the digitalWritecommand which is basically binary. How do transfer something more complicated to have the DAC convert it?

SPI is a communication protocol. It uses digital signals, coupled with time, to transfer information.

To use DSPI you need to first define an SPI object

DSPI0 SPI;

From then on it's the same as using the Arduino SPI library.

Start it

SPI.begin();

Then transfer the correct commands (found in the DAC datasheet) to set the voltage of the output

digitalWrite(10, LOW);
SPI.transfer(0x43);
SPI.transfer(0x1A);
digitalWrite(10, HIGH);

The values there are just examples. The 10 is the chip select pin for the DAC, and the values used in the transfers (however many are needed) need to be found in the datasheet.

If you only want to use the pins associated with DSPI0 you can use the SPI library instead (which only supports one SPI channel - the uC32 has two), in which case it is identical to working with the Arduino SPI library.

Likewise, how do I get the DAC to do the reverse, ADC, where it reads in a voltage and sends the Arduino a digital signal through SPI pins?

You don't. DACs are DACs and ADCs are ADCs. They aren't interchangeable.

For ADC functionality just use any of pins A0 through A11 and the analogRead() function.

Majenko
  • 103,876
  • 5
  • 75
  • 133
  • thanks for responding! You've helped me before so I appreciate the patience. I've been reading for a while, so can I run some things by you? I didn't find anything in the Data Sheet, but what bytes I write are just getting bit_number = (Pos REF V - Neg REF V ) / 2^(18) and convert to bytes? There doesn't seem to be a command for the actual conversion either? From what I've read when I send bytes it automatically converts to an analog voltage and outputs it? – Andrew Hardy Feb 21 '19 at 16:02
  • Secondly, do you think it is worth trying to get the AD Drivers running? The missing file is ior5f100le.h . Is this a standard Arduino library I'm missing? The driver has commands for reading data from the register too, which I don't quite understand the point of. – Andrew Hardy Feb 21 '19 at 16:04
  • That DAC uses a 3-byte (24 bit) control protocol. Page 21 onwards in the datasheet describe the commands. You need to first send the correct commands to turn the DAC on (using the "Control Register"). Once on you send a value to a specific register (not a real register, so it's not listed with the registers), and toggle LDAC (either the pin or the register bit) to output that value. I have never heard of `ior5f100le.h`. Probably something to do with a specific development board. – Majenko Feb 21 '19 at 16:12