8 Replies Latest reply on May 6, 2016 7:28 AM by Oscar_s

    External ADC on Intel Galileo Gen 2

    Oscar_s

      Hello everyone!

       

      I have been using an external ADC (MCP3008) with my Arduino Mega 2560. But I want to try and run my code on a Intel Galileo Gen 2.

      It does work, but the number of measurements I can get per second is much lower than on the Arduino.

       

      When I am using the internal ADC of the Galileo I get readings at a frequency around 3,3kHz. I want to make use of the external ADC to get higher frequencies. But I only reach 1,3kHz with the external ADC. My question is, why is this?

       

      The external ADC I am using can sample at 200k measurements per second and I've been able to get around 50 000 readings per second from it using an Arduino Mega 2560 with SPI for communication. Using the same code below as I am now trying to use on the Galileo.


      I suspect the problem is with the SPI communication and I am wondering if I am missing something trivial when using SPI on the Gaileo?

       

      The code I wrote to test the speed I can read in is something like this:

       

      #include "SPI.h"
      const int samples;
      const int channels;
      
      // SPI pins
      const int cs = 10;
      const int miso = 12;
      const int mosi = 11;
      const int sck = 13;
      
      // Instructions to ADC
      byte channel[8] = { 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0 };
      
      void setup() {
        pinMode(cs, OUTPUT);
        SPI.begin();
        SPI.setBitOrder(MSBFIRST);
        SPI.setDataMode(SPI_MODE0);
        Serial.begin(9600);
      }
      
      void loop() {
        unsigned long start = micros();
        for(int j = 0; j < samples; j++) {
             for(int k = 0; k < channels; k++) {
                  // SPI communication
                  digitalWrite(cs, LOW);                 
                  SPI.transfer(0x01);                       // Init
                  byte result2 = SPI.transfer(channel[k]);  // Instructions
                  byte result3 = SPI.transfer(0x00);     
                  digitalWrite(cs, HIGH);
            }
        }
        unsigned long end = micros();
        unsigned long delta = end - start;
        Serial.println(delta);
      }
      
      
      
      
      
      
      
      

       

      Edited by: Oscar Sanden Added more detailed information about the question.

        • 1. Re: External ADC on Intel Galileo Gen 2
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hi,

          It’s hard to know the actual number of measurements per second you should be get because I don’t have the external ADC you’re using. Have you tried to use the internal ADC of the Galileo, what were the results compared to the external ADC you’re using?

          Have you considered using libmraa with the Galileo? http://iotdk.intel.com/docs/master/mraa/

          Sergio
           

          • 2. Re: External ADC on Intel Galileo Gen 2
            Oscar_s

            Hi Sergio!

             

            Thanks for your reply! The ADC I have already used with succes and got around 50 000 measurements per second from it using an Arduino Mega 2560.

            The internal ADC of the Galileo gives me around 3300 measurements per second. Maybe this can be increased?

            I suspect I am messing up the SPI communication in some way for the external ADC.

             

            I will be looking into libmraa, thank you, but I was hoping to be able to use the same code I had already used on the Arduino.

             

            I updated my question with some more details from the questions you asked.

             

            Oscar

            • 3. Re: External ADC on Intel Galileo Gen 2
              Intel Corporation
              This message was posted on behalf of Intel Corporation

              Well, it’s expected for the Arduino sketch of the Galileo to be slightly slower than the Arduino. This is because the Arduino and Galileo have different processors and architectures. Also, the Galileo handles the scripts differently from the Arduino, the Galileo handles sketches as processes in Linux so it’s expected to be slower.

              Let us know if you ran the tests on mraa.

              Sergio
               

              • 4. Re: External ADC on Intel Galileo Gen 2
                FGT

                Intel Corporation wrote:

                 

                Well, it’s expected for the Arduino sketch of the Galileo to be slightly slower than the Arduino. This is because the Arduino and Galileo have different processors and architectures. Also, the Galileo handles the scripts differently from the Arduino, the Galileo handles sketches as processes in Linux so it’s expected to be slower.

                 

                A little bit off topic, but I think the difference is not given by process (Linux-Galileo) vs. bare metal (Arduino) but by the I/O subsystem:

                Arduino Mega: 8-bit 16 MHz

                Galileo: "Intel® Quark™ SoC X1000 application processor, a 32-bit, single-core, single-thread, Intel® Pentium® processor instruction set architecture (ISA)-compatible, operating at speeds up to 400 MHz."

                 

                which means about 25 times faster, only in clock rates, and not taking into account a lot of better hardware in Galileo (e.g. Quark's floating point facilities)

                 

                Fernando.

                • 5. Re: External ADC on Intel Galileo Gen 2
                  xbolshe

                  Hi,

                   

                  your code is not optimized:

                  1. need to remove SPI.transfer and use SPI.transferBuffer instead.

                  2. need to combine all channels into one SPI.transferBuffer command

                  3. need to remove digitalWrite(cs, X); and use an embedded mechanism to control the CS pin.

                  4. need to setup a SPI frequency to a MCP3008 limit.

                   

                  BR,

                  xbolshe

                  • 6. Re: External ADC on Intel Galileo Gen 2
                    FGT

                    Beyond that indicated by xbolshe, you can take a look at many threads, such as

                    SPI speed of the Galileo

                    https://communities.intel.com/message/231432#231432

                     

                    HTH,

                     

                    Fernando.

                    • 7. Re: External ADC on Intel Galileo Gen 2
                      xbolshe

                      I do not think that Galleo's SPI speed limit is critical for MCP3008.

                      MCP3008 has a maximum speed limit around 3.6 ... 1.35 MHz (it depends on Vdd).

                      Gen2 may work even with Fclk = 17 MHz correctly.

                       

                      Only need to set that speed correctly.

                       

                      BR,

                      xbolshe

                      • 8. Re: External ADC on Intel Galileo Gen 2
                        Oscar_s

                        Thank you all for your replies!

                         

                        I am still working on this and will get back and post my results here. Thank you!

                         

                        Best regards

                        Oscar