We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I want to pass a 2-D array from one function to another function. I wrote the program but sometimes i get wrong values.
float Arr[81][10];
void Monitor_Slot1(void) { if(Slot_1 == 0) { Dev_Curr = fNewVREF_1 / Res; DevCurr_MinLimit = Dev_Curr - PassBand; DevCurr_MaxLimit = Dev_Curr + PassBand; //ROUTINE TO CHECK THE DEVICE VOLTAGE for(r=1;r<=20;r++) { fMonDevVol = 0.0; fMonDevVol = fReadVoltage(r); Arr[r][s] = fMonDevVol; if(s > 9) { s = 0; flt_Average(Arr); } Delay(100); } } }
void flt_Average(float arr[][10]) { unsigned int u_min,u_max; unsigned int u,v; average = 0.0; Ave[0] = 0.0; if(Slot_1 == 0) {u_min = 1; u_max = 20;} if(Slot_2 == 0) {u_min = 21; u_max = 40;} if(Slot_3 == 0) {u_min = 41; u_max = 60;} if(Slot_4 == 0) {u_min = 61; u_max = 80;} for(u=u_min;u<=u_max;u++) { for(v=0;v<10;v++) { average += arr[u][v]; } average /= 10; Ave[u] = average; if((u >= 61) && (u <= 80)) { SBUF= ' '; printf("\n aver is %1.2f",Ave[u]); TI = 0; Delay(1000); SBUF=' '; printf("\n u is %d",u); TI = 0; Delay(1000); } average = 0.0; DevVol_Check(Ave,u); } return; }
In the function Monitor_Slot1(void) i am taking 10 sets of reading for each device. The total devices are 80.
After the 10 readings are taken i calculate the average of the readings. That is done in the second function flt_average().
For example let us assume that device number i.e 'i' is 5 and 10.
When i check the reading of this number it is correct.
But after passing to the flt_average function the average is showing either '0' or garbage number.
I dont know whether the method i followed for storing the number is correct and alos the way i passed an 2-D array is correct or not.
If this method is worng is there any other better method to do it?
Please suggest me.