Jump to content
  • 0

data acquisition system using Cora-Z7-07S-Pmod_Ad1


amilashanaka

Question

Im developing data acquisition system can meassure up to 200 Khz , so far i can measure up to 5Khz , can you give idea how can i improve it ,  im not sure it is limited capacity of SPI  , please advice  me thanks 

my code here 

 

 

image.thumb.png.7dbc3ba8767b1f3216677bfbcde79778.png

 

/******************************************************************************

 * Copyright (C) 2023 Advanced Micro Devices, Inc. All Rights Reserved.

 * SPDX-License-Identifier: MIT

 ******************************************************************************/

/*

 * helloworld.c: simple test application

 *

 * This application configures UART 16550 to baud rate 9600.

 * PS7 UART (Zynq) is not initialized by this application, since

 * bootrom/bsp configures it to baud rate 115200

 *

 * ------------------------------------------------

 * | UART TYPE   BAUD RATE                        |

 * ------------------------------------------------

 *   uartns550   9600

 *   uartlite    Configurable only in HW design

 *   ps7_uart    115200 (configured by bootrom/bsp)

 */

 

#include "platform.h"

#include "xil_printf.h"

#include "xspi.h"

#include "xspi_l.h"

#include <stdio.h>

#include <xparameters_ps.h>

 

// SPI device ID defined in xparameters.h

#define SPI_DEVICE_ID 0

#define BUFFER_SIZE 3

#define NUM_SAMPLES 8000

 

static XSpi SpiInstance;

 

int SpiInit(u16 DeviceId);

void SpiTransfer(u8 *SendBuf, u8 *RecvBuf, int ByteCount);

void Delay(volatile int count);

 

int x = 0;

 

int main() {

  init_platform();

  int Status;

  u8 SendBuffer[BUFFER_SIZE];

  u8 RecvBuffer[BUFFER_SIZE];

 

  u16 samples[NUM_SAMPLES];

 

  // Initialize the SPI driver

  Status = SpiInit(SPI_DEVICE_ID);

  if (Status != XST_SUCCESS) {

    xil_printf("SPI Initialization failed!\n");

    return XST_FAILURE;

  }

 

  // Initialize the send buffer with example data

  for (int i = 0; i < BUFFER_SIZE; i++) {

    SendBuffer[i] = i;

  }

 

  while (1) {

 

    // Collect 1000 samples from Pmod AD1

    for (int i = 0; i < NUM_SAMPLES; i++) {

 

      // Perform SPI transfer

      SpiTransfer(SendBuffer, RecvBuffer, BUFFER_SIZE);

 

      // Print received data in integer format

 

      x = RecvBuffer[1];

      x |= (RecvBuffer[0] << 8);

 

      samples[i] = x; // or use data1 depending on your needs

    }

 

    // Send samples via UART

    for (int i = 0; i < NUM_SAMPLES / 2; i++) {

 

      xil_printf("%d ", samples[i]);

      xil_printf("\r ");

    }

  }

 

  cleanup_platform();

  return XST_SUCCESS;

}

 

int SpiInit(u16 DeviceId) {

  int Status;

  XSpi_Config *ConfigPtr;

 

  // Look up the device configuration

  ConfigPtr = XSpi_LookupConfig(DeviceId);

  if (ConfigPtr == NULL) {

    return XST_FAILURE;

  }

 

  // Initialize the SPI driver

  Status = XSpi_CfgInitialize(&SpiInstance, ConfigPtr, ConfigPtr->BaseAddress);

  if (Status != XST_SUCCESS) {

    return XST_FAILURE;

  }

 

  // Set the SPI options: Master mode, manual slave select

  Status = XSpi_SetOptions(&SpiInstance,

                           XSP_MASTER_OPTION | XSP_MANUAL_SSELECT_OPTION);

  if (Status != XST_SUCCESS) {

    return XST_FAILURE;

  }

 

  // Start the SPI driver

  XSpi_Start(&SpiInstance);

 

  // Disable global interrupt, as this is a polling example

  XSpi_IntrGlobalDisable(&SpiInstance);

 

  // Select the slave device (assuming SS0)

  XSpi_SetSlaveSelect(&SpiInstance, 1);

 

  return XST_SUCCESS;

}

 

void SpiTransfer(u8 *SendBuf, u8 *RecvBuf, int ByteCount) {

  // Perform the SPI transfer

  XSpi_Transfer(&SpiInstance, SendBuf, RecvBuf, ByteCount);

}


 

 

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0
On 6/17/2024 at 9:46 AM, dpaul said:

@amilashanaka

You need to tell us your limitations if you need suggestions from us!

Justing putting here the BD and some will unfortunately not help. You have to be descriptive, what you have done, what you are trying to achieve and what is the bottleneck that you now see!

Thanks replly to me , 

Required  develop  acquisition system can meassure up to 200 Khz, 

hardware  : PMODAD1 & Cora-z7-07s board 

application: c code or python code run in petalinux 

 

Link to comment
Share on other sites

  • 0

Your SPI clock is 6.25 MHz (100/16 == 6.25). According to the datasheet (AD7476A) of the ADC used on PMOD AD1, 6.25 MHz should be more than enough for 200 ksps digitalization.

It is not obvious why you experience only 5 ksps.

However, I think you are not using the ADC correctly. You need to read the datasheet carefully and do SPI reads accordingly. At first glance, I see in the datasheet that one ADC reading is 2 bytes (not 3 bytes as in your code), and then there must be a pause of at least 50 ns before the next SPI read. See page 9 of the datasheet.

I recommend probing the SPI interface to determine what is going on and verifying the timings according to the datasheet's requirements.

Edited by Viktor Nikolov
Link to comment
Share on other sites

  • 0
On 6/22/2024 at 3:15 PM, Viktor Nikolov said:

Your SPI clock is 6.25 MHz (100/16 == 6.25). According to the datasheet (AD7476A) of the ADC used on PMOD AD1, 6.25 MHz should be more than enough for 200 ksps digitalization.

It is not obvious why you experience only 5 ksps.

However, I think you are not using the ADC correctly. You need to read the datasheet carefully and do SPI reads accordingly. At first glance, I see in the datasheet that one ADC reading is 2 bytes (not 3 bytes as in your code), and then there must be a pause of at least 50 ns before the next SPI read. See page 9 of the datasheet.

I recommend probing the SPI interface to determine what is going on and verifying the timings according to the datasheet's requirements.

Thank you somuch , itry to use PMOD AD1 IP as fallows but it does not workign , can you recommended  any working source code for that 

 

image.thumb.png.22e54aa53cfd18b6b09addbbce32a5da.png

 

set_property -dict { PACKAGE_PIN Y18   IOSTANDARD LVCMOS33 } [get_ports { ja_pin1_io }]; #IO_L17P_T2_34 Sch=ja_p[1]
set_property -dict { PACKAGE_PIN Y19   IOSTANDARD LVCMOS33 } [get_ports { ja_pin2_io }]; #IO_L17N_T2_34 Sch=ja_n[1]
set_property -dict { PACKAGE_PIN Y16   IOSTANDARD LVCMOS33 } [get_ports { ja_pin3_io }]; #IO_L7P_T1_34 Sch=ja_p[2]
set_property -dict { PACKAGE_PIN Y17   IOSTANDARD LVCMOS33 } [get_ports { ja_pin4_io }]; #IO_L7N_T1_34 Sch=ja_n[2]
set_property -dict { PACKAGE_PIN U18   IOSTANDARD LVCMOS33 } [get_ports { ja_pin7_io }]; #IO_L12P_T1_MRCC_34 Sch=ja_p[3]
set_property -dict { PACKAGE_PIN U19   IOSTANDARD LVCMOS33 } [get_ports { ja_pin8_io }]; #IO_L12N_T1_MRCC_34 Sch=ja_n[3]
set_property -dict { PACKAGE_PIN W18   IOSTANDARD LVCMOS33 } [get_ports { ja_pin9_io }]; #IO_L22P_T3_34 Sch=ja_p[4]
set_property -dict { PACKAGE_PIN W19   IOSTANDARD LVCMOS33 } [get_ports { ja_pin10_io }]; #IO_L22N_T3_34 Sch=ja_n[4]

 

Thanks

with above PL when i run helloworld program imgetting flowing error 

invalid command name "ps7_init"

 

 

 

 

Edited by amilashanaka
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...