Impedance Fast Circuitry Software

Dependencies:   mbed-dsp mbed

Fork of DSP_200kHz by Mazzeo Research Group

Revision:
84:5b4466dd2326
Parent:
80:7a4856c596fc
Child:
85:f1be018aacac
--- a/main.cpp	Thu Aug 03 17:38:02 2017 +0000
+++ b/main.cpp	Wed Feb 21 23:23:17 2018 +0000
@@ -45,10 +45,14 @@
 bool recording = false;
 
 
-
-#define pre_compute_length 500
-#define demodulation_length 125
-#define CarrierFrequency 200
+//190Hz 528
+//312Hz 320
+//431Hz 232
+//481Hz 208 
+//568Hz 176
+#define pre_compute_length 208
+//#define demodulation_length 125
+#define CarrierFrequency (100000/208)
 #define SAMPLEFREQUENCY 100000
 //float i_mod_pre[demodulation_length+(INPUT_ARRAY_SIZE/DECIMATION_FACTOR)];
 //float q_mod_pre[demodulation_length+(INPUT_ARRAY_SIZE/DECIMATION_FACTOR)];
@@ -59,7 +63,7 @@
 void pre_compute_tables() {
   // This function will precompute the cos and sin tables used in the rest of the program
   for(int precompute_counter = 0; precompute_counter < pre_compute_length; precompute_counter++){
-    out_val_pre[precompute_counter] = (int) ((cos(twopi * CarrierFrequency /SAMPLEFREQUENCY * precompute_counter)+cos(twopi * 1000 /SAMPLEFREQUENCY * precompute_counter+3.14159265359)) * 1023.0 + 2048.0);//12 bit cos wave
+    out_val_pre[precompute_counter] = (int) ((cos(twopi * CarrierFrequency /SAMPLEFREQUENCY * precompute_counter)) * 2046.0 + 2048.0);//12 bit cos wave
   }
   
   //float decimated_frequency = 6250;
@@ -84,7 +88,7 @@
     precompute_tables();
     //turn off all LEDs
     
-    
+    //slight change.
     
     
        
@@ -92,12 +96,12 @@
     
     //pc.printf("High: %x Mid: %x Low: %x",SIM->UIDH,SIM->UIDML,SIM->UIDL);
     
-    if(SIM->UIDH == 0x2effff && SIM->UIDML == 0x4e453154 && SIM->UIDL == 0x1004001e) probe_number = 1;
+    if(SIM->UIDH == 0x2effff && SIM->UIDML == 0x4e453154 && SIM->UIDL == 0x1004001e) probe_number = 6;
     else if(SIM->UIDH == 0x1cffff && SIM->UIDML == 0x4e453215 && SIM->UIDL == 0x700b0003) probe_number = 2;
     else if(SIM->UIDH == 0x2effff && SIM->UIDML == 0x4e453215 && SIM->UIDL == 0x700b0021) probe_number = 3;
     else if(SIM->UIDH == 0x14ffff && SIM->UIDML == 0x4e453154 && SIM->UIDL == 0x5009002b) probe_number = 4;
-    else if(SIM->UIDH == 0x12ffff && SIM->UIDML == 0x4e453103 && SIM->UIDL == 0x60010030) probe_number = 5;
-    else if(SIM->UIDH == 0x10ffff && SIM->UIDML == 0x4e453105 && SIM->UIDL == 0x100b0031) probe_number = 6;
+    else if(SIM->UIDH == 0x12ffff && SIM->UIDML == 0x4e453103 && SIM->UIDL == 0x60010030) probe_number = 1;
+    else if(SIM->UIDH == 0x10ffff && SIM->UIDML == 0x4e453105 && SIM->UIDL == 0x100b0031) probe_number = 5;
     else if(SIM->UIDH == 0x19ffff && SIM->UIDML == 0x4d441504 && SIM->UIDL == 0x90110031) probe_number = 7;//this FRDM board had a bad usb connection
     else
     {
@@ -139,11 +143,12 @@
     filters f2 = filters(4, 8, &f3, 8, 64, Coeffs_12500,DEMOD_No_Demod);
     filters f1 = filters(2, 8, &f2, 64, 64, Coeffs_100k,DEMOD_200HZ);
     
+    /*
     filters f4_b = filters(4, 8, NULL, 8, 32, Coeffs_782,DEMOD_No_Demod);       
     filters f3_b = filters(4, 2, &f4_b, 4, 32, Coeffs_1563,DEMOD_No_Demod);
     filters f2_b = filters(4, 8, &f3_b, 8, 64, Coeffs_12500,DEMOD_No_Demod);
     filters f1_b = filters(2, 8, &f2_b, 64, 64, Coeffs_100k,DEMOD_1000HZ); 
-    
+    */
     //filters f_pre = filters(2, 2, &f1, 64, 64, Coeffs_50k,false);
     
     //float output_print_buffer[PRINT_BUFFER_LENGTH];//used to store the adc0 values(current measurment)
@@ -163,19 +168,30 @@
     pc.printf("\r\n\r\n\r\n");
     
     pdb_start();
+    bool is_actively_printing = false;
+    char read_in_character = 'a';
     //while(print_buffer_count<PRINT_BUFFER_LENGTH) 
     while(!GATHER_STATISTICS||print_buffer_count<PRINT_BUFFER_LENGTH)
     {
         if(pc.readable())//if the python code has sent any characters recently
         {
-            while(pc.readable()){pc.getc();}
-            pc.printf("p%d",probe_number);
+            while(pc.readable())
+            {
+                read_in_character = pc.getc();
+                if (read_in_character == 'R')
+                    is_actively_printing = true;
+                else if (read_in_character == 'S')
+                    is_actively_printing = false;
+                else if (read_in_character == 'P')
+                    pc.printf("p%d",probe_number);
+            }
+            
         }
             
         while(sampling_status == 0)//wait until the ADCs read a new value
         {   
             status_0 = 1;
-            print_filter_data(&pc);
+            print_filter_data(&pc,is_actively_printing);
             //Thread::wait(.0001);
         }
         sampling_status = 0;//sets sampling status to 0.  DMA sets it to one once ADCs sample
@@ -202,7 +218,7 @@
         //input_50k[0] = static_input_array0;
         //input_50k[1] = static_input_array1;
         f1.input(input_50k,64,DEMOD_200HZ);
-        f1_b.input(input_50k,64,DEMOD_1000HZ);  
+        //f1_b.input(input_50k,64,DEMOD_1000HZ);  
         //status_3 = 1;
         //pc.printf("Y");
         //status_3 = 0;