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.
Dependencies: mbed
Fork of Chemical_Sensor_DMA by
Diff: main.cpp
- Revision:
- 6:63de50ac29be
- Parent:
- 5:1b2dc43e8947
- Child:
- 7:af255a90505e
--- a/main.cpp Fri Nov 06 19:28:49 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -#include "mbed.h" -#include "pause.cpp" -#include "Sample/adc.h" -#include "Sample/pdb.h" -#include "SignalProcessing.h" -// for debug purposes -Serial pc(USBTX, USBRX); -DigitalOut led_red(LED_RED); -DigitalOut led_green(LED_GREEN); -DigitalOut led_blue(LED_BLUE); - -Timer t1; -using namespace std; - - - - -#define PDB_DACINTC0_TOE 0x01 // 0x01 -> PDB DAC interal trigger enabled - -#define DAC0_DAT0 (uint16_t *)0x400CC000 // DAC word buffer base address - -uint16_t *p1; -void setUpDac() -{ - SIM_SCGC2 |= SIM_SCGC2_DAC0_MASK; // turn on clock to the DAC - SIM_SCGC6 |= SIM_SCGC6_DAC0_MASK; // turn on clock to the DAC - DAC0_C0 |= DAC_C0_DACEN_MASK ; // enable the DAC; must do before any of the following - DAC0_C2 =9;//cycle through the first 10 values in the buffer - DAC0_C1 = 1;//enable the dac buffer - p1 = DAC0_DAT0; - for (int i = 0; i < 16; i++)//fill the buffer - { - *p1++ = (uint16_t) (cos(3.14159265359 * 2 * 10000 * .00001 * i) * 460.0 + 2870.0); // 3351.0 - //printf("Pointer: %d\tValue: %d\n\r", (uint32_t)p1,(int) (cos(3.14159265359 * 2 * 10000 * .00001 * i) * 800.0 + 3103.0)); - } - -} - -int main() -{ - - led_blue = 1; - led_green = 1; - led_red = 1; - pre_compute_tables(); - - -// t1.reset(); -// for (int t = 0; t<500000; t++) -// { -// int input1 = 5000*cos(3.14159265359 * 2*10000*t*.00001)+2500; -// int input2 = 2500*sin(3.14159265359 * 2*10000*t*.00001)+2500; -// t1.start(); -// filter100K(input1, input2); -// t1.stop(); -// } -// printf("FINAL TIME: %f\n\r",t1.read()); - - pc.printf("Starting...\r\n"); - for(int i = 0; i < 86; i++) - { - if(NVIC_GetPriority((IRQn_Type) i) == 0) NVIC_SetPriority((IRQn_Type) i, 2); - } - - // Give hardware associated with - // sampling the highest priority - NVIC_SetPriority(ADC1_IRQn,0); - NVIC_SetPriority(ADC0_IRQn,0); - NVIC_SetPriority(PDB0_IRQn,0); - NVIC_SetPriority(DMA0_IRQn,0); - NVIC_SetPriority(DMA1_IRQn,0); - NVIC_SetPriority(DMA2_IRQn,0); - - NVIC_SetPriority(ENET_1588_Timer_IRQn,1); - NVIC_SetPriority(ENET_Transmit_IRQn,1); - NVIC_SetPriority(ENET_Receive_IRQn,1); - NVIC_SetPriority(ENET_Error_IRQn,1); - - adc_init(); // initialize ADCs (always initialize adc before dma) - setUpDac(); - dma_init(); // initializes DMAs - pdb_init(); // initialize PDB0 as the timer for ADCs and DMA2 - - // flash green led indicating startup complete - led_red = 1; - led_blue = 1; - led_green = 0; - pause_ms(500); - led_green = 1; - pause_ms(200); - led_green = 0; - pause_ms(500); - led_green = 1; - pdb_start(); - int startAddress = (int)&sample_array0[0]; - int destinationIndex = (DMA_TCD0_DADDR-startAddress)/2; - int currentIndex; - while (1) - { - - - destinationIndex = (DMA_TCD0_DADDR-startAddress)/2;//-1; - //if (destinationIndex<0) - // destinationIndex = 1999; - while (currentIndex!=destinationIndex) - { - filter100K(sample_array0[currentIndex], sample_array1[currentIndex]); - currentIndex++; - if (currentIndex>=2000) - currentIndex = 0; - - } - - } - - -}