Dependencies:   mbed-dsp mbed

Fork of DSP_200kHz by Mazzeo Research Group

Revision:
41:3e0623d81b9a
Parent:
40:bd6d8c35e822
Child:
42:52a92a8d2cc7
--- a/adc.cpp	Fri Jan 30 06:16:39 2015 +0000
+++ b/adc.cpp	Fri Jan 30 06:59:19 2015 +0000
@@ -4,15 +4,12 @@
 DigitalOut blah(LED_BLUE);
 DigitalOut toggle(PTC16);
 
-void analog_initialization(PinName pin, Serial &pc)
+void adc_init(PinName pin)
 {
-    
-    
     // Turn on the ADC0 and ADC1 clocks
     SIM_SCGC6 |= SIM_SCGC6_ADC0_MASK;
     SIM_SCGC3 |= SIM_SCGC3_ADC1_MASK;
-    
-    
+       
     /*
     // Configure System Integration Module for defaults as far as ADC
     SIM_SOPT7 &= ~(SIM_SOPT7_ADC1ALTTRGEN_MASK  | // selects PDB not ALT trigger
@@ -25,14 +22,15 @@
     
     // enable interrupt
     ADC0_SC1A |= ADC_SC1_AIEN_MASK;
+    ADC1_SC1A |= ADC_SC1_AIEN_MASK;
     
     // enable the DMA
     ADC0->SC2 |= ADC_SC2_DMAEN_MASK;
-    //ADC1->SC2 |= ADC_SC2_DMAEN_MASK;
+    ADC1->SC2 |= ADC_SC2_DMAEN_MASK;
     
     // calibrate ADC
     ADC0->SC3 = 0; // Reset SC3
-    //ADC1->SC3 = 0; // Reset SC3
+    ADC1->SC3 = 0; // Reset SC3
     /*do {
         ADC0->SC3 |= (1<<7); // start calibration
         while(ADC0->SC3&(1<<7)) {} // wait for calibration to complete
@@ -41,6 +39,7 @@
     */ // the calibration may be failing because ADC0_SC2 has the Vref set to external pins
     
     ADC0->CFG1 |= ADC_CFG1_ADLPC_MASK; // high power mode for faster frequencies
+    ADC1->CFG1 |= ADC_CFG1_ADLPC_MASK; // high power mode for faster frequencies
     
     ADCName adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
     uint32_t instance = adc >> ADC_INSTANCE_SHIFT;
@@ -67,7 +66,7 @@
     adc_hal_set_group_mux(instance, kAdcChannelMuxB); // only B channels are avail 
 
     pinmap_pinout(pin, PinMap_ADC);
-    
+    /*
     pc.printf("ADC0_SC1a: %08x\r\n",ADC0_SC1A); // module disabled
     pc.printf("ADC0_SC1b: %08x\r\n",ADC0_SC1B); // module disabled
     pc.printf("ADC0_CFG1: %08x\r\n",ADC0_CFG1); // alternate clock2 selected, 16-bit 2's complement selected, short sample time, clock divide ration is input/8, low power mode selected
@@ -76,29 +75,35 @@
     pc.printf("ADC0_RB:   %08x\r\n",ADC0_RB);
     pc.printf("ADC0_SC2:  %08x\r\n",ADC0_SC2); // hw trigger and dma enabled.  Compare function disabled and Vref set to external pin
     pc.printf("ADC0_SC3:  %08x\r\n\n",ADC0_SC3);
-    
+    */
     // Enable the ISR vector
-    NVIC_SetVector (ADC0_IRQn, (uint32_t)&ADC0_IRQHandler);
+    NVIC_SetVector(ADC0_IRQn, (uint32_t)&ADC0_IRQHandler);
+    NVIC_SetVector(ADC1_IRQn, (uint32_t)&ADC1_IRQHandler);
     NVIC_EnableIRQ(ADC0_IRQn);
+    NVIC_EnableIRQ(ADC1_IRQn);
 }
 
-void start_adc() {
+void adc_start() {
     // reset DMA
-    //reset_dma();
-    dma_init(100);
+    //_dma.reset();
     
     // set ADC to continuous mode
     ADC0_SC3 |= ADC_SC3_ADCO_MASK;
+    ADC1_SC3 |= ADC_SC3_ADCO_MASK;
     
     // start ADC conversion (SW trigger)
     BW_ADC_SC1n_ADCH(0, 0, kAdcChannel12);      // This corresponds to starting an ADC conversion on channel 12 of ADC 0 - which is A0 (PTB2)
-    //BW_ADC_SC1n_ADCH(1, 0, kAdcChannel14);      // This corresponds to starting an ADC conversion on channel 14 of ADC 1 - which is A2 (PTB10)
+    BW_ADC_SC1n_ADCH(1, 0, kAdcChannel14);      // This corresponds to starting an ADC conversion on channel 14 of ADC 1 - which is A2 (PTB10)
 }
 
-void stop_adc() {
+void adc_stop() {
     ADC0_SC3 &= ~ADC_SC3_ADCO_MASK; // set to single conversion mode effectively stopping the ADC
+    ADC1_SC3 &= ~ADC_SC3_ADCO_MASK; // set to single conversion mode effectively stopping the ADC
 }
 
 void ADC0_IRQHandler() {
-    blah = !blah;
+    //toggle = !toggle;
+}
+void ADC1_IRQHandler() {
+    //toggle = !toggle;
 }
\ No newline at end of file