![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
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 .
main.cpp@14:379796f5868e, 2017-12-04 (annotated)
- Committer:
- thomasmorris
- Date:
- Mon Dec 04 11:27:35 2017 +0000
- Revision:
- 14:379796f5868e
- Parent:
- 13:db76473a3d76
- Child:
- 15:97b4fa094a48
ELEC347 Coursework Final Version Non Variable Parameters
Who changed what in which revision?
User | Revision | Line number | New 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 |
thomasmorris | 13:db76473a3d76 | 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 | { |
thomasmorris | 14:379796f5868e | 36 | t1.start(sampler);//Start the Sampler timed interrupt |
chills | 7:6cb27cce4c50 | 37 | } |
mwthewsey | 0:d39a06ca6bf1 | 38 | |
mwthewsey | 0:d39a06ca6bf1 | 39 | void sampler(void) |
mwthewsey | 0:d39a06ca6bf1 | 40 | { |
chills | 9:91c53a683856 | 41 | while(1) |
chills | 9:91c53a683856 | 42 | { |
thomasmorris | 13:db76473a3d76 | 43 | SampLED = 1;//LED Indicates start of sampling |
thomasmorris | 13:db76473a3d76 | 44 | input = Ain;//Takes ADC input as a Varaible type float |
thomasmorris | 13:db76473a3d76 | 45 | BP_filter.setvalue(input);//Input ADC. N.B. ADC in MBED is 0.0 to 1.0 float!!!!!! |
thomasmorris | 13:db76473a3d76 | 46 | Aout = BP_filter.getvalue();//Sets the input value to the Class |
thomasmorris | 13:db76473a3d76 | 47 | SampLED = 0;//LED Indicates end of sampling |
thomasmorris | 12:d522a7a061d6 | 48 | Thread::wait(sample_rate*1000);//Look at this |
chills | 9:91c53a683856 | 49 | } |
thomasmorris | 11:7efb6e4759cc | 50 | } |