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:
mwthewsey
Date:
Tue Dec 05 16:08:01 2017 +0000
Revision:
15:97b4fa094a48
Parent:
14:379796f5868e
Child:
17:5774c69932e7
Non-variable (TESTEDandWORKING)

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
mwthewsey 0:d39a06ca6bf1 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
mwthewsey 15:97b4fa094a48 27 FILTER BP_filter(48000,70,16,1); //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 {
mwthewsey 15:97b4fa094a48 36 BP_filter.Define_Filter();
thomasmorris 14:379796f5868e 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 {
thomasmorris 13:db76473a3d76 44 SampLED = 1;//LED Indicates start of sampling
thomasmorris 13:db76473a3d76 45 input = Ain;//Takes ADC input as a Varaible type float
thomasmorris 13:db76473a3d76 46 BP_filter.setvalue(input);//Input ADC. N.B. ADC in MBED is 0.0 to 1.0 float!!!!!!
thomasmorris 13:db76473a3d76 47 Aout = BP_filter.getvalue();//Sets the input value to the Class
thomasmorris 13:db76473a3d76 48 SampLED = 0;//LED Indicates end of sampling
thomasmorris 12:d522a7a061d6 49 Thread::wait(sample_rate*1000);//Look at this
chills 9:91c53a683856 50 }
thomasmorris 11:7efb6e4759cc 51 }