This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Adding axis data and storing in a new column in CSV



Hello every one

I am trying to add X-axis data and Y-axis data. And want to store them in the csv file with new column. I started from "ProcessDataItems(tLogRecord *pRecord)" under acquire.c file. I am using IQMath library.

ProcessDataItems(tLogRecord *pRecord)
{

_iq accelx, accely, rval;
//long lAccel;

unsigned int r;
unsigned int uIdx;
unsigned int uItemIdx = 0;
unsigned long ulSelectedMask = g_pConfigState->usSelectedMask;

//
// Save the time stamp that was saved when the ADC data was acquired.
// Also save into the record the bit mask of the selected data items.
//
pRecord->ulSeconds = g_ulTimeStamp[0];
pRecord->usSubseconds = (unsigned short)g_ulTimeStamp[1];
pRecord->usItemMask = (unsigned short)ulSelectedMask;

..................

............................

//
// Process the accelerometers. These will be processed and stored in
// units of 1/100 g.
//

for(uIdx = LOG_ITEM_ACCELX; uIdx <= LOG_ITEM_ACCELZ; uIdx++)
{

//
// Check to see if this item should be logged
//
           if((1 << uIdx) & ulSelectedMask)
           {
                  //long lAccel;

                  lAccel = (((long)g_ulADCData[uIdx] - 2047L) * 1000L) / 4095L;

                  pRecord->sItems[uItemIdx++] = (short)lAccel;
           }
                     if (uIdx ==LOG_ITEM_ACCELX)
                     {
                            accelx = lAccel;
                    }
                    if (uIdx ==LOG_ITEM_ACCELY)
                    {
                          accely = lAccel;
                   }
}

rval = _IQmag(accelx,accely);

pRecord->sItems[uItemIdx++] = (short)rval;

...............................................

After executing the program, I got the following output and which is not accurate. 

AccelX(.01g) AccelY(.01g) AccelZ(.01g)
2 17476 -3
0 17476 -3
1 17476 -4
1 17476 -3
2 17476 -3
1 17476 -4
-1 17476 -2
0 17476 -5
0 17476 -5
1 17476 -4

Can anyone suggest me for this problem.

Thanks in advance

Rupok

  • Hello Rupok,

    Which device example are you using. LM4F or TM4C123?

    Regards
    Amit
  • Hi Amit
    I am using EK-LM4f232H5QD evaluation board
    Regards
    Rupok
  • Hi Amit

    Now I am getting this output in log file.

    AccelX(.01g) AccelY(.01g) AccelZ(.01g) rval Ext. Temp(.1C) Int. Temp(.1C) Current(100uA)
    0 -3 103 18580
    -25 -5 91 18580
    -22 -6 93 18580
    -23 1 93 18580
    -43 4 103 18580
    -44 0 92 18580
    -34 3 80 18580
    -33 1 87 18580
    -26 0 102 18580


    I have made following change in "ProcessDataItems(tLogRecord *pRecord) function at acquire.c file

    //
    // Process the accelerometers. These will be processed and stored in
    // units of 1/100 g.
    //

    for(uIdx = LOG_ITEM_ACCELX; uIdx <= LOG_ITEM_ACCELZ; uIdx++)
    {
    //
    // Check to see if this item should be logged
    //
         if (uIdx ==LOG_ITEM_ACCELX)
         {
             if((1 << uIdx) & ulSelectedMask)
             {
               long lAccel;
               lAccel = (((long)g_ulADCData[uIdx] - 2047L) * 1000L) / 4095L;
               accelx = lAccel;

              pRecord->sItems[uItemIdx++] = (short)lAccel;
              }

         }
        if (uIdx ==LOG_ITEM_ACCELY)
       {
            if((1 << uIdx) & ulSelectedMask)
            {
               long lAccel;
               lAccel = (((long)g_ulADCData[uIdx] - 2047L) * 1000L) / 4095L;
               accely = lAccel;
               pRecord->sItems[uItemIdx++] = (short)lAccel;
             }
        }
            if (uIdx ==LOG_ITEM_ACCELZ)
           {
                if((1 << uIdx) & ulSelectedMask)
                {
                   long lAccel;
                  lAccel = (((long)g_ulADCData[uIdx] - 2047L) * 1000L) / 4095L;

                 pRecord->sItems[uItemIdx++] = (short)lAccel;
            }

    }

    rval = _IQmag(accelx,accely);

    pRecord1->bItems = (short)rval;
    ////////////////////////////////////////////////////////////////////////////////

    I have also added one column called "rval" in USBStick.c file and also added the following in USBStick.c file:

    ulBufIdx += usnprintf(&cBuf[ulBufIdx], sizeof(cBuf) - ulBufIdx,
                                                                              ",%d", pRecord1->bItems);

    /////////////////////////////////////////////////////////////////////////////////////////////

    In qs-logger.h, I have added a new structure "tLogRecord1" with element "bItems".

    typedef struct
    {

    short bItems;

    } tLogRecord1;

    ////////////////////////////////////////////

    Problem I am facing now is--In the column "Current" , if you see, the data is "18580". During debugging, I see no change in value for "bItems" . In  addition, the program does not execute this equation "rval = _IQmag(accelx,accely);" in acquire.c file.

    Hope, I am able to make you understand about the problem I am facing. Can you suggest me anything.. please

    Regards

    Rupok

  • I have also added the following line in acquire..c and USBStick.c file

    static tLogRecord1 *pRecord1;

    Thanks
  • Hello Rupol,

    Having code snippets does not help me at all. If you have the complete CCS project with instructions, I may be able to help you better. Please do expect upto week of delay as it is not easy for me to switch my test rigs.

    Regards
    Amit
  • Hi Amit

    I managed to solve that problem. Thanks for your time.

    I need another suggestion. Can you please tell me, how can I get the velocity from acceleration. What would be the suitable formula? I know the basic one like:

    V = Vo + a * t ; where Vo: initial velocity, a: acceleration,t: time

  • Hello Mohammed,

    You can measure time using timer ticks.e.g periodic SysTick timer counts. At every instant of the tick you start Vo(n-1) at N-1 time to calculate Vo(n). The base assumption would be that Vo at time =T=0 is 0. So some sort of output to the user to be at rest to calibrate the application. Once 0 has been established then the user can start the use of sensors.

    Regards
    Amit
  • Thank you ...I will give a try and let you know... whats going on..
  • Hi Amit

    After few search and study, so far I understand that  as we are getting acceleration in real time hence I don't think,  I need to multiply time each time with acceleration. So the formula could be:       

    V(Present velocity) = V0 (past velocity) + acceleration

    I am trying to implement this formula...but I am facing some problem is the addition is not done accurately instead the the output is multiplied by 10 with acceleration..  V0 may be taking some arbitrary value . I have initialized  both variable to zero at the top acquire.c file.

             V = V0 + accel_x;
             V  = V0;  // Present velocity becomes past velocity for later calculation    
            pRecord->sItems[uItemIdx++] =(short) V;

    The output is--

    AccelX AccelY AccelZ Ext. Temp.
    (g) (g) (g) (C)
    0.42 -0.01 0.42 4.2
    0.4 0 0.4 4
    0.39 -0.02 0.39 3.9
    0.41 -0.01 0.41 4.1
    0.39 0 0.39 3.9
    0.4 -0.01 0.4 4
    0.39 -0.02 0.39 3.9
    0.4 0 0.4 4
    0.39 -0.03 0.39 3.9
    0.41 -0.02 0.41 4.1
    0.39 -0.02 0.39 3.9
    0.43 0 0.43

    4.3

    Here, Z-Axis is Z = sqrt (x^2+y^2), and Ext-temp is showing this--- V = V0+ accel_z    ;  which is nor correct. It is just multiplying the Z column value by 10.

    As you suggested earlier ""At every instant of the tick you start Vo(n-1) at N-1 time to calculate Vo(n). The base assumption would be that Vo at time =T=0 is 0.""

    can you please tell me how can I do this?

    Thanks in advance.

  • Hello Rupok,

    You need to multiply delta of the time other wise the units will not match m/s for velocity v/s m/sec2. At time 0 send a message to the user to stop the system, so that V is 0 when t is 0. Once done ensure that for every time unit the accel value is received and then velocity computed. The time unit must be a fixed time unit or atleast a unit that can be determined. Once the initial values are known then only value that changes is accel, with Vn-1 known at every Nth time step.

    Regards
    Amit
  • can you please give an example of--How to multiply the delta time and how to set V0 = 0 when t = 0
    I have select 1/32 samples in qs-logger.

    Thnaks in advance
  • Hello Rupok,

    E.g. with SysTick timer. Set the timer for 100ms. When the accel=0, set a variable for time equvialent as 0. At this point the V0 is 0. Now use this as the base reference for further computations. So that when N=1, then t=100ms and V1=V0+100ms*Accel. When N=2, then
    V2=V1+100ms*2*Accel and so on.

    Regards
    Amit
  • Hi Amit


    Now I am facing this problem during debugging. If I move the board to get velocity the program stops here.......

    //*****************************************************************************
    //
    // This is the code that gets called when the processor receives a fault
    // interrupt.  This simply enters an infinite loop, preserving the system state
    // for examination by a debugger.
    //
    //*****************************************************************************
    static void
    FaultISR(void)
    {
        //
        // Enter an infinite loop.
        //
        while(1)
        {
        }
    }

    ..........................................

    I have changed the CLOCK_RATE from 100 to 10000 which is defined at qs-logger.c file but still this is happening.

    please give me some suggestion

  • Hello Rupok,

    You need to check the NVIC_FAULTSTAT and NVIC_FAULTADDR to identify the cause of the fault. There is an application note on www.ti.com TM4C12x web page which does a good job in describing the cause of the faults and what to look for.

    Regards
    Amit