V001. 2017_11_30 10:21 Working code from Tuesday's lab session.

Dependencies:   mbed-rtos mbed

Fork of 2017_11_28_ELEC347_Coursework by Chris Hills

DSP Coursework ELEC347 2017-2018 Group members: Matthew Thewsey, Thomas Morris, Samuel Waggett, Christopher Hills .

Revision:
13:db76473a3d76
Parent:
12:d522a7a061d6
Child:
14:379796f5868e
Child:
16:c91b29c9e9f6
--- a/main.cpp	Sat Dec 02 17:09:34 2017 +0000
+++ b/main.cpp	Mon Dec 04 11:24:15 2017 +0000
@@ -2,7 +2,6 @@
 #include "rtos.h"
 #include "Filter.hpp"
 
-
 unsigned short ADC_DATA;
 
 //Init  values for difference equation
@@ -10,20 +9,17 @@
 DigitalOut SampLED(LED1);              //Digital Output  (GREEN LED is PB_3, D13 You can use an Oscilloscope on This pin to confirm sample rate)
 
 //Analog Inputs
-AnalogIn QDEF(PA_7);                    // Q Factor
-AnalogIn BDEF(PA_6);                    // Boost Level
-AnalogIn FDEF(PA_5);                    //Centre Frequency
 AnalogIn  Ain(PA_1);                    //Analog Input (Signal Input 0 to +3 Volts)
 AnalogOut Aout(PA_4);                   //Analog Output (Signal Input 0 to +3 Volts)
 
-//Declare Tickers
-Ticker sample_timer;
-
-
 //Declare Threads
 Thread t1;
 Thread t2;
 
+AnalogIn QDEF(PA_7);                    // Q Factor
+AnalogIn BDEF(PA_6);                    // Boost Level
+AnalogIn FDEF(PA_5);                    //Centre Frequency
+    
 //Declare Ticker Rates
 float sample_rate = (1.0/35000);        //Rate of sampling
 float coeff_rate = (1.0 / 20);          //Rate of updating coefficients
@@ -31,54 +27,35 @@
 //Initial Input Value
 float input = 0.0;
 
-//Declare Filter
-FILTER BP_filter(48000,10000,-16,2);  //Create object of type Filter(Fs,Fo,Boost,Q)
-
-//Declare Variables
-float Fo = 1;
-float Boost = 0;
-float Q = 1;
-
-//Declare Temporary Coefficient Values
 float Fo_Current;
 float Boost_Current;
 float Q_Current;
 
+//Declare Filter
+FILTER BP_filter(48000,10000,-16,2);  //Create object of type Filter(Fs,Fo,Boost,Q)
+
+
 //Forward Declarations
 void sampler(void);
-void coeff_update(void);
+void update(void);
 
 
 int main()
 {
     t2.start(sampler);//Start the Sampler timed interrupt
-    t1.start(coeff_update);//Update the coeffiecients of the filter
-
+    t1.start(update);//Update the coeffiecients of the filter
 }
 
-
-void coeff_update(void)
+void update(void)
 {
     while(1){
-        Fo_Current = FDEF * 22000 + 10;
-        if (abs(Fo_Current - BP_filter.Get_Fo()) > 50)      //If Centre Frequency has changed significantly
-        {
-            BP_filter.Update_Fo(Fo_Current);                //Update Centre Frequency
-        }
-        Boost_Current = BDEF * 100 - 50;
-        if (abs(Boost_Current - BP_filter.Get_Boost()) > 2) //If Boost has changed significantly
-        {
-            BP_filter.Update_Boost(Boost_Current);          //Update Boost
-        }
-        Q_Current = QDEF * 49 + 1;
-        if (abs(Q_Current - BP_filter.Get_Q()) > 2)         //If Q has changed significantly
-        {
-            BP_filter.Update_Q(Q_Current);                  //Update Q
-        }
-        BP_filter.Define_Filter();                          //Calculate the coefficients
-        //BP_filter.Print_Filter();                           //Print the ceofficients
-        printf("Q = %d \t Boost = %f \t Fo = %d\n\r", BP_filter.Get_Q(), BP_filter.Get_Boost(), BP_filter.Get_Fo());
-        Thread::wait(1000);//Sleep the thread for 1 second then re runs the coefficient calculation 
+    Fo_Current = FDEF * 22000 + 10;
+    Boost_Current = BDEF * 100 - 50;
+    Q_Current = QDEF * 49 + 1;
+    
+    BP_filter.coeff_update(Fo_Current,Boost_Current,Q_Current);//Coefficient update
+    printf("Q = %d \t Boost = %f \t Fo = %d\n\r", BP_filter.Get_Q(), BP_filter.Get_Boost(), BP_filter.Get_Fo());
+    Thread::wait(1000);//Sleep the thread for 1 second then re runs the coefficient calculation    
     }
 }
 
@@ -86,14 +63,11 @@
 {
     while(1)
     {
-        SampLED = 1;                        //LED Indicates start of sampling
-    
-        input = Ain;
-        BP_filter.setvalue(input);          //Input ADC. N.B. ADC in MBED is 0.0 to 1.0 float!!!!!!
-        Aout = BP_filter.getvalue();
-        
-    
-        SampLED = 0;      //LED Indicates end of sampling
+        SampLED = 1;//LED Indicates start of sampling
+        input = Ain;//Takes ADC input  as a Varaible type float
+        BP_filter.setvalue(input);//Input ADC. N.B. ADC in MBED is 0.0 to 1.0 float!!!!!!
+        Aout = BP_filter.getvalue();//Sets the input value to the Class
+        SampLED = 0;//LED Indicates end of sampling
         Thread::wait(sample_rate*1000);//Look at this
     }
 }