LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble with array calculation with CVI

Hello world, after some year I use  CVI, what is happening to me is truly incredible. I have put here a function recalled from my main program through a timer that it ticks every tenth of second: its scope is that one to acquire data in an array in order to mediate them (draft in reality of pseudo code in order not to weight down the reading).

int CVICALLBACK TimerGlobale (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
    int i;
    switch (event)
        {
        case EVENT_TIMER_TICK:
            if (++counter_array >= DIMENSION_ARRAYI) counter_array = 0;
            for (i=CH_TEMPERATURE_1; i<=LAST_CHANNEL; i++)
                {
                VReadChannel (card_num, i, &data [i] [counter_array]);
                data [i] [counter_array] = parameter [2*i] *CALCULATE_TEMPERATURE (data [i] [counter_array]) +parameter [2*i+1];
                Mean (data [i], DIMENSION_ARRAY, &mean [i]);
                }
        break;
        }
    return 0;
}

I have put in boldface the indicted line. The variable Array parameter contains the parameters of the line of calibration of several channels, while macro CALCULATE_TEMPERATURE only serves in order to transform the volt from the acquisition function in effective the centigrade degrees. I have tried to put in the watch window the entire expression and the single data of the operation and obtain paradoxical situations of the type:
parameter [2*i] = 1.042
CALCULATE_TEMPERATURE (data [i] [counter_array]) = 10.6
parameter [2*i+1] = -3.019
data [i] [counter] = 9.11
while the result of the operation is approximately 8.02!!!!
The thing still more amazing is that this anomaly is only introduced for i=0…. Someone knows to help me?
Thanks
Regards
Andrea
0 Kudos
Message 1 of 4
(3,314 Views)
Hi, the sample values that you gave seem to give the correct result based on your code.  What were you expecting the result to be?

It looks like you are computing a running average.  Maybe the problem is that you are averaging over the entire length of the array for every element of the array when you should probably just be computing the mean over the amount of array elements you've collected.

Mean (data [i], DIMENSION_ARRAY, &mean [i]);

maybe should be

Mean (data [i], i+1, &mean [i]);


Message Edited by MattZ on 04-27-2007 03:05 AM

0 Kudos
Message 2 of 4
(3,311 Views)

Hi MattZ, I've experienced the same result with single data, instead of an average. The result I expect is 8.02

The day after I posted this message, I solved the problem by putting a dummy variable before the bolded line in which I charged the value of the macro CALCULATE_TEMPERATURE(x): in this way all work fine, but I did not understood why. Can anyone help me?

 

Thanks

 

Andrea

0 Kudos
Message 3 of 4
(3,264 Views)
Must be an order of operation problem.
0 Kudos
Message 4 of 4
(3,240 Views)