V001. 2017_11_30 10:21 Working code from Tuesday's lab session.
Fork of 2017_11_28_ELEC347_Coursework by
DSP Coursework ELEC347 2017-2018 Group members: Matthew Thewsey, Thomas Morris, Samuel Waggett, Christopher Hills .
Diff: main.cpp
- Revision:
- 8:192b376a6da7
- Parent:
- 7:6cb27cce4c50
- Child:
- 9:91c53a683856
diff -r 6cb27cce4c50 -r 192b376a6da7 main.cpp --- a/main.cpp Tue Nov 28 14:37:13 2017 +0000 +++ b/main.cpp Tue Nov 28 15:19:08 2017 +0000 @@ -10,9 +10,9 @@ 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_2); -AnalogIn BDEF(PA_7); -AnalogIn FDEF(PA_6); +AnalogIn QDEF(PA_7); +AnalogIn BDEF(PA_6); +AnalogIn FDEF(PA_5); AnalogIn Ain(PA_1); //Analog Input (Signal Input 0 to +3 Volts) AnalogOut Aout(PA_4); //Analog Output (Signal Input 0 to +3 Volts) @@ -20,6 +20,9 @@ Ticker sample_timer; Ticker coeff_change; +//Declare Threads +Thread t1; + //Declare Ticker Rates float sample_rate = (1.0/35000); //Rate of sampling float coeff_rate = (1.0 / 20); //Rate of updating coefficients @@ -44,32 +47,36 @@ void sampler(void); void coeff_update(void); + int main() { - //sample_timer.attach(&sampler,sample_rate); - coeff_change.attach(&coeff_update,coeff_rate); + sample_timer.attach(&sampler,sample_rate); + t1.start(coeff_update); printf("Hello"); } + void coeff_update(void) { - Fo_Current = FDEF * 39999 + 1; - if (abs(Fo_Current - BP_filter.Get_Fo()) > 50) //If Centre Frequency has changed significantly - { - BP_filter.Update_Fo(Fo_Current); //Update Centre Frequency + while(1){ + Fo_Current = FDEF * 39999 + 1; + 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 } - 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 } void sampler(void)