Jared Baxter
/
Impedance_Fast_Circuitry
Fork of DSP_200kHz by
main.cpp@67:ec0c58490ce6, 2016-02-26 (annotated)
- Committer:
- bmazzeo
- Date:
- Fri Feb 26 22:53:32 2016 +0000
- Revision:
- 67:ec0c58490ce6
- Parent:
- 66:72c5c24e532c
- Child:
- 68:e5031c18fefb
float conversion passthrough
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:bb128f0e952f | 1 | #include "mbed.h" |
timmey9 | 22:523e316cbe70 | 2 | |
timmey9 | 52:5a40cc58c4c2 | 3 | // Sampling |
bmazzeo | 53:83a90a47c1fd | 4 | #include "DMA_sampling/adc.h" |
bmazzeo | 54:1697dc574b96 | 5 | #include "DMA_sampling/dac.h" |
bmazzeo | 55:2526b3317bc8 | 6 | #include "DMA_sampling/pdb.h" |
timmey9 | 22:523e316cbe70 | 7 | |
bmazzeo | 67:ec0c58490ce6 | 8 | // DSP |
bmazzeo | 67:ec0c58490ce6 | 9 | #include "dsp.h" |
bmazzeo | 67:ec0c58490ce6 | 10 | |
bmazzeo | 67:ec0c58490ce6 | 11 | |
timmey9 | 22:523e316cbe70 | 12 | // for debug purposes |
timmey9 | 18:b17ddeeb1c09 | 13 | Serial pc(USBTX, USBRX); |
timmey9 | 18:b17ddeeb1c09 | 14 | DigitalOut led_red(LED_RED); |
timmey9 | 18:b17ddeeb1c09 | 15 | DigitalOut led_green(LED_GREEN); |
timmey9 | 18:b17ddeeb1c09 | 16 | DigitalOut led_blue(LED_BLUE); |
bmazzeo | 58:4bee89daccff | 17 | DigitalOut status_0(D0); |
bmazzeo | 58:4bee89daccff | 18 | DigitalOut status_1(D1); |
bmazzeo | 66:72c5c24e532c | 19 | DigitalIn sw2(SW2); |
bmazzeo | 66:72c5c24e532c | 20 | DigitalIn sw3(SW3); |
timmey9 | 51:43143a3fc2d7 | 21 | |
timmey9 | 52:5a40cc58c4c2 | 22 | // defined in dma.cpp |
timmey9 | 45:d591d138cdeb | 23 | extern int len; |
bmazzeo | 54:1697dc574b96 | 24 | extern uint16_t static_input_array0[]; |
bmazzeo | 54:1697dc574b96 | 25 | extern uint16_t static_input_array1[]; |
bmazzeo | 55:2526b3317bc8 | 26 | extern uint16_t static_output_array0[]; |
bmazzeo | 57:7b8c49e1c1f6 | 27 | extern uint16_t sampling_status; |
bmazzeo | 57:7b8c49e1c1f6 | 28 | |
bmazzeo | 67:ec0c58490ce6 | 29 | // To set up FIR filtering |
bmazzeo | 67:ec0c58490ce6 | 30 | #define TOTAL_TAPS 8 |
bmazzeo | 67:ec0c58490ce6 | 31 | #define STATE_LENGTH 71 |
bmazzeo | 67:ec0c58490ce6 | 32 | #define BUFFER_LENGTH 64 |
bmazzeo | 67:ec0c58490ce6 | 33 | uint16_t numTaps = TOTAL_TAPS; |
bmazzeo | 67:ec0c58490ce6 | 34 | float State[STATE_LENGTH]= {0}; |
bmazzeo | 67:ec0c58490ce6 | 35 | float Coeffs[TOTAL_TAPS] = {0.25, 0, 0, 0, 0, 0, 0, 0}; |
bmazzeo | 67:ec0c58490ce6 | 36 | arm_fir_instance_f32 S = {numTaps, State, Coeffs}; |
bmazzeo | 67:ec0c58490ce6 | 37 | |
bmazzeo | 67:ec0c58490ce6 | 38 | float filter_input_array[BUFFER_LENGTH] = {0}; |
bmazzeo | 67:ec0c58490ce6 | 39 | float filter_output_array[BUFFER_LENGTH] = {0}; |
bmazzeo | 67:ec0c58490ce6 | 40 | |
bmazzeo | 67:ec0c58490ce6 | 41 | |
emilmont | 7:65188f4a8c25 | 42 | int main() { |
timmey9 | 22:523e316cbe70 | 43 | led_blue = 1; |
timmey9 | 35:df40c4566826 | 44 | led_green = 1; |
timmey9 | 18:b17ddeeb1c09 | 45 | led_red = 1; |
timmey9 | 34:44cc9b76a507 | 46 | |
timmey9 | 18:b17ddeeb1c09 | 47 | pc.baud(230400); |
timmey9 | 34:44cc9b76a507 | 48 | pc.printf("Starting\r\n"); |
timmey9 | 27:8c2b30c855d1 | 49 | |
bmazzeo | 66:72c5c24e532c | 50 | pdb_init(); // Initalize PDB |
bmazzeo | 66:72c5c24e532c | 51 | dac_init(); // initializes DAC |
timmey9 | 45:d591d138cdeb | 52 | adc_init(); // always initialize adc before dma |
bmazzeo | 53:83a90a47c1fd | 53 | pc.printf("ADC Initialized\r\n"); |
timmey9 | 51:43143a3fc2d7 | 54 | dma_init(); // initializes DMAs |
bmazzeo | 55:2526b3317bc8 | 55 | dma_reset(); // This clears any DMA triggers that may have gotten things into a different state |
bmazzeo | 67:ec0c58490ce6 | 56 | pc.printf("Buffer Size: %i\r\n", len); |
bmazzeo | 54:1697dc574b96 | 57 | |
timmey9 | 46:a015ebf4663b | 58 | led_green = 1; |
timmey9 | 38:ec3b16c130d7 | 59 | |
timmey9 | 40:bd6d8c35e822 | 60 | pc.printf("\r\n\r\n\r\n"); |
timmey9 | 37:8bdc71f3e874 | 61 | |
bmazzeo | 64:bb4a4bd57681 | 62 | pdb_start(); |
bmazzeo | 64:bb4a4bd57681 | 63 | while(1) |
bmazzeo | 61:a56cca07d4a6 | 64 | { |
bmazzeo | 61:a56cca07d4a6 | 65 | while(sampling_status == 0) |
bmazzeo | 61:a56cca07d4a6 | 66 | { |
bmazzeo | 61:a56cca07d4a6 | 67 | status_0 = 1; |
bmazzeo | 61:a56cca07d4a6 | 68 | } |
bmazzeo | 66:72c5c24e532c | 69 | |
bmazzeo | 61:a56cca07d4a6 | 70 | sampling_status = 0; |
bmazzeo | 61:a56cca07d4a6 | 71 | status_0 = 0; |
bmazzeo | 66:72c5c24e532c | 72 | |
bmazzeo | 66:72c5c24e532c | 73 | if(sw2) |
bmazzeo | 61:a56cca07d4a6 | 74 | { |
bmazzeo | 66:72c5c24e532c | 75 | if(sw3) |
bmazzeo | 66:72c5c24e532c | 76 | { |
bmazzeo | 66:72c5c24e532c | 77 | //Default PASSTHROUGH Condition |
bmazzeo | 66:72c5c24e532c | 78 | status_1 = 1; |
bmazzeo | 66:72c5c24e532c | 79 | for(int i = 0; i < len; i++) |
bmazzeo | 66:72c5c24e532c | 80 | { |
bmazzeo | 66:72c5c24e532c | 81 | static_output_array0[i] = static_input_array0[i] >> 4; |
bmazzeo | 66:72c5c24e532c | 82 | } |
bmazzeo | 66:72c5c24e532c | 83 | status_1 = 0; |
bmazzeo | 66:72c5c24e532c | 84 | } |
bmazzeo | 66:72c5c24e532c | 85 | else |
bmazzeo | 66:72c5c24e532c | 86 | { |
bmazzeo | 66:72c5c24e532c | 87 | // Can show that buttons are active - Serial link working |
bmazzeo | 66:72c5c24e532c | 88 | status_1 = 1; |
bmazzeo | 66:72c5c24e532c | 89 | pc.printf("DSP\r\n"); |
bmazzeo | 66:72c5c24e532c | 90 | for(int i = 0; i < len; i++) |
bmazzeo | 66:72c5c24e532c | 91 | { |
bmazzeo | 66:72c5c24e532c | 92 | static_output_array0[i] = static_input_array0[i] >> 4; |
bmazzeo | 66:72c5c24e532c | 93 | } |
bmazzeo | 66:72c5c24e532c | 94 | status_1 = 0; |
bmazzeo | 66:72c5c24e532c | 95 | } |
bmazzeo | 66:72c5c24e532c | 96 | } |
bmazzeo | 66:72c5c24e532c | 97 | else |
bmazzeo | 66:72c5c24e532c | 98 | { |
bmazzeo | 66:72c5c24e532c | 99 | // Here we can really put our DSP blocks |
bmazzeo | 66:72c5c24e532c | 100 | status_1 = 1; |
bmazzeo | 66:72c5c24e532c | 101 | for(int i = 0; i < len; i++) |
bmazzeo | 66:72c5c24e532c | 102 | { |
bmazzeo | 67:ec0c58490ce6 | 103 | //static_output_array0[i] = static_input_array0[i] >> 4; |
bmazzeo | 67:ec0c58490ce6 | 104 | //filter_input_array[i] = (float) (((int) static_input_array0[i]) - 0x8000); |
bmazzeo | 67:ec0c58490ce6 | 105 | filter_input_array[i] = (float) static_input_array0[i]; |
bmazzeo | 67:ec0c58490ce6 | 106 | } |
bmazzeo | 67:ec0c58490ce6 | 107 | |
bmazzeo | 67:ec0c58490ce6 | 108 | //filter_input_array[0] = (float) static_input_array0[0]; |
bmazzeo | 67:ec0c58490ce6 | 109 | |
bmazzeo | 67:ec0c58490ce6 | 110 | //arm_fir_f32(&S, filter_input_array, filter_output_array, len); |
bmazzeo | 67:ec0c58490ce6 | 111 | |
bmazzeo | 67:ec0c58490ce6 | 112 | for(int i = 0; i < len; i++) |
bmazzeo | 67:ec0c58490ce6 | 113 | { |
bmazzeo | 67:ec0c58490ce6 | 114 | //static_output_array0[i] = static_input_array0[i] >> 4; |
bmazzeo | 67:ec0c58490ce6 | 115 | //filter_output_array[i] = 0.25 * filter_input_array[i]; |
bmazzeo | 67:ec0c58490ce6 | 116 | filter_output_array[i] = 0.0625 * filter_input_array[i]; |
bmazzeo | 67:ec0c58490ce6 | 117 | } |
bmazzeo | 67:ec0c58490ce6 | 118 | |
bmazzeo | 67:ec0c58490ce6 | 119 | |
bmazzeo | 67:ec0c58490ce6 | 120 | for(int i = 0; i < len; i++) |
bmazzeo | 67:ec0c58490ce6 | 121 | { |
bmazzeo | 67:ec0c58490ce6 | 122 | //static_output_array0[i] = static_input_array0[i] >> 4; |
bmazzeo | 67:ec0c58490ce6 | 123 | //static_output_array0[i] = (uint16_t) (( (int) filter_output_array[i] ) + 0x800); |
bmazzeo | 67:ec0c58490ce6 | 124 | static_output_array0[i] = (uint16_t) filter_output_array[i]; |
bmazzeo | 67:ec0c58490ce6 | 125 | //static_output_array0[i] = (uint16_t) filter_input_array[i]; |
bmazzeo | 67:ec0c58490ce6 | 126 | //static_output_array0[i] = static_input_array0[i] >> 4; |
bmazzeo | 66:72c5c24e532c | 127 | } |
bmazzeo | 66:72c5c24e532c | 128 | status_1 = 0; |
bmazzeo | 61:a56cca07d4a6 | 129 | } |
bmazzeo | 61:a56cca07d4a6 | 130 | } |
bmazzeo | 61:a56cca07d4a6 | 131 | } |
bmazzeo | 63:7903a33e2fd4 | 132 |