Non-variable (TESTEDandWORKING)

Dependencies:   mbed-rtos mbed

Fork of ELEC347_Coursework by CMST

Committer:
mwthewsey
Date:
Tue Dec 05 15:59:45 2017 +0000
Revision:
15:a98f8182c86f
Parent:
14:379796f5868e
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:a98f8182c86f 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 {
thomasmorris 14:379796f5868e 36 t1.start(sampler);//Start the Sampler timed interrupt
mwthewsey 15:a98f8182c86f 37 BP_filter.Define_Filter();
mwthewsey 15:a98f8182c86f 38 BP_filter.Print_Filter();
chills 7:6cb27cce4c50 39 }
mwthewsey 0:d39a06ca6bf1 40
mwthewsey 0:d39a06ca6bf1 41 void sampler(void)
mwthewsey 0:d39a06ca6bf1 42 {
chills 9:91c53a683856 43 while(1)
chills 9:91c53a683856 44 {
thomasmorris 13:db76473a3d76 45 SampLED = 1;//LED Indicates start of sampling
thomasmorris 13:db76473a3d76 46 input = Ain;//Takes ADC input as a Varaible type float
thomasmorris 13:db76473a3d76 47 BP_filter.setvalue(input);//Input ADC. N.B. ADC in MBED is 0.0 to 1.0 float!!!!!!
thomasmorris 13:db76473a3d76 48 Aout = BP_filter.getvalue();//Sets the input value to the Class
thomasmorris 13:db76473a3d76 49 SampLED = 0;//LED Indicates end of sampling
thomasmorris 12:d522a7a061d6 50 Thread::wait(sample_rate*1000);//Look at this
chills 9:91c53a683856 51 }
thomasmorris 11:7efb6e4759cc 52 }