Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

USB-8451 I2C interface for MPU 9250-9150-6050 IMU

Hi there, 

 

I'm using the USB-8451 for reading data from a MPU 9250/9150/6050 IMU (mostly the same ). The chip allows a I2C protocol for this task. I usually write my code in C, sometimes CVI but in this case Visual Studio 12.

 

I need to characterize this device for future control applications. Clearly, the bandwidth of my measurements will provide me better spectral information for modelling purposes.

 

1- High level approach:

 

  • First of all, I've tried with the "higher" level API functions, this is, ni845xI2cWriteRead() like functions.
  • The IMU chip puts the measurements in two read only registers. These registers must be accessed by calling two times ni845xI2cWriteRead(), and then building a 16 bit signed data.
  • Unfortunatelly, the performance of this applicaction is so poor than I looked for a possible better startegy for implementation. When I say "poor", I mean 50-80 Hz in a loop, for three axis measurement (3 axis x 2 registers = 6 measurements, not including addresses and ack bites).

2- Scripting approach:

 

  • My second approach was the scripting one. According to NI documentation "more flexible".
  • In this case I'm hoping that by generating a I2C sequence in one shot, I can reduce the communication between the 8451 and the PC (we all know the possible delays added by windows)
  •  My code is basically the next (not optimal, just for explanation)

// Script basics

ni845xI2cScriptOpen (&ScriptHandle); // create script handle
ni845xI2cScriptClockRate (ScriptHandle, I2C_FREQ); // configure clock rate

 

// Read sequences 
ni845xI2cScriptIssueStart (ScriptHandle); // issue start condition
ni845xI2cScriptAddressWrite (ScriptHandle, MPU9250_ADDRESS); //Set direction of I2C device (slave) + direction bit 0 (write)

ni845xI2cScriptWrite (ScriptHandle, nWrite, &dirRegs[0]); //write (1 byte) register address

ni845xI2cScriptIssueStart (ScriptHandle);// issue start condition
ni845xI2cScriptAddressRead (ScriptHandle, MPU9250_ADDRESS); //Set direction of I2C device (slave) + direction bit (1) (read)

ni845xI2cScriptRead (ScriptHandle, nRead1[0], kNi845xI2cNakTrue, &scriptReadIndex[0]);//read number of bytes (1) specified and get Read Index
ni845xI2cScriptIssueStop (ScriptHandle); //issue stop condition
//==============================================================================================
//Second Register (Same code)
//==============================================================================================
ni845xI2cScriptIssueStart (ScriptHandle); // issue start condition
ni845xI2cScriptAddressWrite (ScriptHandle, MPU9250_ADDRESS); //Set direction of I2C device (slave) + direction bit 0 (write)
ni845xI2cScriptWrite (ScriptHandle, nWrite, &dirRegs[1]);//Set direction of I2C device (slave) + direction bit 0 (write)


ni845xI2cScriptIssueStart (ScriptHandle);// issue start condition
ni845xI2cScriptAddressRead (ScriptHandle, MPU9250_ADDRESS);//Set direction of I2C device (slave) + direction bit (1) (read)
ni845xI2cScriptRead (ScriptHandle, nRead2[0], kNi845xI2cNakTrue, &scriptReadIndex[1]);//read number of bytes (1) specified and get Read Index
ni845xI2cScriptIssueStop (ScriptHandle); //issue stop condition
/*========================== RUN ==========================*/
errChk (ni845xI2cScriptRun (ScriptHandle, myUSB8451, PortNumber));
*nRead1 = 0;
*nRead2 = 0;
/*========================== READ ==========================*/
ni845xI2cScriptExtractReadDataSize (ScriptHandle, scriptReadIndex[0], nRead1);
ni845xI2cScriptExtractReadDataSize (ScriptHandle, scriptReadIndex[1], nRead2);
/* extract the read data */
ni845xI2cScriptExtractReadData (ScriptHandle, scriptReadIndex[0], dMeas1);
ni845xI2cScriptExtractReadData (ScriptHandle, scriptReadIndex[1], dMeas2);
/*========================== CLOSE ==========================*/
ni845xI2cScriptClose (ScriptHandle);

 

The behaviour of this code was totally unespected. I'm getting estrange measuments. I buid my data from:

*yM = (double)(((PINT16)rawData_X[0] << 😎 + rawData_X[1]);

 

My measurements are wrong and data jumps continuosly between two values:

 

untitled.png

 

Everithing in this plot is wrong, values and jums.

 

Please, any advice??

 

Thanks a lot.

WAB.

0 Kudos
Message 1 of 1
(4,644 Views)