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@6:a2737b51424c, 2017-11-28 (annotated)
- Committer:
- chills
- Date:
- Tue Nov 28 13:06:24 2017 +0000
- Revision:
- 6:a2737b51424c
- Parent:
- 5:e49e5515488d
- Child:
- 7:6cb27cce4c50
Working Code with Proof
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 | |
chills | 6:a2737b51424c | 5 | |
mwthewsey | 0:d39a06ca6bf1 | 6 | unsigned short ADC_DATA; |
mwthewsey | 0:d39a06ca6bf1 | 7 | |
mwthewsey | 0:d39a06ca6bf1 | 8 | //Init values for difference equation |
mwthewsey | 0:d39a06ca6bf1 | 9 | //MBED Class Instances follows |
mwthewsey | 0:d39a06ca6bf1 | 10 | 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 | 11 | |
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 | |
mwthewsey | 0:d39a06ca6bf1 | 15 | Ticker sample_timer; |
chills | 6:a2737b51424c | 16 | |
mwthewsey | 0:d39a06ca6bf1 | 17 | |
mwthewsey | 2:f6e49378dd8a | 18 | float input = 0.0; |
chills | 6:a2737b51424c | 19 | FILTER BP_filter(48000,10000,16,2); //Create object of type Filter(Fs,Fo,Boost,Q) |
mwthewsey | 2:f6e49378dd8a | 20 | |
mwthewsey | 0:d39a06ca6bf1 | 21 | |
mwthewsey | 0:d39a06ca6bf1 | 22 | void sampler(void); |
mwthewsey | 0:d39a06ca6bf1 | 23 | |
mwthewsey | 0:d39a06ca6bf1 | 24 | |
mwthewsey | 0:d39a06ca6bf1 | 25 | int main() |
mwthewsey | 0:d39a06ca6bf1 | 26 | { |
mwthewsey | 2:f6e49378dd8a | 27 | BP_filter.Define_Filter(); |
chills | 6:a2737b51424c | 28 | BP_filter.Print_Filter(); |
chills | 6:a2737b51424c | 29 | float sample_rate = (1.0/35000); |
chills | 6:a2737b51424c | 30 | //sample_timer.attach(&sampler,sample_rate); |
mwthewsey | 0:d39a06ca6bf1 | 31 | |
mwthewsey | 0:d39a06ca6bf1 | 32 | while(1) { |
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 | { |
chills | 6:a2737b51424c | 39 | printf("H"); |
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 |