Dependencies:   mbed-dsp mbed

Fork of DSP_200kHz by Mazzeo Research Group

Revision:
36:07d8a3143967
Parent:
35:df40c4566826
Child:
37:8bdc71f3e874
--- a/main.cpp	Sun Jan 25 06:32:11 2015 +0000
+++ b/main.cpp	Sun Jan 25 09:10:24 2015 +0000
@@ -14,8 +14,8 @@
 
 // Analog sampling
 #define MAX_FADC 6000000
-#define SAMPLING_RATE       1000000 // In microseconds, so 10 us will be a sampling rate of 100 kHz
-#define TOTAL_SAMPLES       5 // originally 30000 for 0.3 ms of sampling.
+#define SAMPLING_RATE       10 // In microseconds, so 10 us will be a sampling rate of 100 kHz
+#define TOTAL_SAMPLES       3 // originally 30000 for 0.3 ms of sampling.
 
 #define LAST_SAMPLE_INDEX   (TOTAL_SAMPLES-1) // If sampling time is 25 us, then 2000 corresponds to 50 ms
 #define FIRST_SAMPLE_INDEX  0
@@ -66,17 +66,18 @@
     analog_initialization(A0);
     analog_initialization(A2);
     
-    ADC0->SC2 |= ADC_SC2_DMAEN_MASK;    // DMA Enable
-    
+    // enable the DMA
+    ADC0->SC2 |= ADC_SC2_DMAEN_MASK;
+    ADC1->SC2 |= ADC_SC2_DMAEN_MASK;
     ADC0->SC3 = 0; // Reset SC3
+    ADC1->SC3 = 0; // Reset SC3
     
-    dma_init(sample_array1,TOTAL_SAMPLES);
+    dma_init(sample_array1, sample_array2, angle_array, TOTAL_SAMPLES);
     pc.printf("SampleArr: %08x\r\n", &sample_array1);
     uint16_t* dma_csr = (uint16_t*) 0x4000901C;
     uint32_t* dma_daddr = (uint32_t*) 0x40009010;
     *dma_csr |= 1;
     
-    
     // Start the sampling loop
     current_sample_index = WAITING_TO_BEGIN;
     Sampler.attach_us(&timed_sampling, SAMPLING_RATE);
@@ -84,12 +85,14 @@
     pc.printf("\r\n\r\n\r\n");
     
     while(1) {
+        rotary_count++;
         if(pc.readable() > 0) {
             char temp = pc.getc();
             
             switch(temp) {
                 case 's':
                     for(int i = 0; i < TOTAL_SAMPLES; i++) pc.printf("%i: %f\t",i,sample_array1[i]*3.3/65535);
+                    
                     pc.printf("\r\n");
                     break;
                 case 'f':
@@ -98,7 +101,9 @@
                     
             }
         }
-        for(int i = 0; i < TOTAL_SAMPLES; i++) pc.printf("%i: %f  ",i,sample_array1[i]*3.3/65535);
+        for(int i = 0; i < TOTAL_SAMPLES; i++) pc.printf("A%i: %f  ",i,sample_array1[i]*3.3/65535);
+        for(int i = 0; i < TOTAL_SAMPLES; i++) pc.printf("B%i: %f  ",i,sample_array2[i]*3.3/65535);
+        for(int i = 0; i < TOTAL_SAMPLES; i++) pc.printf("C%i: %i  ",i,angle_array[i]);
         pc.printf("\r");
         //pc.printf("DMA_DADDR: %08x                  \r", *dma_daddr);
         //pc.printf("A1: %f\tA2: %f\r\n", currA0, currA2);
@@ -127,7 +132,7 @@
     /*
     currA0 = (float) A0_value*3.3/65535;
     currA2 = (float) A2_value*3.3/65535;
-    
+    */
     
     // The following updates the rotary counter for the AMT20 sensor
     // Put A on PTC0
@@ -149,6 +154,7 @@
         
         last_AMT20_AB_read = AMT20_AB;        
     }
+    /*
     //current_sample_index = BEGIN_SAMPLING; // Used to force extra time.
     if (current_sample_index == WAITING_TO_BEGIN) {}
     else