Martin Simpson / Mbed 2 deprecated ELEC347_STM32F303K8_FIR

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 //Just Comment out the Dataset you DO NOT wish to use and UN-Comment the one that you wish to use
00004 //and then 'Build' <F7> and once complete 'Load' to the STM-Discovery board <F8>
00005 
00006 #include "LP_2KHz_Fc_6KHz_Fs_37N.h"
00007 //#include "LP_2KHz_Fc_40KHz_Fs_37N.h"
00008 //#include "LP_2KHz_Fc_40KHz_Fs_100N.h"
00009 
00010 #define ON      1
00011 #define OFF     0
00012 
00013 float x[N]={0};
00014 float yn;
00015 
00016 void sampler(void);                     //Ticker routine PROTOTYPE
00017 
00018 //MBED Class Instances follows
00019 DigitalOut SampLED(LED1);               //Digital Output  (GREEN LED is PB_3, D13 You can use an Oscilloscope on This pin to confirm sample rate)
00020 
00021 AnalogIn  Ain(PA_1);                    //Analog Input (Signal Input 0 to +3 Volts)
00022 AnalogOut Aout(PA_4);                   //Analog Output (Signal Input 0 to +3 Volts) NB PA_4 because Arduin Nano Compatability
00023                                         //on STM32F303k8 uses I2C PA_5 to PB7
00024 
00025 Ticker sample_timer;                    //Ticker class instance called sample_timer
00026 
00027 PwmOut test(PWM_OUT);
00028 
00029 
00030 int main() {
00031     float duty=0.1f;
00032     test.period_ms(1);
00033     test=duty;
00034   
00035     float sample_rate=(1.0/Fs)*1000000.0; //Calculate the number of uS required for a Frequency Sampling Rate
00036                                           //Fs held in *.h
00037   
00038     sample_timer.attach_us(&sampler,(int)sample_rate);
00039                                           //Ticker Instance serviced by routine at a repeat rate in microseconds
00040   
00041     while(1) {
00042         sleep();
00043     }
00044 }
00045 
00046 void sampler(void){                     //Ticker routine
00047     
00048     SampLED = ON;                       //LED Indicates start of sampling
00049     int i;                              //Initialise local variable i
00050     x[0]=Ain;                           //Input ADC. N.B. ADC in MBED is 0.0 to 1.0 float!!!!!!
00051     yn=0.0;                             //output accumulation, start as zero
00052     
00053     for(i=0; i<N; i++) yn+=x[i]*b[i];   //generate output from filter components FIR a=0
00054     for(i=N-1; i!=0; i--) x[i]=x[i-1];  //shift data
00055     
00056     Aout=yn;                            //Output resultant to DAC. Again MBED uses 0.0 to 1.0 float!!!!!!
00057     
00058     SampLED = OFF;                      //LED Indicates end of sampling
00059     }
00060