added FM demod
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 27 Feb 2015 20:56:21 +0000 (20:56 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 27 Feb 2015 20:56:21 +0000 (20:56 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2048 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/stm32/Makefile
codec2-dev/stm32/inc/iir_tuner.h [new file with mode: 0644]
codec2-dev/stm32/src/stm32f4_adc.c
codec2-dev/stm32/src/stm32f4_adc_tuner.c
codec2-dev/stm32/src/stm32f4_dac.c
codec2-dev/stm32/src/tuner_ut.c

index 0ebb6c2ae95e1809d5f30dc54dafbfcfc13353c9..ae8a90d58060a5f4f7cad194880e4d4528da6127 100644 (file)
@@ -362,7 +362,8 @@ src/sm1000_leds_switches.c \
 src/debugblinky.c \
 src/system_stm32f4xx.c \
 src/startup_stm32f4xx.s \
-src/init.c
+src/init.c \
+../src/fm.c
 
 # this needs to be compiled without the optimiser or ugly things happen
 # would be nice to work out why as ISRs need to run fast
diff --git a/codec2-dev/stm32/inc/iir_tuner.h b/codec2-dev/stm32/inc/iir_tuner.h
new file mode 100644 (file)
index 0000000..7788a8d
--- /dev/null
@@ -0,0 +1,36 @@
+/*---------------------------------------------------------------------------*\
+
+  FILE........: iir_tuner.h
+  AUTHOR......: David Rowe
+  DATE CREATED: 20 Feb 2015
+
+  Header file for IIR tuner function.
+
+\*---------------------------------------------------------------------------*/
+
+/*
+  Copyright (C) 2015 David Rowe
+
+  All rights reserved.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License version 2.1, as
+  published by the Free Software Foundation.  This program is
+  distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+  License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __IIR_TUNER__
+#define __IIR_TUNER__
+
+#define IIR_TUNER_DEC_50_10_FILT_MEM 100
+
+void iir_tuner(float dec_50[], unsigned short adc_buf[]);
+void iir_tuner_dec_50_to_10(float dec_10[], float dec_50[], int n);
+
+#endif
index e310f2aa3f6c0efa4825c8ddae80aa03e62a535f..1aab0df5a63be6a38a412f7f0a262fa6cd9460c1 100644 (file)
@@ -209,7 +209,7 @@ void DMA2_Stream0_IRQHandler(void) {
     short signed_buf1[ADC_BUF_SZ/2];
     short signed_buf2[ADC_BUF_SZ/2];
 
-    GPIOE->ODR = (1 << 0);
+    GPIOE->ODR |= (1 << 0);
 
     /* Half transfer interrupt */
 
index b8e3b2a6feca75c6b043d691d8321662c9376d9f..d083c599e26a2c98b26d63d3e7a542c1cbcfac92 100644 (file)
@@ -211,7 +211,7 @@ void DMA2_Stream0_IRQHandler(void) {
 
     /* PE0 is asserted high for the duration of this ISR */
 
-    GPIOE->ODR = (1 << 0);
+    GPIOE->ODR |= (1 << 0);
 
     //#define DUMMY_SIGNAL
     #ifdef DUMMY_SIGNAL
index 2115fa34ddc69e95ffcc83876a3b057a264ef010..5f36402f8a18f2a2b6ef38aed86407b7e79485b1 100644 (file)
@@ -289,7 +289,7 @@ void DMA1_Stream5_IRQHandler(void) {
     int i, j, sam;\r
     short signed_buf[DAC_BUF_SZ/2];\r
 \r
-    GPIOE->ODR = (1 << 1);\r
+    GPIOE->ODR |= (1 << 1);\r
 \r
     /* Transfer half empty interrupt - refill first half */\r
 \r
@@ -346,7 +346,7 @@ void DMA1_Stream6_IRQHandler(void) {
     int i, j, sam;\r
     short signed_buf[DAC_BUF_SZ/2];\r
 \r
-    GPIOE->ODR = (1 << 2);\r
+    GPIOE->ODR |= (1 << 2);\r
 \r
     /* Transfer half empty interrupt - refill first half */\r
 \r
index 788e5cfd705ecc0bb4dad4431cef8f53bd42c5a0..ac5220003d205bde7a71117b64a97c266604e15f 100644 (file)
 #include "stm32f4_adc_tuner.h"\r
 #include "iir_tuner.h"\r
 #include "sm1000_leds_switches.h"\r
+#include "../src/codec2_fm.h"\r
+#include "stm32f4xx.h"\r
 \r
 #define REC_TIME_SECS 10\r
 #define FS            50000\r
-#define N             10000\r
+#define N             5000\r
 \r
 extern int adc_overflow1;\r
 \r
 int main(void) {\r
     float  tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM+N/2];\r
-    float  dec_10[(N/2)/5];\r
-    short  dec_10_short[(N/2)/5];\r
-    int    bufs, i, j, fifo_sz;\r
+    float  fm_out[N/2];\r
+    //float  dec_10[(N/2)/5];\r
+    short  dec_10_short[(N/2)];\r
+    int    bufs, i, j, k, fifo_sz, bn;\r
     FILE  *ftuner;\r
+    struct FM *fm;\r
 \r
     ftuner = fopen("tuner.raw", "wb");\r
     if (ftuner == NULL) {\r
@@ -60,8 +64,14 @@ int main(void) {
     adc_open(fifo_sz);\r
     sm1000_leds_switches_init();\r
 \r
-    for(i=0; i<bufs; i++) {\r
+    fm         = fm_create(N/2);\r
+    fm->Fs     = 44400.0;\r
+    fm->fm_max = 3000.0;\r
+    fm->fd     = 5000.0;\r
+    fm->fc     = fm->Fs/4;\r
 \r
+    i = 0; bn = 0;\r
+    while(1) {\r
         /* wait for buffer of Fs=50kHz tuner output samples */\r
 \r
         while(adc1_read((short *)&tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM], N) == -1);\r
@@ -69,21 +79,44 @@ int main(void) {
         /* The semi-hosting system can only handle Fs=16kHz and below so resample down\r
            to Fs=10 kHz and convert to shorts */\r
 \r
-        //for(j=0; j<N/2; j++)\r
-        //    tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM+j] = 45.0;\r
+        #ifdef SSB\r
         iir_tuner_dec_50_to_10(dec_10, &tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM], N/2);\r
         for(j=0; j<IIR_TUNER_DEC_50_10_FILT_MEM; j++)\r
             tuner_out[j] = tuner_out[j+N/2];\r
         for(j=0; j<(N/2)/5; j++)\r
             dec_10_short[j] = dec_10[j]/ADC_TUNER_M;\r
-\r
-        fwrite(dec_10_short, sizeof(short), (N/2)/5, ftuner);\r
-        printf("%d %d\n", i, adc_overflow1);\r
+        #else\r
+        GPIOE->ODR |= (1 << 3);\r
+        /*\r
+        for(j=0; j<N/2; j++)\r
+            tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM+j] = 0;\r
+        for(j=1; j<N/2; j+=4)\r
+            tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM+j] = 100;\r
+        for(j=3; j<N/2; j+=4)\r
+            tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM+j] = -100;\r
+        */\r
+        fm_demod(fm, fm_out, &tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM]);\r
+        GPIOE->ODR &= ~(1 << 3);\r
+\r
+        for(j=0,k=0; j<N/2; j+=5,k++)\r
+            dec_10_short[k+bn] = 16384*fm_out[j];\r
+        bn += (N/2)/5;\r
+        #endif\r
+\r
+        if ((bn == N/2) && (i < bufs)) {\r
+            //for(j=0; j<N/2; j++)\r
+            //    dec_10_short[j] = tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM+j];\r
+            fwrite(dec_10_short, sizeof(short), (N/2), ftuner);\r
+            bn = 0;\r
+            i += 5;\r
+            //fwrite(dec_10_short, sizeof(short), (N/2)/5, ftuner);\r
+            //printf("%d %d\n", i, adc_overflow1);\r
+        }\r
+        if (i == bufs) {\r
+            printf("finished! %d\n", adc_overflow1);\r
+            fclose(ftuner);\r
+            i++;\r
+        }\r
     }\r
-\r
-    printf("finished! %d\n", adc_overflow1);\r
-    fclose(ftuner);\r
-\r
-    while(1); /* keep ISR running */\r
 }\r
 \r