Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem dspmodified mbed
Diff: merged_code.cpp
- Revision:
- 18:4e3aa33674c8
- Parent:
- 17:824537d9204b
- Child:
- 20:764af4c48cf2
diff -r 824537d9204b -r 4e3aa33674c8 merged_code.cpp
--- a/merged_code.cpp Tue Jun 23 11:24:06 2015 +0000
+++ b/merged_code.cpp Tue Jun 23 12:17:18 2015 +0000
@@ -69,6 +69,8 @@
unsigned short DC_Detect_data[10];
unsigned short Temp_data[10];
uint32_t dataLength = dur_sec*freq*1000;
+int avg_dc_detect[2];
+int avg_temp[2];
//--------------------------------------------------------------------------------------------------//
// Module reset //
@@ -204,9 +206,9 @@
}
//--------------------------------------------------------------------------------------------------//
-// DC Detect //
+// DC & Temp Detect //
//--------------------------------------------------------------------------------------------------//
-void DC_Detection()
+void DC_TC_Detection(short int k) //k limited by array size of avg_dc_detect & avg_temp
{
Timer t;
int j=0;
@@ -224,6 +226,15 @@
t.stop();
//pc.printf("\r\nTemp Time Taken %f \n\r", t.read());
t.reset();
+ avg_dc_detect[k]=0;
+ avg_temp[k]=0;
+ for(int i=0; i<10; i++)
+ {
+ avg_dc_detect[k]=avg_dc_detect[k]+int(DC_Detect_data[i]);
+ avg_temp[k]=avg_temp[k]+int(Temp_data[i]);
+ }
+ avg_dc_detect[k]=avg_dc_detect[k]/10;
+ avg_temp[k]=avg_temp[k]/10;
// pc.printf("Total Samples %d\r\n",j);
}
@@ -258,8 +269,9 @@
void sampling()
{
pc.printf("\r\nSampling attempt");
+ DC_TC_Detection(0);
calculate_ADC();
- DC_Detection();
+ DC_TC_Detection(1);
}
//--------------------------------------------------------------------------------------------------//
// FFT Function //
@@ -485,14 +497,7 @@
fclose(fp);
}
*/
- int avg_dc_detect=0, avg_temp=0;
- for(int i=0; i<10; i++)
- {
- avg_dc_detect=avg_dc_detect+int(DC_Detect_data[i]);
- avg_temp=avg_temp+int(Temp_data[i]);
- }
- avg_dc_detect=avg_dc_detect/10;
- avg_temp=avg_temp/10;
+
//FFT starts
//pc.printf("\r\nfftstart");
//pc.printf("\r\nfftstage1");
@@ -524,7 +529,7 @@
{
AC_rms_value=AC_rms_value+((AC_mean_value-fft_array[i])*(AC_mean_value-fft_array[i])/10000);
}
-
+//FFT file write
fp = fopen(pathfft, "w");
//pc.printf("\r\nopened path fft\r\n");
if(fp == NULL)
@@ -535,8 +540,10 @@
else
{
fprintf(fp, "%s",time_stamp);
- fprintf(fp, " %d",avg_dc_detect);
- fprintf(fp, " %d",avg_temp);
+ fprintf(fp, " %d",avg_dc_detect[0]);
+ fprintf(fp, " %d",avg_dc_detect[1]);
+ fprintf(fp, " %d",avg_temp[0]);
+ fprintf(fp, " %d",avg_temp[1]);
fprintf(fp, " %.0f",AC_rms_value);
fclose(fp);
}
@@ -569,7 +576,7 @@
}
else
{
- fprintf(fp13,"\r\n%02d%02d %d %.0f %d",minute,second,avg_dc_detect/100,AC_rms_value/100000,maxfreq);
+ fprintf(fp13,"\r\n%02d%02d %d %.0f %d",minute,second,avg_dc_detect[1]/100,AC_rms_value/100000,maxfreq); //Rushabh: avg_dc_detect[2] missing, need to accomodate
//pc.printf("Value is \r\n%02d%02d %d %.0f %d",minute,second,avg_dc_detect,AC_rms_value,maxfreq);
fclose(fp13);
}