From 4a4fd491d3fccc4eae44f5f19deb6cd95ab2eb12 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 27 Feb 2015 20:56:21 +0000 Subject: [PATCH] added FM demod git-svn-id: https://svn.code.sf.net/p/freetel/code@2048 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/stm32/Makefile | 3 +- codec2-dev/stm32/inc/iir_tuner.h | 36 ++++++++++++++ codec2-dev/stm32/src/stm32f4_adc.c | 2 +- codec2-dev/stm32/src/stm32f4_adc_tuner.c | 2 +- codec2-dev/stm32/src/stm32f4_dac.c | 4 +- codec2-dev/stm32/src/tuner_ut.c | 63 ++++++++++++++++++------ 6 files changed, 90 insertions(+), 20 deletions(-) create mode 100644 codec2-dev/stm32/inc/iir_tuner.h diff --git a/codec2-dev/stm32/Makefile b/codec2-dev/stm32/Makefile index 0ebb6c2a..ae8a90d5 100644 --- a/codec2-dev/stm32/Makefile +++ b/codec2-dev/stm32/Makefile @@ -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 index 00000000..7788a8d8 --- /dev/null +++ b/codec2-dev/stm32/inc/iir_tuner.h @@ -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 . +*/ + +#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 diff --git a/codec2-dev/stm32/src/stm32f4_adc.c b/codec2-dev/stm32/src/stm32f4_adc.c index e310f2aa..1aab0df5 100644 --- a/codec2-dev/stm32/src/stm32f4_adc.c +++ b/codec2-dev/stm32/src/stm32f4_adc.c @@ -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 */ diff --git a/codec2-dev/stm32/src/stm32f4_adc_tuner.c b/codec2-dev/stm32/src/stm32f4_adc_tuner.c index b8e3b2a6..d083c599 100644 --- a/codec2-dev/stm32/src/stm32f4_adc_tuner.c +++ b/codec2-dev/stm32/src/stm32f4_adc_tuner.c @@ -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 diff --git a/codec2-dev/stm32/src/stm32f4_dac.c b/codec2-dev/stm32/src/stm32f4_dac.c index 2115fa34..5f36402f 100644 --- a/codec2-dev/stm32/src/stm32f4_dac.c +++ b/codec2-dev/stm32/src/stm32f4_dac.c @@ -289,7 +289,7 @@ void DMA1_Stream5_IRQHandler(void) { int i, j, sam; short signed_buf[DAC_BUF_SZ/2]; - GPIOE->ODR = (1 << 1); + GPIOE->ODR |= (1 << 1); /* Transfer half empty interrupt - refill first half */ @@ -346,7 +346,7 @@ void DMA1_Stream6_IRQHandler(void) { int i, j, sam; short signed_buf[DAC_BUF_SZ/2]; - GPIOE->ODR = (1 << 2); + GPIOE->ODR |= (1 << 2); /* Transfer half empty interrupt - refill first half */ diff --git a/codec2-dev/stm32/src/tuner_ut.c b/codec2-dev/stm32/src/tuner_ut.c index 788e5cfd..ac522000 100644 --- a/codec2-dev/stm32/src/tuner_ut.c +++ b/codec2-dev/stm32/src/tuner_ut.c @@ -33,19 +33,23 @@ #include "stm32f4_adc_tuner.h" #include "iir_tuner.h" #include "sm1000_leds_switches.h" +#include "../src/codec2_fm.h" +#include "stm32f4xx.h" #define REC_TIME_SECS 10 #define FS 50000 -#define N 10000 +#define N 5000 extern int adc_overflow1; int main(void) { float tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM+N/2]; - float dec_10[(N/2)/5]; - short dec_10_short[(N/2)/5]; - int bufs, i, j, fifo_sz; + float fm_out[N/2]; + //float dec_10[(N/2)/5]; + short dec_10_short[(N/2)]; + int bufs, i, j, k, fifo_sz, bn; FILE *ftuner; + struct FM *fm; ftuner = fopen("tuner.raw", "wb"); if (ftuner == NULL) { @@ -60,8 +64,14 @@ int main(void) { adc_open(fifo_sz); sm1000_leds_switches_init(); - for(i=0; iFs = 44400.0; + fm->fm_max = 3000.0; + fm->fd = 5000.0; + fm->fc = fm->Fs/4; + i = 0; bn = 0; + while(1) { /* wait for buffer of Fs=50kHz tuner output samples */ while(adc1_read((short *)&tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM], N) == -1); @@ -69,21 +79,44 @@ int main(void) { /* The semi-hosting system can only handle Fs=16kHz and below so resample down to Fs=10 kHz and convert to shorts */ - //for(j=0; jODR |= (1 << 3); + /* + for(j=0; jODR &= ~(1 << 3); + + for(j=0,k=0; j