Reading Multiple Sensors Simultaneously

Discussion in 'Embedded Systems and Microcontrollers' started by Johnny1010, Jun 11, 2016.

  1. Johnny1010

    Thread Starter Member

    Jul 13, 2014
    79
    0
    Hi everyone,

    I have 2 sensors connected to my arduino one is the invensense mpu6050 and the other is a force sensor. I am using the i2cdev library by jeff rowberg for the mpu6050. Now I am sequentially reading the values of mpu and those of the force sensor. Whenever I tap the force sensor very fast the values are skipped because I think at that moment the controller is busy reading values from the mpu. I measured the time taken by the function for reading the mpu is around 10ms. When I stop reading the mpu no matter how fast I tap the sensor there is no value left off.

    What I want is the value of the mpu and the bend sensor at a given time instance.

    Can anybody suggest a possible solution for this?
     
  2. AlbertHall

    Well-Known Member

    Jun 4, 2014
    1,881
    373
    The only way to read multiple sources simultaneously with one micro is if one of the sensors can be triggered and then while it is making its measurement the micro reads the other one then fetches the result of the triggered measurement. I haven't used the MPU6050 but a quick skim tells me that it has a FIFO in which it can store readings to be retrieved later by the micro. Maybe that can solve the problem.
     
  3. dannyf

    Well-Known Member

    Sep 13, 2015
    1,767
    357
    The answer depends on your definition of "simultaneously".

    If you meant to use it literally here, you will need two mcus and you will need to see if the chips can be sampled on command and then read back later.

    If you meant to say that you want to read the chips sufficiently fast so as to almost simultaneously to a human, that's a different ask and certainly can be done easily.
     
  4. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,644
    759
    No idea if those arduinos could do what some PICS in the 18F family: simultaneous ADC followed by successive writing of the target registers with the results.
     
  5. DickCappels

    Moderator

    Aug 21, 2008
    2,647
    632
    Arduinos use Atmel ATMEGA controllers with execution rates of 1 instruction every one or two clocks, depending upon the instruction. Run it at 16 MHz and that's 1 instruction ever 63 nanoseconds for most instructions (Jumps and Branches can take three, if I recall correctly). Of course with the Arduino software and the C compiler underneath it, the code might not be nearly as tight as you could get by using an assembler directly.

    It might just be a matter of re-arranging your code. If there is the need to wait for a measurement, use interrupts so you can be doing other things rather than waiting around for data. An easy way to do that is to use a timer to periodically interrupt whatever is going on and jump to the next task -check out preemptive multitasking.
     
  6. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,644
    759
    So, the most "simultaneous" readings that way, how long would take, Dick? No experience with Atmel.
     
  7. dannyf

    Well-Known Member

    Sep 13, 2015
    1,767
    357
    That would require two independent adc modules, or at least two sample-and-hold units.

    No PIC18s have that. No AVRs (8-bit) have that as well. Some PIC24/dsPIC do.
     
  8. dannyf

    Well-Known Member

    Sep 13, 2015
    1,767
    357
    The OP's probably, however, is slightly different. He's reading / writing to mpu6050 (via i2c) is too slow - 10ms.

    The solution is actually much simpler than being discussed.
     
  9. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,644
    759
    The last PIC I was using before moving to this house, takes simultaneous readings. I should look which one is. To read (and process the readings, of course) it is you that goes sequentially with your code.
     
  10. dannyf

    Well-Known Member

    Sep 13, 2015
    1,767
    357
    well, show me the part number then.

    I think you are talking about reading multiple channels (still sequentially) vs. sampling multiple channels concurrently.
     
  11. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,644
    759
    Concurrently; that's the word!

    Here you have, Daniel.

    Para Daniel.png
     
    tracecom likes this.
  12. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    You will still miss events no matter how fast one reading is if you access the reading thru I2C. It takes a not insignificant time to get the data from the perf to the processor.

    You may want to add a peak detector between the sensor and the A2D to preserve that high tap value. Once you read the value your processor can reset the peak level... Though you may still loose an event there. Only go this way if the intensity of the tap needs be captured.

    An even simpler way is to amplify the senors up to a digital level and use an interrupt to capture the tapping event. You loose amplitude info but get all the events.

    A combination of the two methods may be necessary.
     
  13. Johnny1010

    Thread Starter Member

    Jul 13, 2014
    79
    0
    Guys MPU6050 has an inbuilt DMP which implements some sort of algorithm for the data fusion and this is what takes most of the time and I can't sample from the DMP more than 100 Hz. So, basically this 100 Hz is stopping me from sampling the other sensor at a higher rate.
    If I sample the raw accelerometer and gyro values leaving the dmp out I could sample at 1000 Hz. Now, if I apply a complementary filter myself what do you guys think would that be faster?
     
  14. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Why is this stopping you? Sample the slow thing at a slow rate and sample the fast thing at a fast rate.
     
  15. dannyf

    Well-Known Member

    Sep 13, 2015
    1,767
    357
    that's an interesting part. I didn't know such a beast existed. Thanks.
     
  16. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,644
    759
    I started using it by 2008 IIRC, for the most varied applications, except for what seem its stronger point (motors control).
     
  17. Picbuster

    Member

    Dec 2, 2013
    373
    50
    The mpu6050 is the slowest ( in reaction time) use SPI bus and the trigger output to do two things;
    1:read force sensor use an interrupt to speed up.
    2:read mpu6050 via spi @ highest possible rate. (value is in output registry and clocked out when addressed)
    You introduce a time delay, depending on program and cpu speed, between 1 and 2.
    picbuster
     
Loading...