Legacy Forum: Preserving Nearly 20 Years of Community History - A Time Capsule of Discussions, Memories, and Shared Experiences.

continuous acquisition using the AD7918 on the RB-100

Based on DMP's Vortex processor / SoC this board is a full computer capable of running a standard Windows and Linux installation on the backpack of your robot.
16 postsPage 1 of 21, 2
16 postsPage 1 of 21, 2

continuous acquisition using the AD7918 on the RB-100

Post by wahooburger » Wed Mar 31, 2010 11:01 pm

Post by wahooburger
Wed Mar 31, 2010 11:01 pm

Hello,

I am writing to inquire if you anyone can provide some suggestions, example tutorials or example source code on how to use the AD7918 to do continuous analog-to-digital acquisition for a Windows XP installation on the Roboard-100 using the .h or .dll files. We are trying to capture the voltage versus time signature from an ultrasound rangefinder at approximately 10 kHz sampling rate.

Many thanks for your kind assistance.

Regards,
Andy
Hello,

I am writing to inquire if you anyone can provide some suggestions, example tutorials or example source code on how to use the AD7918 to do continuous analog-to-digital acquisition for a Windows XP installation on the Roboard-100 using the .h or .dll files. We are trying to capture the voltage versus time signature from an ultrasound rangefinder at approximately 10 kHz sampling rate.

Many thanks for your kind assistance.

Regards,
Andy
wahooburger
Newbie
Newbie
Posts: 5
Joined: Wed Mar 24, 2010 10:38 pm

Re: continuous acquisition using the AD7918 on the RB-100

Post by roboard » Thu Apr 01, 2010 2:37 pm

Post by roboard
Thu Apr 01, 2010 2:37 pm

Code: Select all
//Example : Analog to Digital Converter on RoBoard(AD7918)
#include <stdio.h>
#include <roboard.h>
int main()
{
   int* val;
   int c,i;
   //choose 0 ~ 7 channels that you want to use
   unsigned int usedchannels = AD7918_USECHANNEL0 +
                                             AD7918_USECHANNEL1 +
                                             AD7918_USECHANNEL2 +
                                             AD7918_USECHANNEL3 +
                                             AD7918_USECHANNEL4 +
                                             AD7918_USECHANNEL5 +
                                             AD7918_USECHANNEL6 +
                                             AD7918_USECHANNEL7;
   printf("Start ADC\n");

   //SPI interface should be initialized first
   if(spi_Initialize(SPICLK_21400KHZ) == false)
   {
      printf("SPI Initialize Failure : %s",roboio_GetErrMsg());
      spi_Close();
      return -1;
   }

   //Set AD7918 Input-voltage range: 0V ~ 5V , value range : -512 ~ 511
   if (ad7918_InitializeMCH(usedchannels,AD7918MODE_RANGE_2VREF,AD7918MODE_CODING_511) == false)
   {
      printf("AD7918 Initialize Failure : %s",roboio_GetErrMsg());
      spi_Close();
      return -1;
   }
   
   while((c = getchar()) != 'q')//Press enter to read AD value or 'q' to exit
   {
      if(c == '\n')
      {
         val = ad7918_ReadMCH();
         for(i = 0;i < 8;i++)
            printf("AD7918 channel %d = %d\n",i,val[i]);
      }
   }

   ad7918_CloseMCH();
   spi_Close();
   return 0;
}
Code: Select all
//Example : Analog to Digital Converter on RoBoard(AD7918)
#include <stdio.h>
#include <roboard.h>
int main()
{
   int* val;
   int c,i;
   //choose 0 ~ 7 channels that you want to use
   unsigned int usedchannels = AD7918_USECHANNEL0 +
                                             AD7918_USECHANNEL1 +
                                             AD7918_USECHANNEL2 +
                                             AD7918_USECHANNEL3 +
                                             AD7918_USECHANNEL4 +
                                             AD7918_USECHANNEL5 +
                                             AD7918_USECHANNEL6 +
                                             AD7918_USECHANNEL7;
   printf("Start ADC\n");

   //SPI interface should be initialized first
   if(spi_Initialize(SPICLK_21400KHZ) == false)
   {
      printf("SPI Initialize Failure : %s",roboio_GetErrMsg());
      spi_Close();
      return -1;
   }

   //Set AD7918 Input-voltage range: 0V ~ 5V , value range : -512 ~ 511
   if (ad7918_InitializeMCH(usedchannels,AD7918MODE_RANGE_2VREF,AD7918MODE_CODING_511) == false)
   {
      printf("AD7918 Initialize Failure : %s",roboio_GetErrMsg());
      spi_Close();
      return -1;
   }
   
   while((c = getchar()) != 'q')//Press enter to read AD value or 'q' to exit
   {
      if(c == '\n')
      {
         val = ad7918_ReadMCH();
         for(i = 0;i < 8;i++)
            printf("AD7918 channel %d = %d\n",i,val[i]);
      }
   }

   ad7918_CloseMCH();
   spi_Close();
   return 0;
}
roboard
Savvy Roboteer
Savvy Roboteer
Posts: 302
Joined: Fri Jul 03, 2009 4:44 am

Post by wahooburger » Thu Apr 01, 2010 3:08 pm

Post by wahooburger
Thu Apr 01, 2010 3:08 pm

Hello,

Many thanks for the example.

Does that source code implement a single reading of one A/D value that I can repeat when pressing the enter key? If so, can it be changed do continuous acquisition ( see example below)

I am attempting to do a continuous acquisition at 1 kHz sampling rate over a period of 1 second, so I would want 1 second * 1 KSamples / second = 1000 samples each time I hit the enter key.

Many thanks for your kind assistance.

Regards,
Andy
Hello,

Many thanks for the example.

Does that source code implement a single reading of one A/D value that I can repeat when pressing the enter key? If so, can it be changed do continuous acquisition ( see example below)

I am attempting to do a continuous acquisition at 1 kHz sampling rate over a period of 1 second, so I would want 1 second * 1 KSamples / second = 1000 samples each time I hit the enter key.

Many thanks for your kind assistance.

Regards,
Andy
wahooburger
Newbie
Newbie
Posts: 5
Joined: Wed Mar 24, 2010 10:38 pm

Post by roboard » Tue Apr 06, 2010 6:56 am

Post by roboard
Tue Apr 06, 2010 6:56 am

wahooburger wrote:Hello,

Many thanks for the example.

Does that source code implement a single reading of one A/D value that I can repeat when pressing the enter key? If so, can it be changed do continuous acquisition ( see example below)

I am attempting to do a continuous acquisition at 1 kHz sampling rate over a period of 1 second, so I would want 1 second * 1 KSamples / second = 1000 samples each time I hit the enter key.

Many thanks for your kind assistance.

Regards,
Andy


Hi,

ad7918_ReadMCH() and related MCH functions use AD7918's continuous acquistion mode; they don't simply repeat the single reading. Please check the source code to see how they are implemented:)
wahooburger wrote:Hello,

Many thanks for the example.

Does that source code implement a single reading of one A/D value that I can repeat when pressing the enter key? If so, can it be changed do continuous acquisition ( see example below)

I am attempting to do a continuous acquisition at 1 kHz sampling rate over a period of 1 second, so I would want 1 second * 1 KSamples / second = 1000 samples each time I hit the enter key.

Many thanks for your kind assistance.

Regards,
Andy


Hi,

ad7918_ReadMCH() and related MCH functions use AD7918's continuous acquistion mode; they don't simply repeat the single reading. Please check the source code to see how they are implemented:)
roboard
Savvy Roboteer
Savvy Roboteer
Posts: 302
Joined: Fri Jul 03, 2009 4:44 am

Post by wahooburger » Tue Apr 06, 2010 3:52 pm

Post by wahooburger
Tue Apr 06, 2010 3:52 pm

Hello,
thank you for the clarification.
Just got the Roboard yesterday, and should be able to start testing things out!
looking forward to working with it.
Hello,
thank you for the clarification.
Just got the Roboard yesterday, and should be able to start testing things out!
looking forward to working with it.
wahooburger
Newbie
Newbie
Posts: 5
Joined: Wed Mar 24, 2010 10:38 pm

Source code for test ADC

Post by ea4ps » Wed Jul 14, 2010 9:13 pm

Post by ea4ps
Wed Jul 14, 2010 9:13 pm

Hi!

I'm trying to test the source code downloaded roboard's web to use ADC for a sensor temperature but I can't even run the examples (e.g. Roboard.cpp).
I have also tried to create a myexample.c including the code write here for roboard user. If I compile this code with gcc -o myexe niexample.c I get a lot of errors.

How I can test the examples?

Thanks,
Hi!

I'm trying to test the source code downloaded roboard's web to use ADC for a sensor temperature but I can't even run the examples (e.g. Roboard.cpp).
I have also tried to create a myexample.c including the code write here for roboard user. If I compile this code with gcc -o myexe niexample.c I get a lot of errors.

How I can test the examples?

Thanks,
ea4ps
Robot Builder
Robot Builder
Posts: 15
Joined: Fri Jan 22, 2010 7:02 pm

Post by matt.stevenson » Wed Jul 14, 2010 11:03 pm

Post by matt.stevenson
Wed Jul 14, 2010 11:03 pm

@ea4ps:
Are you running windows or linux? From the gcc it sounds like linux.

Have you managed to build the the roboard libraries first? They come with a a Makefile Make.LINUX. You can compile with:
make -f Make.LINUX

Once you have that built, when you compile your code make sure to link the appropriate libraries in your gcc command.
@ea4ps:
Are you running windows or linux? From the gcc it sounds like linux.

Have you managed to build the the roboard libraries first? They come with a a Makefile Make.LINUX. You can compile with:
make -f Make.LINUX

Once you have that built, when you compile your code make sure to link the appropriate libraries in your gcc command.
matt.stevenson
Savvy Roboteer
Savvy Roboteer
Posts: 37
Joined: Thu Apr 29, 2010 9:29 pm

Post by ea4ps » Thu Jul 15, 2010 7:35 pm

Post by ea4ps
Thu Jul 15, 2010 7:35 pm

Thank you for your advise.
I finally found out how to compile my main. I typed:
g++ -o demo demo.c -I../libsrc -L../ -static -lRBIO
in the place where demo.c contains the code of this thread.

Sorry for my ignorance but, the values returned (-512 if pin is null) are in units of milivolts (mV)?
My temperature sensor returns values between 250 and 350 although the measure is in both at the same time, why the diffrence if temperature no change? In the datasheet (LM35) 250mV is equivalent to 25ºC. Near to heatsink I think that this value is wrong.
For test, I connected one batterie (AA 1,5V) to ADC and the value returned was 32700, but I still don't know the equivalent of return value for ad7918_ReadMCH() and voltage.

Sorry for my very bad english :-(
Thank you for your advise.
I finally found out how to compile my main. I typed:
g++ -o demo demo.c -I../libsrc -L../ -static -lRBIO
in the place where demo.c contains the code of this thread.

Sorry for my ignorance but, the values returned (-512 if pin is null) are in units of milivolts (mV)?
My temperature sensor returns values between 250 and 350 although the measure is in both at the same time, why the diffrence if temperature no change? In the datasheet (LM35) 250mV is equivalent to 25ºC. Near to heatsink I think that this value is wrong.
For test, I connected one batterie (AA 1,5V) to ADC and the value returned was 32700, but I still don't know the equivalent of return value for ad7918_ReadMCH() and voltage.

Sorry for my very bad english :-(
ea4ps
Robot Builder
Robot Builder
Posts: 15
Joined: Fri Jan 22, 2010 7:02 pm

Post by matt.stevenson » Thu Jul 15, 2010 8:26 pm

Post by matt.stevenson
Thu Jul 15, 2010 8:26 pm

I haven't done any work with the ADC yet.
If I have some time later today, I will hook it up with my accelerometer and see if I can get it working properly.
I haven't done any work with the ADC yet.
If I have some time later today, I will hook it up with my accelerometer and see if I can get it working properly.
matt.stevenson
Savvy Roboteer
Savvy Roboteer
Posts: 37
Joined: Thu Apr 29, 2010 9:29 pm

Post by roboard » Tue Jul 20, 2010 4:31 am

Post by roboard
Tue Jul 20, 2010 4:31 am

ea4ps wrote:Sorry for my ignorance but, the values returned (-512 if pin is null) are in units of milivolts (mV)?
...
For test, I connected one batterie (AA 1,5V) to ADC and the value returned was 32700, but I still don't know the equivalent of return value for ad7918_ReadMCH() and voltage.


Hi,

If you initialize ad7918_InitializeMCH() with AD7918MODE_RANGE_2VREF option, the unit of the returned value is 5V/1024 (~5mV); and if with AD7918MODE_RANGE_VREF option, the unit is 2.5V/1024 (~2.5mV).

Also, with AD7918MODE_CODING_1023 option, the returned value 0 corresponds to 0V, and value 1023 corresponds to the selected maximum voltage limit (2.5V or 5V);

with AD7918MODE_CODING_511 option, the returned value -512 corresponds to 0V, and value 511 corresponds to the selected maximum voltage limit (2.5V or 5V).

The returned value 32767 indicates an ADC fail or that the corresponding channel is not selected when calling ad7918_InitializeMCH().
ea4ps wrote:Sorry for my ignorance but, the values returned (-512 if pin is null) are in units of milivolts (mV)?
...
For test, I connected one batterie (AA 1,5V) to ADC and the value returned was 32700, but I still don't know the equivalent of return value for ad7918_ReadMCH() and voltage.


Hi,

If you initialize ad7918_InitializeMCH() with AD7918MODE_RANGE_2VREF option, the unit of the returned value is 5V/1024 (~5mV); and if with AD7918MODE_RANGE_VREF option, the unit is 2.5V/1024 (~2.5mV).

Also, with AD7918MODE_CODING_1023 option, the returned value 0 corresponds to 0V, and value 1023 corresponds to the selected maximum voltage limit (2.5V or 5V);

with AD7918MODE_CODING_511 option, the returned value -512 corresponds to 0V, and value 511 corresponds to the selected maximum voltage limit (2.5V or 5V).

The returned value 32767 indicates an ADC fail or that the corresponding channel is not selected when calling ad7918_InitializeMCH().
roboard
Savvy Roboteer
Savvy Roboteer
Posts: 302
Joined: Fri Jul 03, 2009 4:44 am

Post by ea4ps » Fri Jul 23, 2010 8:37 pm

Post by ea4ps
Fri Jul 23, 2010 8:37 pm

roboard wrote:Hi,

If you initialize ad7918_InitializeMCH() with AD7918MODE_RANGE_2VREF option, the unit of the returned value is 5V/1024 (~5mV); and if with AD7918MODE_RANGE_VREF option, the unit is 2.5V/1024 (~2.5mV).

Also, with AD7918MODE_CODING_1023 option, the returned value 0 corresponds to 0V, and value 1023 corresponds to the selected maximum voltage limit (2.5V or 5V);

with AD7918MODE_CODING_511 option, the returned value -512 corresponds to 0V, and value 511 corresponds to the selected maximum voltage limit (2.5V or 5V).

The returned value 32767 indicates an ADC fail or that the corresponding channel is not selected when calling ad7918_InitializeMCH().


Thanks for help me! but something goes wrong. Im executing this program and if Im wrong in this code are initialized all channels, however, I get out this:
AD7918 channel 0 = 32767
AD7918 channel 1 = 496
AD7918 channel 2 = 32767
AD7918 channel 3 = 32767
AD7918 channel 4 = 32767
AD7918 channel 5 = 32767
AD7918 channel 6 = 32767
AD7918 channel 7 = 1023

and I have nothing connected to any pin. If I connected any voltage exit of program is the same. ADC chip could be broken?

:-|
roboard wrote:Hi,

If you initialize ad7918_InitializeMCH() with AD7918MODE_RANGE_2VREF option, the unit of the returned value is 5V/1024 (~5mV); and if with AD7918MODE_RANGE_VREF option, the unit is 2.5V/1024 (~2.5mV).

Also, with AD7918MODE_CODING_1023 option, the returned value 0 corresponds to 0V, and value 1023 corresponds to the selected maximum voltage limit (2.5V or 5V);

with AD7918MODE_CODING_511 option, the returned value -512 corresponds to 0V, and value 511 corresponds to the selected maximum voltage limit (2.5V or 5V).

The returned value 32767 indicates an ADC fail or that the corresponding channel is not selected when calling ad7918_InitializeMCH().


Thanks for help me! but something goes wrong. Im executing this program and if Im wrong in this code are initialized all channels, however, I get out this:
AD7918 channel 0 = 32767
AD7918 channel 1 = 496
AD7918 channel 2 = 32767
AD7918 channel 3 = 32767
AD7918 channel 4 = 32767
AD7918 channel 5 = 32767
AD7918 channel 6 = 32767
AD7918 channel 7 = 1023

and I have nothing connected to any pin. If I connected any voltage exit of program is the same. ADC chip could be broken?

:-|
ea4ps
Robot Builder
Robot Builder
Posts: 15
Joined: Fri Jan 22, 2010 7:02 pm

Post by roboard » Mon Jul 26, 2010 6:27 am

Post by roboard
Mon Jul 26, 2010 6:27 am

ea4ps wrote:Thanks for help me! but something goes wrong. Im executing this program and if Im wrong in this code are initialized all channels, however, I get out this:
AD7918 channel 0 = 32767
AD7918 channel 1 = 496
AD7918 channel 2 = 32767
AD7918 channel 3 = 32767
AD7918 channel 4 = 32767
AD7918 channel 5 = 32767
AD7918 channel 6 = 32767
AD7918 channel 7 = 1023

and I have nothing connected to any pin. If I connected any voltage exit of program is the same. ADC chip could be broken?

:-|


Hi,

please post you ADC code; we will check whether your code is correct. :)
ea4ps wrote:Thanks for help me! but something goes wrong. Im executing this program and if Im wrong in this code are initialized all channels, however, I get out this:
AD7918 channel 0 = 32767
AD7918 channel 1 = 496
AD7918 channel 2 = 32767
AD7918 channel 3 = 32767
AD7918 channel 4 = 32767
AD7918 channel 5 = 32767
AD7918 channel 6 = 32767
AD7918 channel 7 = 1023

and I have nothing connected to any pin. If I connected any voltage exit of program is the same. ADC chip could be broken?

:-|


Hi,

please post you ADC code; we will check whether your code is correct. :)
roboard
Savvy Roboteer
Savvy Roboteer
Posts: 302
Joined: Fri Jul 03, 2009 4:44 am

Post by ea4ps » Mon Jul 26, 2010 6:37 am

Post by ea4ps
Mon Jul 26, 2010 6:37 am

My code is exactly the same as written here, the second message of this thread.

I really appreciate your help
My code is exactly the same as written here, the second message of this thread.

I really appreciate your help
ea4ps
Robot Builder
Robot Builder
Posts: 15
Joined: Fri Jan 22, 2010 7:02 pm

Post by roboard » Mon Jul 26, 2010 1:40 pm

Post by roboard
Mon Jul 26, 2010 1:40 pm

ea4ps wrote:My code is exactly the same as written here, the second message of this thread.


Hi,

that code does always not print value > 511 (even if the ADC were broken) because it uses AD7918MODE_CODING_511 to initialize.

That code is for RB-100, and, if your RoBoard is RB-110, you need to employ the newest version of RoBoIO (i.e., RoBoIO 1.6) and add roboio_SetRBVer(RB-110) at the beginning to try again. :)

Code: Select all
#include <stdio.h>
#include <roboard.h>
int main()
{
   int* val;
   int c,i;
   //choose 0 ~ 7 channels that you want to use
   unsigned char usedchannels = AD7918_USECHANNEL0 +
                                                AD7918_USECHANNEL1 +
                                                AD7918_USECHANNEL2 +
                                                AD7918_USECHANNEL3 +
                                                AD7918_USECHANNEL4 +
                                                AD7918_USECHANNEL5 +
                                                AD7918_USECHANNEL6 +
                                                AD7918_USECHANNEL7;
   printf("Start ADC\n");

   roboio_SetRBVer(RB-110);

   //SPI interface should be initialized first
   if(spi_Initialize(SPICLK_21400KHZ) == false)
   {
      printf("SPI Initialize Failure : %s",roboio_GetErrMsg());
      spi_Close();
      return -1;
   }

   //Set AD7918 Input-voltage range: 0V ~ 5V , value range : -512 ~ 511
   if (ad7918_InitializeMCH(usedchannels, AD7918MODE_RANGE_2VREF, AD7918MODE_CODING_511) == false)
   {
      printf("AD7918 Initialize Failure : %s",roboio_GetErrMsg());
      spi_Close();
      return -1;
   }
   
   while((c = getchar()) != 'q')//Press enter to read AD value or 'q' to exit
   {
      if(c == '\n')
      {
         val = ad7918_ReadMCH();
         for(i = 0;i < 8;i++)
            printf("AD7918 channel %d = %d\n",i,val[i]);
      }
   }

   ad7918_CloseMCH();
   spi_Close();
   return 0;
}

ea4ps wrote:My code is exactly the same as written here, the second message of this thread.


Hi,

that code does always not print value > 511 (even if the ADC were broken) because it uses AD7918MODE_CODING_511 to initialize.

That code is for RB-100, and, if your RoBoard is RB-110, you need to employ the newest version of RoBoIO (i.e., RoBoIO 1.6) and add roboio_SetRBVer(RB-110) at the beginning to try again. :)

Code: Select all
#include <stdio.h>
#include <roboard.h>
int main()
{
   int* val;
   int c,i;
   //choose 0 ~ 7 channels that you want to use
   unsigned char usedchannels = AD7918_USECHANNEL0 +
                                                AD7918_USECHANNEL1 +
                                                AD7918_USECHANNEL2 +
                                                AD7918_USECHANNEL3 +
                                                AD7918_USECHANNEL4 +
                                                AD7918_USECHANNEL5 +
                                                AD7918_USECHANNEL6 +
                                                AD7918_USECHANNEL7;
   printf("Start ADC\n");

   roboio_SetRBVer(RB-110);

   //SPI interface should be initialized first
   if(spi_Initialize(SPICLK_21400KHZ) == false)
   {
      printf("SPI Initialize Failure : %s",roboio_GetErrMsg());
      spi_Close();
      return -1;
   }

   //Set AD7918 Input-voltage range: 0V ~ 5V , value range : -512 ~ 511
   if (ad7918_InitializeMCH(usedchannels, AD7918MODE_RANGE_2VREF, AD7918MODE_CODING_511) == false)
   {
      printf("AD7918 Initialize Failure : %s",roboio_GetErrMsg());
      spi_Close();
      return -1;
   }
   
   while((c = getchar()) != 'q')//Press enter to read AD value or 'q' to exit
   {
      if(c == '\n')
      {
         val = ad7918_ReadMCH();
         for(i = 0;i < 8;i++)
            printf("AD7918 channel %d = %d\n",i,val[i]);
      }
   }

   ad7918_CloseMCH();
   spi_Close();
   return 0;
}

roboard
Savvy Roboteer
Savvy Roboteer
Posts: 302
Joined: Fri Jul 03, 2009 4:44 am

Post by ea4ps » Mon Jul 26, 2010 2:02 pm

Post by ea4ps
Mon Jul 26, 2010 2:02 pm

My fault!!! I did try and change the variable to 1023, for this reason in channel 7 I get 1023 value. Despite this, why do I get values like 32767 if these are inicializated or 496 and 1023 if nothing is connected?
I think that this happend because the adc chip is ?burned?
My fault!!! I did try and change the variable to 1023, for this reason in channel 7 I get 1023 value. Despite this, why do I get values like 32767 if these are inicializated or 496 and 1023 if nothing is connected?
I think that this happend because the adc chip is ?burned?
ea4ps
Robot Builder
Robot Builder
Posts: 15
Joined: Fri Jan 22, 2010 7:02 pm

Next
16 postsPage 1 of 21, 2
16 postsPage 1 of 21, 2