Jared Baxter / Mbed 2 deprecated Impedance_Fast_Circuitry_print_V_I

Dependencies:   mbed-dsp mbed

Fork of Impedance_Fast_Circuitry by Jared Baxter

Revision:
51:43143a3fc2d7
Parent:
50:33524a27e08c
--- a/adc.cpp	Sat Jan 31 19:46:00 2015 +0000
+++ b/adc.cpp	Sat Jan 31 20:17:58 2015 +0000
@@ -14,11 +14,16 @@
         single vs continuous mode
         does asynchronous clock have to do with this?
 */
-DigitalOut toggle1(PTC16);
+DigitalOut toggle1(PTA0);
 DigitalOut green(LED_GREEN);
 DigitalOut red(LED_RED);
-Serial debug(USBTX,USBRX);
+//Serial debug(USBTX,USBRX);
+
+
 
+/* The ADCs are setup so that ADC0 and ADC1 are triggered by the PDB.
+ * When the conversions are complete, ADC0 and ADC1 then trigger DMA0
+ * and DMA1, respectively.                                         */
 void adc_init()
 {
     // red, indicating now ready
@@ -32,7 +37,6 @@
     // Set ADC hardware trigger to PDB0
     SIM_SOPT7 = SIM_SOPT7_ADC0TRGSEL(0); // Select triggering by PDB and select pre-trigger A
     SIM_SOPT7 = SIM_SOPT7_ADC1TRGSEL(0); // Select triggering by PDB and select pre-trigger A
-    debug.printf("SIM_SOPT7: 0x%08x\r\n",SIM_SOPT7); //(0x00000000)
     
     // Setup Configuration Register 1 
     ADC0_CFG1 = 0; // clear register
@@ -123,7 +127,8 @@
     ADC1_SC1A = 0; // clear register
     ADC1_SC1A &= ~ADC_SC1_DIFF_MASK; // select single-ended mode
     ADC1_SC1A |= ADC_SC1_AIEN_MASK;  // enable interrupt (for debugging)
-    ADC1_SC1A |= ADC_SC1_ADCH(14);   // select channel 13
+    ADC1_SC1A |= ADC_SC1_ADCH(14);   // select channel 14
+    
     
     // Check if ADC is finished initializing  TODO:  This part doesn't seem right, but I did it according to 871
     while( (ADC0_SC1B&ADC_SC1_COCO_MASK)) {}
@@ -136,22 +141,25 @@
     red = 1;
     green = 0;
     
-    /*
-    debug.printf("ADC0_SC1a: %08x\r\n",ADC0_SC1A);  //(0x0000004d)
-    debug.printf("ADC0_SC1b: %08x\r\n",ADC0_SC1B);  //(0x0000001f)
-    debug.printf("ADC0_CFG1: %08x\r\n",ADC0_CFG1);  //(0x0000000c)
-    debug.printf("ADC0_CFG2: %08x\r\n",ADC0_CFG2);  //(0x00000004)
-    debug.printf("ADC0_RA:   %08x\r\n",ADC0_RA);    //(0x00000000)
-    debug.printf("ADC0_RB:   %08x\r\n",ADC0_RB);    //(0x00000000)
-    debug.printf("ADC0_SC2:  %08x\r\n",ADC0_SC2);   //(0x00000044)
-    debug.printf("ADC0_SC3:  %08x\r\n\n",ADC0_SC3); //(0x00000000)
-    */
-    
     // Enable the ISR vector
     //NVIC_SetVector(ADC0_IRQn, (uint32_t)&ADC0_IRQHandler);
     //NVIC_EnableIRQ(ADC0_IRQn);
 }
 
+
+void ADC0_IRQHandler() {
+    
+    toggle1 = !toggle1;
+}
+
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
+ * DEBUG:  This is supposed to put the ADC in continuous     *
+ *         mode so it samples without the PCB.  But for      *
+ *         some reason it isn't working.  I haven't deleted  *
+ *         it just in case it is needed for debug purposes   *
+ *         in the future.                                    *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 void adc_start() {
     // reset DMA
     dma_reset();
@@ -169,6 +177,13 @@
     ADC1_SC1A |= ADC_SC1_ADCH(14);   // write to SC1A causing a trigger
 }
 
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
+ * DEBUG:  This is supposed to revert back from adc_start()  *
+ *         but because adc_start() isn't working, this       *
+ *         function is good for nothing.  I held on to       *
+ *         it just in case it is needed for debug purposes   *
+ *         in the future.                                    *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 void adc_stop() {
     // set ADC to hardware trigger
     ADC0_SC2 |= ADC_SC2_ADTRG_MASK;
@@ -179,7 +194,12 @@
     ADC1_SC3 &= ~ADC_SC3_ADCO_MASK; 
 }
 
-// DEBUG: this function causes the continuous sampling to break
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
+ * DEBUG:  This is supposed to trigger a software conversion *
+ *         and take a single sample.  However, it only       *
+ *         worked for ADC1 for some reason.  It is here for  *
+ *         possible debug purposes in the future.            *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 void adc_single_sample() {
     ADC0_SC3 &= ~ADC_SC3_ADCO_MASK;  // single conversion mode
     ADC1_SC3 &= ~ADC_SC3_ADCO_MASK;  // single conversion mode
@@ -193,7 +213,14 @@
     ADC1_SC2 |= ADC_SC2_ADTRG_MASK; // set ADC to software trigger
 }
 
-void ADC0_IRQHandler() {
-    
-    toggle1 = !toggle1;
-}
\ No newline at end of file
+
+/*
+    debug.printf("ADC0_SC1a: %08x\r\n",ADC0_SC1A);  //(0x0000004d)
+    debug.printf("ADC0_SC1b: %08x\r\n",ADC0_SC1B);  //(0x0000001f)
+    debug.printf("ADC0_CFG1: %08x\r\n",ADC0_CFG1);  //(0x0000000c)
+    debug.printf("ADC0_CFG2: %08x\r\n",ADC0_CFG2);  //(0x00000004)
+    debug.printf("ADC0_RA:   %08x\r\n",ADC0_RA);    //(0x00000000)
+    debug.printf("ADC0_RB:   %08x\r\n",ADC0_RB);    //(0x00000000)
+    debug.printf("ADC0_SC2:  %08x\r\n",ADC0_SC2);   //(0x00000044)
+    debug.printf("ADC0_SC3:  %08x\r\n\n",ADC0_SC3); //(0x00000000)
+    */
\ No newline at end of file