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 .

Committer:
chills
Date:
Wed Dec 06 02:44:22 2017 +0000
Revision:
17:5774c69932e7
Parent:
15:97b4fa094a48
Child:
18:b442994a01fd
Task 4.2 (Boost Filter Implementation)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mwthewsey 0:d39a06ca6bf1 1 #include "mbed.h"
mwthewsey 0:d39a06ca6bf1 2 #include "rtos.h"
mwthewsey 0:d39a06ca6bf1 3 #include "Filter.hpp"
chills 6:a2737b51424c 4
mwthewsey 0:d39a06ca6bf1 5 unsigned short ADC_DATA;
mwthewsey 0:d39a06ca6bf1 6
mwthewsey 0:d39a06ca6bf1 7 //Init values for difference equation
mwthewsey 0:d39a06ca6bf1 8 //MBED Class Instances follows
chills 17:5774c69932e7 9 DigitalOut SampLED(LED1); //Digital Output (GREEN LED is PB_3, D13 You can use an Oscilloscope on This pin to confirm sample rate)
mwthewsey 0:d39a06ca6bf1 10
chills 7:6cb27cce4c50 11 //Analog Inputs
mwthewsey 0:d39a06ca6bf1 12 AnalogIn Ain(PA_1); //Analog Input (Signal Input 0 to +3 Volts)
mwthewsey 0:d39a06ca6bf1 13 AnalogOut Aout(PA_4); //Analog Output (Signal Input 0 to +3 Volts)
mwthewsey 0:d39a06ca6bf1 14
chills 8:192b376a6da7 15 //Declare Threads
chills 8:192b376a6da7 16 Thread t1;
chills 8:192b376a6da7 17
thomasmorris 13:db76473a3d76 18
chills 7:6cb27cce4c50 19 //Declare Ticker Rates
chills 7:6cb27cce4c50 20 float sample_rate = (1.0/35000); //Rate of sampling
mwthewsey 0:d39a06ca6bf1 21
chills 7:6cb27cce4c50 22 //Initial Input Value
mwthewsey 2:f6e49378dd8a 23 float input = 0.0;
chills 7:6cb27cce4c50 24
chills 7:6cb27cce4c50 25
thomasmorris 13:db76473a3d76 26 //Declare Filter
chills 17:5774c69932e7 27 FILTER BP_filter(48000,10000,16,2); //Create object of type Filter(Fs,Fo,Boost,Q)
thomasmorris 13:db76473a3d76 28
thomasmorris 13:db76473a3d76 29
chills 7:6cb27cce4c50 30 //Forward Declarations
mwthewsey 0:d39a06ca6bf1 31 void sampler(void);
mwthewsey 0:d39a06ca6bf1 32
chills 8:192b376a6da7 33
mwthewsey 0:d39a06ca6bf1 34 int main()
mwthewsey 0:d39a06ca6bf1 35 {
chills 17:5774c69932e7 36 BP_filter.Define_Filter(); //Define the filter variables
chills 17:5774c69932e7 37 t1.start(sampler); //Start the Sampler timed interrupt
chills 7:6cb27cce4c50 38 }
mwthewsey 0:d39a06ca6bf1 39
mwthewsey 0:d39a06ca6bf1 40 void sampler(void)
mwthewsey 0:d39a06ca6bf1 41 {
chills 9:91c53a683856 42 while(1)
chills 9:91c53a683856 43 {
chills 17:5774c69932e7 44 SampLED = 1; //LED Indicates start of sampling
chills 17:5774c69932e7 45 input = Ain; //Takes ADC input as a Varaible type float
chills 17:5774c69932e7 46 BP_filter.setvalue(input); //Passes the input value to the filter
chills 17:5774c69932e7 47 Aout = BP_filter.getvalue(); //Collects the output from the filter and outputs it
chills 17:5774c69932e7 48 SampLED = 0; //LED Indicates end of sampling
chills 17:5774c69932e7 49 Thread::wait(sample_rate*1000); //Delay before taking the next sample
chills 9:91c53a683856 50 }
thomasmorris 11:7efb6e4759cc 51 }