8 Replies Latest reply on Sep 22, 2015 2:50 PM by Intel_Alvarado

    How fast is MCU gpio_write( )?

    welcomesorrow

      I have an Edison with Arduino breakout board and Intel's MCU SDK.

      I wonder if MCU's gpio_write takes nano seconds or micro seconds to set a pin level high or low.

      Is MCU gpio_write faster than mraa_gpio_write (if mraa can be used for MCU)?

      Is there any faster alternative for setting gpio or serial pin signals?

       

      Thanks for your comments.

        • 1. Re: How fast is MCU gpio_write( )?
          Intel_Alvarado

          Hi,

           

          We’ll investigate this. We’ll contact you as soon as possible.

           

          Sergio

          • 2. Re: How fast is MCU gpio_write( )?
            welcomesorrow

            Hi Sergio,

             

            Thank you for your attention.

             

            My intention is to generate DMX packets which consists of total of 1 + 8 + 2 = 11 bits of high/low signals where 1 bit corresponds to 4 us. Below, SEQUENCE is an array of 8 bit char which specify lighting patterns. If each gpio_write(PORT, _BYTE) can be finished within a time scale of perhaps 0.1 microseconds, then the script may be OK.

             

            /*
             *  DMX512 Serial Protocol sendPacket function
            */
            
            static int MBB = 100;  /* Mark Before Break */
            static int BREAK = 22  /* Break */
            static int MAB = 2;    /* Mark After Break */
            static int START = 1;  /* Start Bit */
            static int STOP = 2;   /* Stop Bit */
            static int MTBS = 0;   /* Mark Time Between Slots */
            static int TICK = 4;   /* A tick is 4 microseconds */
            
            void sendPacket(int PORT, unsigned char* SEQUENCE)
            {
                int s = strlen((char*)SEQUENCE);
                int* _BYTE = [];
                gpio_setup(PORT, 1);
                gpio_write(PORT, 1);  /* Mark Before Break Hi */
                mcu_delay(MBB * TICK);
                gpio_write(PORT, 0);  /* Break Lo */
                mcu_delay(BREAK * TICK);
                gpio_write(PORT, 1);  /* Mark After Break Hi */
                mcu_delay(MAB * TICK);
                for (i = 0; i < s; i++)  /* Data Sequence */
                {
                    for (j = 0; j < 8; j++)
                        _BYTE[j] = !!(SEQUENCE[i] | (0x1 << j));
                    gpio_write(PORT, 0);  /* Start Bit Lo */
                    mcu_delay(START * TICK);
                    for (j = 0; j < 8; j++)  /* Data Bit 1 - 8*/
                    {
                        gpio_write(PORT, _BYTE[j]);
                        mcu_delay(TICK);
                    }
                    mcu_delay((STOP + MTBS) * TICK);  /* Stop bit + Mark Time Hi */
                }
            }
            
            
            • 3. Re: How fast is MCU gpio_write( )?
              LeonY

              Hey mate, you will most likely not be able to do this on the edison. If you do, please post your results. I would suggest ditching this platform as I have and many others who got tired of Intels "We’ll investigate this. We’ll contact you as soon as possible." policy.

              • 4. Re: How fast is MCU gpio_write( )?
                welcomesorrow

                Hi LeonY,

                 

                Let's hope and see.

                 

                Galileo, which uses 400 MHz Quark core, has fastGpioDigitalWriteDestructive function that achives 2.93 MHz by directly writing into a GPIO register. Since Edison's Quark runs at 100 MHz,  if MCU's gpio_write were an equivalent of Galileo's fast write it would be 683 KHz. That might be fast enough to generate 4 uS = 250 KHz signals.

                • 5. Re: How fast is MCU gpio_write( )?
                  welcomesorrow

                  I measured the MCU GPIO speed with the following script. It was 8.8-8.9 microseconds, approx. 113 MHz. Since DMX512 bit is 4 microsencods, the gpio_write() is about half the speed required. I wish Intel's team develop an API similar to Galileo's fastGpioDigitalWriteDestrutive.

                   

                  void mcu_main() {

                      unsigned long start, stop;

                      char buf[12];

                      int i, len;

                      gpio_setup(40, 1);

                      uart_setup(2, 115200);

                      while (1) {

                          start = time_us();

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

                              gpio_write(40, 1);

                          }

                          stop = time_us();

                          len = mcu_snprintf(buf, 12, "%d us\n", (int) (stop - start));

                          uart_write(2, (unsigned char*) buf, len);

                      }

                  }

                  • 6. Re: How fast is MCU gpio_write( )?
                    Intel_Alvarado

                    Hi,

                     

                    Take a look at this document: Intel® Edison Boards — MCU Digital Pin On/Off Toggle Speed . This document has some measurements of the gpio_write.

                     

                    Sergio

                    • 7. Re: How fast is MCU gpio_write( )?
                      welcomesorrow

                      Hi Sergio,

                       

                      Thanks a lot for your feedback and it is very interesting! Different pins have differnt latencies. My estimate for DIG 13 agrees very well with yours.

                       

                      I need a toggle speed of 4 micro seconds. Is there any possibility that Intel could kindly make Edison version of fastGpioDigitalWriteDestructive API in near future? Alternatively, could one directly access GPIO registers using inline assembler?

                       

                      Thanks,

                       

                      sorrow

                      • 8. Re: How fast is MCU gpio_write( )?
                        Intel_Alvarado

                        Hi,

                         

                        Sure, we will pass this feedback to the appropriate team. Regarding assembler I’d suggest you take a look at Re: Search assembly command list for Edison .

                         

                        Sergio