0 Replies Latest reply on Jun 15, 2018 3:50 AM by gr_be

    Reading of XADC to slow

    gr_be

      Hello!

      I bought a Zybo Z7-20 board. And i want to read to analog signals via XADC.

      My first try was to read the voltages from the file with the commands open, read, close. Problem is taking too long.

      I took 60uSec and I only have 6uSec time for this.

      So my next try is to read directly from user space with the following code:

       

      #include <stdio.h>

       

      #include <stdlib.h>

      #include <unistd.h>

      #include <fcntl.h>

      #include <time.h>

      #include <errno.h>

      #include <string.h>

      #include <iostream>

      #include <fstream>

      #include <cstring>

      #include <ctime>

      #include <netinet/in.h>

      #include <arpa/inet.h>

      #include <sys/types.h>

      #include <sys/time.h>

      #include <sys/mman.h>

      #include <sys/socket.h>


      #define XADC_START_ADDR 0x43C00000

      #define XADC_END_ADDR   0x43C0FFFF

      #define XADC_SIZE   (XADC_END_ADDR - XADC_START_ADDR)

      #define XADC_VAUX6  0x16

      #define XADC_VAUX14 0x1E


      void write_data(void *gpio_base, unsigned int offset, unsigned int value){

          *((volatile unsigned *)(gpio_base + offset)) = value;

      }



      int main(int arg, char *argv[]){

          int i;

          int sample = 10;

          int stamp = 2;

          void *xadc_addr;

          unsigned int VolUS[sample], VolIR[sample];

          //char BuffVolUS[i], BuffVolIR[i];

          char BuffTime[stamp][64];


          char fmt[64];

          struct timeval tv[stamp];

          struct tm *tm[stamp];

          struct timesafe {

              int seconds;

              int nano;

          } timestamp[stamp];


          /*

           * Mapping of XADC

           */

          int fd = open("/dev/mem", O_RDWR|O_SYNC);

          printf("Mapping %X - %X (size: %X)\n", XADC_START_ADDR, XADC_END_ADDR, XADC_SIZE);


          xadc_addr = mmap(0, XADC_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, XADC_START_ADDR);

          if (xadc_addr == MAP_FAILED) {

              printf("Unable to map XADC\n");

              return -1;

          }

          printf("XADC mapped to %p\n", xadc_addr);


          /*

           * Read XADC Values + Generate 2 Timestamps

           */

          gettimeofday(&tv[0], NULL); //get current time

          tm[0] = localtime(&tv[0].tv_sec);


          for(i=0; i<sample; i++){

              VolUS[i] = *((volatile unsigned *)(xadc_addr + XADC_VAUX6));

              VolIR[i] = *((volatile unsigned *)(xadc_addr + XADC_VAUX14));


          }

          stamp = 1;          //generate Stop Timestamp

          gettimeofday(&tv[1], NULL);     //get current time

          tm[1] = localtime(&tv[1].tv_sec);


          /*

           * Send XADC Values + Calculate the Timestamps

           */

          for(i=0; i<sample; i++){

              //sprintf(BuffVolUS[i], "%d", VolUS[i]);

              //sprintf(BuffVolIR[i], "%d", VolIR[i]);


              printf("%i --- %i\n", VolUS[i], VolIR[i]);

          }

          for(i=0; i<=stamp; i++){

              strftime (fmt, sizeof (fmt), "%H:%M:%S:%%06u", tm[i]);

              snprintf (BuffTime[i], sizeof (BuffTime[i]), fmt, tv[i].tv_usec);

              printf("Timestamp: %s\n", BuffTime[i]);

          }





          return 0;

      }

      The problem now is, that I only get the value 0 from the register.

       

      Is someone haveing experiences and can help me?

      I am feeling a bit lost now, since days!