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 DSP_200kHz by
Diff: main.cpp
- Revision:
- 69:014d4bbd4e03
- Parent:
- 68:e5031c18fefb
- Child:
- 70:8cd7a8a2c153
- Child:
- 71:973fac37c5b3
--- a/main.cpp Fri May 05 21:41:36 2017 +0000
+++ b/main.cpp Wed May 17 19:33:26 2017 +0000
@@ -27,23 +27,50 @@
extern uint16_t sampling_status;
// To set up FIR filtering
-#define TOTAL_TAPS 8
-#define STATE_LENGTH 71
+#define TOTAL_TAPS 16
+#define STATE_LENGTH 79
#define BUFFER_LENGTH 64
uint16_t numTaps = TOTAL_TAPS;
float State[STATE_LENGTH]= {0};
-float Coeffs[TOTAL_TAPS] = {1, -1, 0, 0, 0, 0, 0, 0};
+float Coeffs[TOTAL_TAPS] = {0.0351885543264657, 0.0326718041339497, 0.0447859388579763, 0.0571840193174261, 0.0688188647212066, 0.0786841934234295, 0.0858044659079242, 0.0895870376972757, 0.0895870376972757, 0.0858044659079242, 0.0786841934234295, 0.0688188647212066, 0.0571840193174261, 0.0447859388579763, 0.0326718041339497, 0.0351885543264657};
arm_fir_instance_f32 S = {numTaps, State, Coeffs};
float filter_input_array[BUFFER_LENGTH] = {0};
float filter_output_array[BUFFER_LENGTH] = {0};
+
+#define pre_compute_length 500
+#define CarrierFrequency 200
+#define SAMPLEFREQUENCY 100000
+//float i_mod_pre[pre_compute_length];
+//float q_mod_pre[pre_compute_length];
+uint16_t out_val_pre[pre_compute_length];
+float twopi = 3.14159265359 * 2;
+
+
+void pre_compute_tables() {
+ // This function will precompute the cos and sin tables used in the rest of the program
+ for(int precompute_counter = 0; precompute_counter < pre_compute_length; precompute_counter++){
+ out_val_pre[precompute_counter] = (int) (cos(twopi * CarrierFrequency /SAMPLEFREQUENCY * precompute_counter) * 2046.0 + 2048.0);
+ //printf("%d\n\r",out_val_pre[precompute_counter]);
+ //i_mod_pre[precompute_counter] = (cos(twopi * CarrierFrequency * TimerInterruptInMicroSeconds * 1e-6 * precompute_counter));
+ //q_mod_pre[precompute_counter] = (-sin(twopi * CarrierFrequency * TimerInterruptInMicroSeconds * 1e-6 * precompute_counter));
+
+ }
+}
+
+
int main() {
led_blue = 1;
led_green = 1;
led_red = 1;
+ int DAC_COUNTER = 0;
+ //bool is_magnified_sample = true;
+ pre_compute_tables();
+
+
pc.baud(230400);
pc.printf("Starting\r\n");
@@ -66,7 +93,17 @@
{
status_0 = 1;
}
-
+ /*
+ if (is_magnified_sample)
+ {
+ ADC0_SC1A = 0x0D;
+ }
+ else
+ {
+ ADC0_SC1A = 0x0C;
+ }
+ is_magnified_sample = !is_magnified_sample;
+ */
sampling_status = 0;
status_0 = 0;
@@ -78,7 +115,11 @@
status_1 = 1;
for(int i = 0; i < len; i++)
{
- static_output_array0[i] = static_input_array0[i] >> 4;
+ static_output_array0[i] = static_input_array0[i] >> 4;
+
+
+
+
}
status_1 = 0;
}
@@ -86,7 +127,8 @@
{
// Can show that buttons are active - Serial link working
status_1 = 1;
- pc.printf("DSP\r\n");
+ pc.printf("DSP: %d\r\n",out_val_pre[DAC_COUNTER]);
+ //pc.printf("DSP: %d\r\n",out_val_pre[DAC_COUNTER]);
for(int i = 0; i < len; i++)
{
static_output_array0[i] = static_input_array0[i] >> 4;
@@ -124,10 +166,20 @@
{
//static_output_array0[i] = static_input_array0[i] >> 4;
//static_output_array0[i] = (uint16_t) (( (int) filter_output_array[i] ) + 0x800);
- static_output_array0[i] = (uint16_t) (filter_output_array[i] + 0x8000) >> 4;
+ //static_output_array0[i] = (uint16_t) (filter_output_array[i] + 0x8000) >> 4;
//static_output_array0[i] = (uint16_t) filter_input_array[i];
//static_output_array0[i] = static_input_array0[i] >> 4;
- }
+
+
+ static_output_array0[i] = out_val_pre[DAC_COUNTER];
+ DAC_COUNTER++;
+ if (DAC_COUNTER>=pre_compute_length)
+ {
+ DAC_COUNTER = 0;
+ }
+ }
+
+
status_1 = 0;
}
}

