ZYNQ: reading analog value from ADC LTC2314 with AXI Quad SPI

Chanon Khongprasongsiri
4 min readJun 27, 2020

Hi, guys. The topics we are going to talk to day is about the SPI serial communication with ZYNQ development environment. You will be familiar with SPI with Arduino board. So, it will be the same because SPI is the standard protocol, However, to do with ZYNQ, you need more works to get it. The development board that we use to day is PYNQ which compose of ZYNQ-7020 chip.

At first, I will introduce you a little bit about ZYNQ. The ZYNQ can be define as the microprocessor stay with the FPGA in one chip. It is different from any microprocessor (Arduino, Raspberry PI) because the ZYNQ have FPGA. It can be said that it is the hardware and software co-design. By the way, to program ZYNQ, you need to config 2 main steps. First, you need to develop the hardware platform using Vivado which is the software provide by Xilinx for FPGA programming. Then, when you get hardware platform, you will write C/C++ program to control it using Xilinx SDK or Vitis.

Before we go to the experiment, I want to tell you that, with this problem, there are many ways to tackle. For example, you can use the SPI with VHDL code to communication between ZYNQ and LTC2314. But, today, I want introduce you with the AXI Qaud SPI which is require C programming skill instead of HDL. It would be easier than learning the tough HDL code.

Now, I will show you the hardware block with Vivado. To do this, you just put the ZYNQ7 PS and AXI Quad SPI. Then, the rest of that will automatically done by your command.

After this, because this is the FPGA part, you need to specified the output and input pin for the spi_rtl bus with the xdc file. Because, this SPI is config just for 1 device, you need 4 pin which follow the standard SPI. The following is the xdc file for my PYNQ board. The xdc file will be different when you change the development board and when you want the input and output pin in different location.

There are some setting in the AXI Quad SPI. Here, the mode that I select is standard mode because we have only one device. The transaction width is how long the bit will be send or receive. We can choose 8 bit. If we want more that we can have multiple transaction. For example, in LTC2314 which is 14 bit. So, to get one sample of data, we need to have two transactions and use bit masking to get 14 bit. Moreover, the frequency ratio is the clock divider. It will divide the clock from the s_axi_aclk pin which can config in the Z7 block. Here, the setting is 100MHz and the LTC2314 clock will work at more that 40MHz. So, here I chose 2 which result in the spi clock will be 50MHz.

Now that, we are ready to synthesis, implementation and generate bitstream. Then, we get the hardware definition file and we will export this to the Xilinx SDK and launch it. The following is the C code. At first, we initial the SPI through line 44 and 49. In line 56 is to setting to IP core. We start the SPI using XSpi_start in line 61. Then we receive the data through XSpi_transfer and in line 75 is the bitmasking. Last but not least, xil_printf will send the data to the PC through UART with baud rate 115200.

Here is the result from serial plotter from Arduino with sinusoidal wave frequency around 50Hz. The amplitude is 0 to 2.5V. If put more than this, it will be aliasing because it undersampling.

When we run this code, the speed of ADC is fast enough because we run the SPI clock in 50MHz. But when we send the data to PC through UART for debug, it really slow because the UART run with baud rate 115200 which is around 100KHz. So in this here, some data will be lost because of the UART. So, the next topic about this will be try to solve the sending the data to PC. There are many ways to do this, the first solution can be use ethernet.

In summary, this article take you to know how to use the AXI Quad SPI. Thank you for reading.

--

--

Chanon Khongprasongsiri

Electronics Engineer and Master Student at King Mongkut’s University of Technology Thonburi.