![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Non-variable (TESTEDandWORKING)
Fork of ELEC347_Coursework by
main.cpp@5:e49e5515488d, 2017-11-28 (annotated)
- Committer:
- chills
- Date:
- Tue Nov 28 09:59:04 2017 +0000
- Revision:
- 5:e49e5515488d
- Parent:
- 4:c9ed97dad32b
- Child:
- 6:a2737b51424c
Test3
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) ; |
chills | 5:e49e5515488d | 29 | sample_timer.attach(&sampler,sample_rate);; |
mwthewsey | 0:d39a06ca6bf1 | 30 | |
mwthewsey | 0:d39a06ca6bf1 | 31 | while(1) { |
chills | 5:e49e5515488d | 32 | //EMPTY |
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 |