9 Replies Latest reply on Jul 27, 2016 2:23 PM by AlexT_Intel

    micros() call with MRAA

    TJs

      Is there an MRAA call that returns what micros() does for the Arduino IDE (for an Edison)?

        • 1. Re: micros() call with MRAA
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hi TJs,

          I would like to know which programming language you are using. I checked the MRAA documentation and I didn’t find a similar command that could help, as you know this library allows to control the pins in the board; the micro() function from Arduino returns the number of microseconds since the board began running, this of function is not related to the pins so using MRAA will not help you with this. 
          On Linux, you can run the command cat /proc/uptime, the first number is the total of seconds the system/board has been up. Check the time libraries for the programming language you are using in order to be able to get this number, you can also use system call in order to check this specific file.
          I hope this helps.

          Regards,
          Charlie
           

          • 2. Re: micros() call with MRAA
            TJs

            Hi Charlie, Thanks for the reply.  I am trying to accurately read several hundred sequential encoder pulse times that are on the order of 100 microseconds (uSec).  Using a Arduino UNO with interrupts, I was able to read them to within the accuracy of the 8 bit clock (about 4 uSec).  When I switched over to the Edison using the Arduino IDE, I had some issues with the interrupts which I am working through.  Ultimately, I will be using C in Eclipse to program the Edison, but I want to make sure I can get the data accurately before programming too much. I will test the Linux call this week and see how it works, but I have some concerns as I read in other posts that this only has millisecond (not microsecond) resolution. As you can probably tell by my questions, I am somewhat new at this. If there is a better way, I'm all ears.  This question was also posed in   Is it possible to get a timer with a very small period? and AlexT_Intel responded, so I apologize for doubling this question up.  -TJS

            • 3. Re: micros() call with MRAA
              Intel Corporation
              This message was posted on behalf of Intel Corporation

                Hi,

              I haven’t seen examples of codes for Edison using microseconds, but I think that using the timer.h libraries and some system calls it may be possible. I also suggest you to check first the functionality of the functions you will discover before coding your entire project. Please let me know the advance you and results you get in this week, I will be looking for something else that may help us.

              Regards,
              Charlie

              • 4. Re: micros() call with MRAA
                AlexT_Intel

                In general, getting down to that level of precision may be hard due to the fact that on Edison you are working on the general-purpose multiprocess OS, which is not a real-time one. So you don't have any guarantees as to the times allotted for your process to run or when it's going to be preempted. So the task you're after may be better accomplished using Edison's MCU. It does have an RTOS on it and no competing tasks + it has means to communicate with CPU in case you need to do something high-level with that data, see MCU SDK API description.

                 

                On Linux you could use gettimeofday() or clock_gettime() functions defined in time.h to get current time down to microsecond level, as Charlie mentioned. So if your program is lean enough and if you switch off all necessary processes on your Edison, which compete for CPU time, you can try doing a busy loop pattern, checking time using one of those functions and reading the encoder parameters you are after.

                 

                Try to measure how long a single such loop takes in your case and if it's noticeably smaller that your average time unit for the project (so that there's headroom for that OS noise) - you may be good doing it purely on CPU. If not - I'd suggest you to look into Edison MCU, or getting an Arduino 101 and connecting it to Edison via mraa's firmata/imraa functionality. The latter may be an overkill, as you need a second board, but I just want to describe all options I see here, so that you can pick whatever fits your project.

                1 of 1 people found this helpful
                • 5. Re: micros() call with MRAA
                  TJs

                  AlexT - Thanks for that input, very helpful.  Can you provide a link to learn more about the MCU SDK API?  Just a quick update on the project - I was able to get 1 uSec resolution with a MKR1000 Arduino (32 bit ARM at 48MHz), but now I need to get the data to Edison for processing and displaying data over WiFi.  I am trying to send the array of data over serial which is giving me some fits, but I know it's doable. I am also testing an external 100 MHz ripple counter (74HC4020) which should be a lot more accurate and maybe can be done only with the Edison.  I have not used this IC before, so I have another question about reading the 12 bits of data (counts) with the Edison.  It seams to me that this should be done quickly with a direct port read.  Is this possible with the Edison?

                  • 6. Re: micros() call with MRAA
                    TJs

                    AlexT - Thanks for that input, very helpful.  Can you provide a link to learn more about the MCU SDK API?  Just a quick update on the project - I was able to get 1 uSec resolution with a MKR1000 Arduino (32 bit ARM at 48MHz), but now I need to get the data to Edison for processing and displaying data over WiFi.  I am trying to send the array of data over serial which is giving me some fits, but I know it's doable. I am also testing an external 100 MHz ripple counter (74HC4020) which should be a lot more accurate and maybe can be done only with the Edison.  I have not used this IC before, so I have another question about reading the 12 bits of data (counts) with the Edison.  It seams to me that this should be done quickly with a direct port read.  Is this possible with the Edison?

                    • 7. Re: micros() call with MRAA
                      FerryT

                      We are using:

                              #include <sys/time.h>

                          clock_gettime(CLOCK_REALTIME, &Tick); //retrieve time of realtime clock
                          TimeLast = (unsigned long)Tick.tv_nsec;

                      and link with -lrt

                       

                      I noticed clock_gettime doesn't always return 0, and then Tick contains invalid data.

                       

                      But as mentioned, even though the clock may be accurate, the non-rt behavior causes the clock to be retrieved not exactly when when you called it. We are playing around with the preempt-rt patch, will post separately on that when I have some sane results.

                      1 of 1 people found this helpful
                      • 8. Re: micros() call with MRAA
                        TJs

                        Link found for MCU SDk:  Creating applications with the MCU SDK for the Intel® Edison board: Overview | Intel® Software. Spent the last 3+ hours trying unsuccessfully installing the software.  3 forum links with the same problems.  (MCU-SDK: mcusdk.exe doesn't start MCU SDK failed to execute MCU SDK exe failed ) 64bit cygwin downloaded and installed to D:/MCU directory (no spaces) but still won't run.  I probably should post this issue here but I'm a bit frustrated.

                        • 9. Re: micros() call with MRAA
                          AlexT_Intel

                          Too bad it won't run! I haven't used MCU SDK for quite a while, but I tested that version 1.0.10 and it worked fine for me. You really should start a thread on this, I'm sure either community or support team will help you sort it out.

                           

                          As far as 74HC4020 - no idea, to be honest as I haven't worked with this part at all and I'm not sure what speed or type of access you can do using a serial there. Very generally speaking, as Edison has a standard UART with quite a few supported data rates, if that part supports that, you should be able to work with it, UART is less sensitive to processing time jitter in the multi-process OS, so depending on the details of your project, it may be up to the task.