
Impedance Fast Circuitry Software
Fork of DSP_200kHz by
Diff: main.cpp
- Revision:
- 85:f1be018aacac
- Parent:
- 84:5b4466dd2326
- Child:
- 86:b3520f4453cf
--- a/main.cpp Wed Feb 21 23:23:17 2018 +0000 +++ b/main.cpp Wed Apr 25 16:21:11 2018 +0000 @@ -10,23 +10,44 @@ #include "dsp.h" #include "print_data.h" +#define PROBE_NUMBER 5 +#if PROBE_NUMBER == 1 + #define PRE_COMPUTE_LENGTH 232 +#elif PROBE_NUMBER == 2 + #define PRE_COMPUTE_LENGTH 528 +#elif PROBE_NUMBER == 3 + #define PRE_COMPUTE_LENGTH 176 +#elif PROBE_NUMBER == 4 + #define PRE_COMPUTE_LENGTH 320 +#elif PROBE_NUMBER == 5 + #define PRE_COMPUTE_LENGTH 208 +#elif PROBE_NUMBER == 6 + #define PRE_COMPUTE_LENGTH 528 +#endif +//#define probe_number 1 //Probe number +const int probe_number = PROBE_NUMBER; +//const int PCL_LUT[] = {232,528,176,320,208}; //Pre-compute-length for the different probe numbers +//190Hz 528 +//312Hz 320 +//431Hz 232 +//481Hz 208 +//568Hz 176 + #define PRINT_BUFFER_LENGTH 10000 #define GATHER_STATISTICS 1 +Serial pc(USBTX, USBRX); // for debug purposes -DigitalOut led1(LED1); -DigitalOut led2(LED2); -Serial pc(USBTX, USBRX); DigitalOut led_red(LED_RED); DigitalOut led_green(LED_GREEN); DigitalOut led_blue(LED_BLUE); DigitalOut status_0(D0); DigitalOut status_1(D1); DigitalOut status_3(D3); -DigitalOut Start_sync(D4);// -DigitalIn sw2(SW2);//Button 2 -DigitalIn sw3(SW3);//Button 3 +DigitalOut Start_sync(D4);// Currently not being used. +DigitalIn sw2(SW2);//Button 2 Currently not being used +DigitalIn sw3(SW3);//Button 3 Currently not being used // defined in dma.cpp extern int len; @@ -35,14 +56,14 @@ extern uint16_t static_output_array0[];//DAC outputs whatever wave form we want. extern uint16_t sampling_status;//used to determine when adc's are done reading. -#define INPUT_ARRAY_SIZE 32 -#define DECIMATION_FACTOR 8 -#define DEMODULATED_SIGNAL_LENGTH 64 +//#define INPUT_ARRAY_SIZE 32 +//#define DECIMATION_FACTOR 8 +//#define DEMODULATED_SIGNAL_LENGTH 64 float *input_50k[8]; -int probe_number = -1; -bool recording = false; + + //190Hz 528 @@ -50,12 +71,12 @@ //431Hz 232 //481Hz 208 //568Hz 176 -#define pre_compute_length 208 -//#define demodulation_length 125 -#define CarrierFrequency (100000/208) +//#define pre_compute_length 208 +//#define CarrierFrequency (100000/pre_compute_length) +const int pre_compute_length = PRE_COMPUTE_LENGTH; +const float CarrierFrequency = (100000/pre_compute_length); #define SAMPLEFREQUENCY 100000 -//float i_mod_pre[demodulation_length+(INPUT_ARRAY_SIZE/DECIMATION_FACTOR)]; -//float q_mod_pre[demodulation_length+(INPUT_ARRAY_SIZE/DECIMATION_FACTOR)]; + uint16_t out_val_pre[pre_compute_length]; //used to write values to the dac float twopi = 3.14159265359 * 2; @@ -66,18 +87,10 @@ out_val_pre[precompute_counter] = (int) ((cos(twopi * CarrierFrequency /SAMPLEFREQUENCY * precompute_counter)) * 2046.0 + 2048.0);//12 bit cos wave } - //float decimated_frequency = 6250; - //for(int precompute_counter = 0; precompute_counter < demodulation_length+(INPUT_ARRAY_SIZE/DECIMATION_FACTOR); precompute_counter++){ - // i_mod_pre[precompute_counter] = (cos(twopi * CarrierFrequency / decimated_frequency * precompute_counter)); - // q_mod_pre[precompute_counter] = (-sin(twopi * CarrierFrequency / decimated_frequency * precompute_counter)); } -void callback() { - // Note: you need to actually read from the serial to clear the RX interrupt - printf("%c\n", pc.getc()); - led2 = !led2; -} + int main() { led_blue = 1; @@ -93,9 +106,8 @@ pc.baud(230400); - + /* //pc.printf("High: %x Mid: %x Low: %x",SIM->UIDH,SIM->UIDML,SIM->UIDL); - if(SIM->UIDH == 0x2effff && SIM->UIDML == 0x4e453154 && SIM->UIDL == 0x1004001e) probe_number = 6; else if(SIM->UIDH == 0x1cffff && SIM->UIDML == 0x4e453215 && SIM->UIDL == 0x700b0003) probe_number = 2; else if(SIM->UIDH == 0x2effff && SIM->UIDML == 0x4e453215 && SIM->UIDL == 0x700b0021) probe_number = 3; @@ -109,19 +121,14 @@ pc.printf("High: %x Mid: %x Low: %x\n\r",SIM->UIDH,SIM->UIDML,SIM->UIDL); probe_number = 6; } + */ pc.printf("PROBE #%d",probe_number); wait(1.0f); - /* - while(!pc.readable()) - { - continue; - } - pc.printf("%d",probe_number); - */ + int DAC_COUNTER = 0; - //SIM_UIDH == 0x20ffff && SIM_UIDML == 0x4e453103 && SIM_UIDL == 0x60010028) - //printf("High: %x Mid: %x Low: %x",SIM->UIDH,SIM->UIDML,SIM->UIDL); + + //Filters used in program. Coefficients generated using matlab FDA tool //Fs = 100000, FPass = 1500, FStop = 4500, -40db float Coeffs_100k[64] = {0.00368762746013400, -0.00390835182721185, -0.00352466159836192, -0.00378044968164769, -0.00434746630849834, -0.00502920744118478, -0.00570543677799210, -0.00628464650365093, -0.00668691824262464, -0.00683917139561193, -0.00667505410229485, -0.00613341508706847, -0.00516232410283893, -0.00371868951723358, -0.00177417571286934, 0.000685809876396031, 0.00365648516386919, 0.00711658039739992, 0.0110234409358280, 0.0153179248880130, 0.0199204447074274, 0.0247385052308702, 0.0296636617979935, 0.0345813441342327, 0.0393672306749833, 0.0438989152744108, 0.0480511039644129, 0.0517108728403463, 0.0547710075854812, 0.0571509837193129, 0.0587848911618005, 0.0596038010741317, 0.0596038010741317, 0.0587848911618005, 0.0571509837193129, 0.0547710075854812, 0.0517108728403463, 0.0480511039644129, 0.0438989152744108, 0.0393672306749833, 0.0345813441342327, 0.0296636617979935, 0.0247385052308702, 0.0199204447074274, 0.0153179248880130, 0.0110234409358280, 0.00711658039739992, 0.00365648516386919, 0.000685809876396031, -0.00177417571286934, -0.00371868951723358, -0.00516232410283893, -0.00613341508706847, -0.00667505410229485, -0.00683917139561193, -0.00668691824262464, -0.00628464650365093, -0.00570543677799210, -0.00502920744118478, -0.00434746630849834, -0.00378044968164769, -0.00352466159836192, -0.00390835182721185, 0.00368762746013400}; //FS = 12500, Fpass = 100 Fstop 595 -50 db, picks on 1KHz signal @@ -134,10 +141,16 @@ float Coeffs[20] = {0.0328368433284673, 0.0237706090075265, 0.0309894695180997, 0.0385253568846695, 0.0459996974310349, 0.0530165318016261, 0.0591943866845610, 0.0641755708098907, 0.0676960677594849, 0.0694621149975389, 0.0694621149975389, 0.0676960677594849, 0.0641755708098907, 0.0591943866845610, 0.0530165318016261, 0.0459996974310349, 0.0385253568846695, 0.0309894695180997, 0.0237706090075265, 0.0328368433284673}; float Coeffs2[20] = {-0.00506451294187997, -0.00824932319607346, -0.00986370066237912, -0.00518913235010027, 0.00950858650162284, 0.0357083149022659, 0.0711557142019980, 0.109659494661247, 0.142586101123340, 0.161603335553589, 0.161603335553589, 0.142586101123340, 0.109659494661247, 0.0711557142019980, 0.0357083149022659, 0.00950858650162284, -0.00518913235010027, -0.00986370066237912, -0.00824932319607346, -0.00506451294187997}; + //note I allocate space for 4 adc inputs, but usually I only use 2 for(int i = 0; i < 8; i++) input_50k[i] = new float[64];//each array represents the input of the adcs - + //filters(const int num_filters, const int DECIMATION, filters * f, const int block_size, const int numTaps, float coeffs[], int demodulate_after) + //num filters: usually 4. In-phase and quadrature phase for both voltage and current + //DECIMATION: Decimation Factor + //f: the filter after current filter. + //block_size: block size of each filter command should be an integer multiple of DECIMATION + //Flag noting rather or not to demodulate, and if so what frequency to demodulate at filters f4 = filters(4, 8, NULL, 8, 32, Coeffs_782,DEMOD_No_Demod); filters f3 = filters(4, 2, &f4, 4, 32, Coeffs_1563,DEMOD_No_Demod); filters f2 = filters(4, 8, &f3, 8, 64, Coeffs_12500,DEMOD_No_Demod); @@ -175,23 +188,23 @@ { if(pc.readable())//if the python code has sent any characters recently { - while(pc.readable()) + while(pc.readable())//if there is a Keyboard input { - read_in_character = pc.getc(); - if (read_in_character == 'R') + read_in_character = pc.getc();// read the keyboard input + if (read_in_character == 'R')//start printing is_actively_printing = true; - else if (read_in_character == 'S') + else if (read_in_character == 'S')//Stop printing is_actively_printing = false; - else if (read_in_character == 'P') + else if (read_in_character == 'P')//return probe number pc.printf("p%d",probe_number); } } - while(sampling_status == 0)//wait until the ADCs read a new value + while(sampling_status == 0)//wait until the ADCs read a new values { - status_0 = 1; - print_filter_data(&pc,is_actively_printing); + status_0 = 1; //used for debugging allows to see utilization + print_filter_data(&pc,is_actively_printing);//while waiting for new samples print as much data as possible //Thread::wait(.0001); } sampling_status = 0;//sets sampling status to 0. DMA sets it to one once ADCs sample @@ -207,16 +220,15 @@ //DAC_COUNTER++;//Counter to kepp track of where we are in our precomputed table //if (DAC_COUNTER>=pre_compute_length) {DAC_COUNTER = 0;}//wrap around the counter + //Note currently we are sampling 2 adc at 100 KHz. If desired you can also sample 4 ADCs at 50 KHz input_50k[1][i]=float(static_input_array1[i]); // input_50k[3][i/2]=static_input_array1[i+1]; input_50k[0][i]=float(static_input_array0[i]); //input_50k[2][i/2]=static_input_array0[i+1]; - - }//End of for loop going throught the buffer of adc samples - //input_50k[0] = static_input_array0; - //input_50k[1] = static_input_array1; + + f1.input(input_50k,64,DEMOD_200HZ); //f1_b.input(input_50k,64,DEMOD_1000HZ); //status_3 = 1; @@ -225,11 +237,11 @@ status_1 = 0;//turn off D1 used in deterimining how long processing is taking - //filter_input_array[i] = (float) (((int)static_input_array0[i]) - 0x8000); - //arm_fir_f32(&S, filter_input_array, filter_output_array, len); - + }//end of while loop + //prints ADC buffer if desired + //for(int i = 0; i<PRINT_BUFFER_LENGTH; i++)//print all the adc values measured //{ // printf("%.1f %.1f\n\r",output_print_buffer[i],output_print_buffer2[i]);