![](/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@2:f6e49378dd8a, 2017-11-28 (annotated)
- Committer:
- mwthewsey
- Date:
- Tue Nov 28 09:51:30 2017 +0000
- Revision:
- 2:f6e49378dd8a
- Parent:
- 1:b088b771a591
- Child:
- 3:36d6642c2c45
Working Working version;
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" |
mwthewsey | 0:d39a06ca6bf1 | 4 | unsigned short ADC_DATA; |
mwthewsey | 0:d39a06ca6bf1 | 5 | |
mwthewsey | 0:d39a06ca6bf1 | 6 | //Init values for difference equation |
mwthewsey | 0:d39a06ca6bf1 | 7 | //MBED Class Instances follows |
mwthewsey | 0:d39a06ca6bf1 | 8 | 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 | 9 | |
mwthewsey | 0:d39a06ca6bf1 | 10 | AnalogIn Ain(PA_1); //Analog Input (Signal Input 0 to +3 Volts) |
mwthewsey | 0:d39a06ca6bf1 | 11 | AnalogOut Aout(PA_4); //Analog Output (Signal Input 0 to +3 Volts) |
mwthewsey | 0:d39a06ca6bf1 | 12 | |
mwthewsey | 0:d39a06ca6bf1 | 13 | Ticker sample_timer; |
mwthewsey | 0:d39a06ca6bf1 | 14 | Thread T1; |
mwthewsey | 0:d39a06ca6bf1 | 15 | Thread T2; |
mwthewsey | 0:d39a06ca6bf1 | 16 | |
mwthewsey | 2:f6e49378dd8a | 17 | float input = 0.0; |
mwthewsey | 2:f6e49378dd8a | 18 | FILTER BP_filter(48000,10,16,1600); //Create object of type Filter(Fs,Fo,Boost,Q) |
mwthewsey | 2:f6e49378dd8a | 19 | |
mwthewsey | 0:d39a06ca6bf1 | 20 | |
mwthewsey | 0:d39a06ca6bf1 | 21 | void sampler(void); |
mwthewsey | 0:d39a06ca6bf1 | 22 | |
mwthewsey | 0:d39a06ca6bf1 | 23 | |
mwthewsey | 0:d39a06ca6bf1 | 24 | int main() |
mwthewsey | 0:d39a06ca6bf1 | 25 | { |
mwthewsey | 0:d39a06ca6bf1 | 26 | |
mwthewsey | 2:f6e49378dd8a | 27 | BP_filter.Define_Filter(); |
mwthewsey | 0:d39a06ca6bf1 | 28 | float sample_rate = (1.0/35000) ; |
mwthewsey | 2:f6e49378dd8a | 29 | sample_timer.attach(&sampler,sample_rate);; |
mwthewsey | 0:d39a06ca6bf1 | 30 | |
mwthewsey | 0:d39a06ca6bf1 | 31 | while(1) { |
mwthewsey | 2:f6e49378dd8a | 32 | |
mwthewsey | 0:d39a06ca6bf1 | 33 | } |
mwthewsey | 0:d39a06ca6bf1 | 34 | } |
mwthewsey | 0:d39a06ca6bf1 | 35 | |
mwthewsey | 0:d39a06ca6bf1 | 36 | |
mwthewsey | 0:d39a06ca6bf1 | 37 | void sampler(void) |
mwthewsey | 0:d39a06ca6bf1 | 38 | { |
mwthewsey | 0:d39a06ca6bf1 | 39 | |
mwthewsey | 0:d39a06ca6bf1 | 40 | SampLED = 1; //LED Indicates start of sampling |
mwthewsey | 0:d39a06ca6bf1 | 41 | |
mwthewsey | 2:f6e49378dd8a | 42 | input = Ain; |
mwthewsey | 0:d39a06ca6bf1 | 43 | BP_filter.setvalue(input); //Input ADC. N.B. ADC in MBED is 0.0 to 1.0 float!!!!!! |
mwthewsey | 0:d39a06ca6bf1 | 44 | Aout = BP_filter.getvalue(); |
mwthewsey | 0:d39a06ca6bf1 | 45 | |
mwthewsey | 0:d39a06ca6bf1 | 46 | |
mwthewsey | 0:d39a06ca6bf1 | 47 | SampLED = 0; //LED Indicates end of sampling |
mwthewsey | 0:d39a06ca6bf1 | 48 | } |
mwthewsey | 0:d39a06ca6bf1 | 49 |