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.
Fork of Impedance_Fast_Circuitry by
Diff: main.cpp
- Revision:
- 35:df40c4566826
- Parent:
- 34:44cc9b76a507
- Child:
- 36:07d8a3143967
--- a/main.cpp Sun Jan 25 02:45:58 2015 +0000 +++ b/main.cpp Sun Jan 25 06:32:11 2015 +0000 @@ -14,8 +14,8 @@ // Analog sampling #define MAX_FADC 6000000 -#define SAMPLING_RATE 1000 // In microseconds, so 10 us will be a sampling rate of 100 kHz -#define TOTAL_SAMPLES 10 // originally 30000 for 0.3 ms of sampling. +#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 LAST_SAMPLE_INDEX (TOTAL_SAMPLES-1) // If sampling time is 25 us, then 2000 corresponds to 50 ms #define FIRST_SAMPLE_INDEX 0 @@ -57,7 +57,7 @@ int main() { led_blue = 1; - led_green = 0; + led_green = 1; led_red = 1; pc.baud(230400); @@ -66,19 +66,31 @@ analog_initialization(A0); analog_initialization(A2); + ADC0->SC2 |= ADC_SC2_DMAEN_MASK; // DMA Enable + + ADC0->SC3 = 0; // Reset SC3 + dma_init(sample_array1,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); + pc.printf("\r\n\r\n\r\n"); + while(1) { if(pc.readable() > 0) { char temp = pc.getc(); switch(temp) { case 's': - for(int i = 0; i < TOTAL_SAMPLES; i++) pc.printf("%i: ",i,sample_array1[i]); + 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': for(int i = 0; i < TOTAL_SAMPLES; i++) sample_array1[i] = 0; @@ -86,7 +98,10 @@ } } - pc.printf("A1: %f\tA2: %f\r\n", currA0, currA2); + for(int i = 0; i < TOTAL_SAMPLES; i++) pc.printf("%i: %f ",i,sample_array1[i]*3.3/65535); + pc.printf("\r"); + //pc.printf("DMA_DADDR: %08x \r", *dma_daddr); + //pc.printf("A1: %f\tA2: %f\r\n", currA0, currA2); wait(1); } @@ -94,23 +109,30 @@ } void timed_sampling() { - __disable_irq(); // Disable Interrupts + + // Write to SC1A to start conversion with channel 12 PTB2 + //ADC0_SC1A = (ADC_SC1_ADCH(ADC_CHANNEL) | (ADC0_SC1A & (ADC_SC1_AIEN_MASK | ADC_SC1_DIFF_MASK))); + + //__disable_irq(); // Disable Interrupts // The following performs analog-to-digital conversions - first reading the last conversion - then initiating another - uint32_t A0_value = adc_hal_get_conversion_value(0, 0); - uint32_t A2_value = adc_hal_get_conversion_value(1, 0); + //uint32_t A0_value = adc_hal_get_conversion_value(0, 0); // ADC0_RA + //uint32_t A2_value = adc_hal_get_conversion_value(1, 0); + + 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) + /* 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 // Put B on PTC1 uint32_t AMT20_AB = HW_GPIO_PDIR_RD(HW_PORTC) & 0x03; - //AMT20_AB = ~last_AMT20_AB_read; // Used to force a count - extend time. if (AMT20_AB != last_AMT20_AB_read) { // change "INVERT_ANGLE" to change whether relative angle counts up or down. @@ -144,8 +166,8 @@ } else { current_sample_index++; } } - - __enable_irq(); // Enable Interrupts + */ + //__enable_irq(); // Enable Interrupts } void analog_initialization(PinName pin) @@ -179,4 +201,49 @@ adc_hal_set_group_mux(instance, kAdcChannelMuxB); // only B channels are avail pinmap_pinout(pin, PinMap_ADC); -} \ No newline at end of file +} + + + +/* + // read some registers for some info. + uint32_t* dma_cr = (uint32_t*) 0x40008000; + pc.printf("DMA_CR: %08x\r\n", *dma_cr); + + uint32_t* dma_eei = (uint32_t*) 0x40008014; + pc.printf("DMA_EEI: %08x\r\n", *dma_eei); + + uint32_t* dma_erq = (uint32_t*) 0x4000800C; + pc.printf("DMA_ERQ: %08x\r\n", *dma_erq); + + uint16_t* dma_csr = (uint16_t*) 0x4000901C; + pc.printf("DMA_TD0_CSR: %04x\r\n\n", *dma_csr); + + uint32_t* dma_saddr = (uint32_t*) 0x40009000; + pc.printf("DMA_SAADR: %08x\r\n", *dma_saddr); + + uint16_t* dma_soff = (uint16_t*) 0x40009004; + pc.printf("DMA_SOFF: %04x\r\n", *dma_soff); + + uint16_t* dma_attr = (uint16_t*) 0x40009006; + pc.printf("DMA_ATTR: %04x\r\n", *dma_attr); + + uint32_t* dma_minor = (uint32_t*) 0x40009008; + pc.printf("DMA_MINOR: %08x\r\n", *dma_minor); + + uint32_t* dma_daddr = (uint32_t*) 0x40009010; + pc.printf("DMA_DADDR: %08x\r\n", *dma_daddr); + + + // read some registers for some info. + pc.printf("DMA_CR: %08x\r\n", *dma_cr); + pc.printf("DMA_EEI: %08x\r\n", *dma_eei); + pc.printf("DMA_ERQ: %08x\r\n", *dma_erq); + pc.printf("DMA_TD0_CSR: %04x\r\n\n", *dma_csr); + pc.printf("DMA_SAADR: %08x\r\n", *dma_saddr); + pc.printf("DMA_SOFF: %04x\r\n", *dma_soff); + pc.printf("DMA_ATTR: %04x\r\n", *dma_attr); + pc.printf("DMA_MINOR: %08x\r\n", *dma_minor); + pc.printf("DMA_DADDR: %08x\r\n", *dma_daddr); + pc.printf("SampleArr: %08x\r\n",&sample_array1); +*/ \ No newline at end of file